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:
Now you are reading pin A0 and toggling the led on the Arduino board.
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) 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,13) led.on() time.sleep(1) led.off()
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.