Adafruit STEMMA Soil Sensor driver
-
- Posts: 8
- Joined: Thu Dec 26, 2019 6:32 pm
- Location: UK
Adafruit STEMMA Soil Sensor driver
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.
Any tips to steer me in the right direction will be greatly appreciated.
- MostlyHarmless
- Posts: 166
- Joined: Thu Nov 21, 2019 6:25 pm
- Location: Pennsylvania, USA
Re: Adafruit STEMMA Soil Sensor driver
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
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
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Adafruit STEMMA Soil Sensor driver
Adafruit have a CircuitPython driver for it here. I've only glanced at it but it seems rather heavyweight.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 8
- Joined: Thu Dec 26, 2019 6:32 pm
- Location: UK
Re: Adafruit STEMMA Soil Sensor driver
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.
I've published the code and usage instructions at https://github.com/mihai-dinculescu/mic ... ter/seesaw.
Last edited by FaithRaven on Sun Dec 29, 2019 2:25 pm, edited 1 time in total.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Adafruit STEMMA Soil Sensor driver
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.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Adafruit STEMMA Soil Sensor driver
Couldn't get this to work. Not sure what's wrong. Using a Wemos D1 Mini.FaithRaven wrote: ↑Fri Dec 27, 2019 9:32 pmThank 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.
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()
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
That probably means the i2c bus can't find the sensor.
can you see your devices when scanning the i2c bus on the repl?
can you see your devices when scanning the i2c bus on the repl?
Re: Adafruit STEMMA Soil Sensor driver
It looks like you are correct. Here is what I ran and the results
What does that mean? What are some next steps?
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 !
Re: Adafruit STEMMA Soil Sensor driver
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.
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
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.marcidy wrote: ↑Wed Oct 06, 2021 12:24 amyou 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.