Page 1 of 2
Adafruit STEMMA Soil Sensor driver
Posted: Thu Dec 26, 2019 6:38 pm
by FaithRaven
I wonder if it's possible to use the Adafruit STEMMA Soil Sensor with an ESP32 board running MicroPython.
Any tips to steer me in the right direction will be greatly appreciated.
Re: Adafruit STEMMA Soil Sensor driver
Posted: Thu Dec 26, 2019 7:32 pm
by MostlyHarmless
Possible for sure, it is just another I2C device.
I would start by connecting it and then using machine.I2C's scan() method. That should reveal the device's I2C address.
A quick Google search told me that the thing produces a "moisture level" value between 200 and 2000. That value can be found at memory address 0x10, representing touch pin 1. There is also a temperature sensor. My guess is that the reading of that can be found in Celsius at some other memory location.
You should not be able to damage an I2C device by reading from it. So unless you can find a datasheet, start poking around.
Regards, Jan
Re: Adafruit STEMMA Soil Sensor driver
Posted: Fri Dec 27, 2019 9:12 am
by pythoncoder
Adafruit have a CircuitPython driver for it
here. I've only glanced at it but it seems rather heavyweight.
Re: Adafruit STEMMA Soil Sensor driver
Posted: Fri Dec 27, 2019 9:32 pm
by FaithRaven
Thank you both for steering me in the right direction. I've managed to strip Adafruit's drivers down to the essentials and this is what works for me:
I've published the code and usage instructions at
https://github.com/mihai-dinculescu/mic ... ter/seesaw.
Re: Adafruit STEMMA Soil Sensor driver
Posted: Sat Dec 28, 2019 11:32 am
by pythoncoder
Well done! I've ported drivers from CircuitPython to MicroPython. Adafruit's approach to coding prioritises ease of use by beginners over performance and code complexity. The upshot is that porting drivers from CircuitPython can be tougher than porting them from C.
Re: Adafruit STEMMA Soil Sensor driver
Posted: Tue Oct 05, 2021 1:03 am
by dhust
Couldn't get this to work. Not sure what's wrong. Using a Wemos D1 Mini.
Here is my code:
Code: Select all
import stemma_soil_sensor
SDA_PIN = 4 # update this
SCL_PIN = 5 # update this
i2c = machine.I2C(sda=machine.Pin(SDA_PIN), scl=machine.Pin(SCL_PIN), freq=400000)
seesaw = stemma_soil_sensor.StemmaSoilSensor(i2c)
# get moisture
moisture = seesaw.get_moisture()
# get temperature
temperature = seesaw.get_temp()
Here is my error:
ampy.pyboard.PyboardError: ('exception', b'', b'Traceback (most recent call last):\r\n File "<stdin>", line 47, in <module>\r\n File "stemma_soil_sensor.py", line 62, in __init__\r\n File "seesaw.py", line 64, in __init__\r\n File "seesaw.py", line 68, in sw_reset\r\n File "seesaw.py", line 79, in _write8\r\n File "seesaw.py", line 98, in _write\r\nOSError: [Errno 110] ETIMEDOUT\r\n')
Thoughts on how to fix this or what I'm missing?
Re: Adafruit STEMMA Soil Sensor driver
Posted: Tue Oct 05, 2021 8:07 pm
by marcidy
That probably means the i2c bus can't find the sensor.
can you see your devices when scanning the i2c bus on the repl?
Re: Adafruit STEMMA Soil Sensor driver
Posted: Tue Oct 05, 2021 10:32 pm
by dhust
It looks like you are correct. Here is what I ran and the results
Code: Select all
import machine
i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))
print('Scan i2c bus...')
devices = i2c.scan()
print(devices)
if len(devices) == 0:
print("No i2c device !")
else:
print('i2c devices found:',len(devices))
for device in devices:
print("Decimal address: ",device," | Hexa address: ",hex(device))
Code: Select all
Scan i2c bus...
[]
No i2c device !
What does that mean? What are some next steps?
Re: Adafruit STEMMA Soil Sensor driver
Posted: Wed Oct 06, 2021 12:24 am
by marcidy
you need to check the connections and make sure they correspond correctly to the pin declarations. is sda connected to sda? is that pin declared as sda in the code? etc.
post the schematic you are using and confirm you have connected everything according to the schematic
if the connection is correct, it's possible the sensor is broken, and so test with another sensor.
Re: Adafruit STEMMA Soil Sensor driver
Posted: Wed Oct 06, 2021 11:37 am
by dhust
marcidy wrote: ↑Wed Oct 06, 2021 12:24 am
you need to check the connections and make sure they correspond correctly to the pin declarations. is sda connected to sda? is that pin declared as sda in the code? etc.
post the schematic you are using and confirm you have connected everything according to the schematic
if the connection is correct, it's possible the sensor is broken, and so test with another sensor.
That's unfortunate. I've checked the connections a few times. It's good there. There are no schematics to post. I just connected ground to ground, vin to 5V or 3.3V, SDA to D2 (GPIO4: SDA), and SCL to D1 (GPIO5: SCL). I'll have to swap out the ESP8266 later to see if that's the issue. Shouldn't be because it's brand new but we'll see.