Control your Arduino

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Control your Arduino

Post by kevinkk525 » Sun Apr 07, 2019 9:46 am

I created a library to control your Arduino (pins) from a micropython device communicating by 1-wire protocol: https://github.com/kevinkk525/micropyth ... no_control

Motivation
I was faced with the situation of having to connect 16 simple analog sensors to my ESP32 running micropython. These were all within a few meters from the device but would require me to run a lot of cables and still use an analog multiplexer and a multiplexer for the power supply lines as these devices are not supposed to be powered all the time but can not be powered at the same time either. Therefore the easier solution was to have small, power efficient and cheap Arduinos do the sensor power toggling and reading. This way I only need to run one cable with Vcc,Data and GND between all Arduinos and can reliably read all 16 sensors.

How does it work
You flash the Arduino with the provided Sketch and just implement it like any other 1-wire device. On the micropython side it's as simple as this:

Code: Select all

from arduinoGPIO.arduinoControl import ArduinoControl
from arduinoGPIO.arduino import Arduino
import machine
import time

arduinoControl = ArduinoControl(machine.Pin(19)) # 19: pin number of the 1-wire connection
roms=arduinoControl.scanSafely() # .scan() can be used too, this is just safer as it scans multiple times

arduino = Arduino(arduinoControl, roms[0])

adc=arduino.ADC(0,vcc=3.3) # Analog pin 0. optional argument vcc used for calculating voltages
print(adc.read())
print(adc.readVoltage())

led=arduinoControl.Pin(roms[0],13)
led.on()
time.sleep(1)
led.off()
Now you are reading pin A0 and toggling the led on the Arduino board.

By the way: Be careful not to connect a 5V power supply for the Arduinos to any ESP pin. It will destroy the ESP. However the Arduinos I tested worked fine at 3.3V powered by the ESP32 without flashing them specifically for 3.3V.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Post Reply