Adafruit STEMMA Soil Sensor driver

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
FaithRaven
Posts: 8
Joined: Thu Dec 26, 2019 6:32 pm
Location: UK

Adafruit STEMMA Soil Sensor driver

Post by FaithRaven » Thu Dec 26, 2019 6:38 pm

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.

User avatar
MostlyHarmless
Posts: 166
Joined: Thu Nov 21, 2019 6:25 pm
Location: Pennsylvania, USA

Re: Adafruit STEMMA Soil Sensor driver

Post by MostlyHarmless » Thu Dec 26, 2019 7:32 pm

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

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Adafruit STEMMA Soil Sensor driver

Post by pythoncoder » Fri Dec 27, 2019 9:12 am

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.

FaithRaven
Posts: 8
Joined: Thu Dec 26, 2019 6:32 pm
Location: UK

Re: Adafruit STEMMA Soil Sensor driver

Post by FaithRaven » Fri Dec 27, 2019 9:32 pm

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.
Last edited by FaithRaven on Sun Dec 29, 2019 2:25 pm, edited 1 time in total.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Adafruit STEMMA Soil Sensor driver

Post by pythoncoder » Sat Dec 28, 2019 11:32 am

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.

dhust
Posts: 40
Joined: Sun Jul 11, 2021 10:59 pm

Re: Adafruit STEMMA Soil Sensor driver

Post by dhust » Tue Oct 05, 2021 1:03 am

FaithRaven wrote:
Fri Dec 27, 2019 9:32 pm
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.
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?

marcidy
Posts: 133
Joined: Sat Dec 12, 2020 11:07 pm

Re: Adafruit STEMMA Soil Sensor driver

Post by marcidy » Tue Oct 05, 2021 8:07 pm

That probably means the i2c bus can't find the sensor.

can you see your devices when scanning the i2c bus on the repl?

dhust
Posts: 40
Joined: Sun Jul 11, 2021 10:59 pm

Re: Adafruit STEMMA Soil Sensor driver

Post by dhust » Tue Oct 05, 2021 10:32 pm

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?

marcidy
Posts: 133
Joined: Sat Dec 12, 2020 11:07 pm

Re: Adafruit STEMMA Soil Sensor driver

Post by marcidy » 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.

dhust
Posts: 40
Joined: Sun Jul 11, 2021 10:59 pm

Re: Adafruit STEMMA Soil Sensor driver

Post by dhust » Wed Oct 06, 2021 11:37 am

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.

Post Reply