adafruit / Adafruit_CircuitPython_SHT31D

CircuitPython driver for the SHT31-D temperature and humidity sensor
MIT License
20 stars 18 forks source link

Can't find i2c device, but it is detected #36

Open trippinCode opened 2 weeks ago

trippinCode commented 2 weeks ago

Hello,

i'm currently struggling to get my sht30 sensor up and running. I bought this sensor and i'm following this guide.

I have a Raspberry Model 3b+. The sensor is connected to the GPIO Pins 9 and 7 and i'm finding it when i scan my i2c port with:

i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- 44 -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

I'm also finding it via the scan method in python:

$ cat test2.py
import board
import busio
import adafruit_sht31d

i2c = busio.I2C(board.SCL, board.SDA)

i2c.try_lock()
print(i2c.scan())
i2c.unlock()
i2c.deinit()
$ bin/python test2.py
[68]

So there should be something at the hex address 0x44, but when i try to run the "hello world" of reading the sensor i get the following error error:

(sht30_exporter) grow-monitor@grow-monitor:~/sht30_exporter $ cat test3.py
import board
import busio
import adafruit_sht31d
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_sht31d.SHT31D(i2c)

print('Humidity: {0}%'.format(sensor.relative_humidity))
print('Temperature: {0}C'.format(sensor.temperature))
(sht30_exporter) grow-monitor@grow-monitor:~/sht30_exporter $ bin/python test3.py
Traceback (most recent call last):
  File "/home/grow-monitor/sht30_exporter/lib/python3.11/site-packages/adafruit_bus_device/i2c_device.py", line 175, in __probe_for_device
    self.i2c.writeto(self.device_address, b"")
  File "/home/grow-monitor/sht30_exporter/lib/python3.11/site-packages/busio.py", line 215, in writeto
    return self._i2c.writeto(address, buffer, stop=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/grow-monitor/sht30_exporter/lib/python3.11/site-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 60, in writeto
    self._i2c_bus.write_bytes(address, buffer[start:end])
  File "/home/grow-monitor/sht30_exporter/lib/python3.11/site-packages/Adafruit_PureIO/smbus.py", line 303, in write_bytes
    self._device.write(buf)
OSError: [Errno 121] Remote I/O error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/grow-monitor/sht30_exporter/lib/python3.11/site-packages/adafruit_bus_device/i2c_device.py", line 181, in __probe_for_device
    self.i2c.readfrom_into(self.device_address, result)
  File "/home/grow-monitor/sht30_exporter/lib/python3.11/site-packages/busio.py", line 205, in readfrom_into
    return self._i2c.readfrom_into(address, buffer, stop=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/grow-monitor/sht30_exporter/lib/python3.11/site-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 67, in readfrom_into
    readin = self._i2c_bus.read_bytes(address, end - start)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/grow-monitor/sht30_exporter/lib/python3.11/site-packages/Adafruit_PureIO/smbus.py", line 170, in read_bytes
    return self._device.read(number)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 5] Input/output error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/grow-monitor/sht30_exporter/test3.py", line 5, in <module>
    sensor = adafruit_sht31d.SHT31D(i2c)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/grow-monitor/sht30_exporter/lib/python3.11/site-packages/adafruit_sht31d.py", line 187, in __init__
    self.i2c_device = I2CDevice(i2c_bus, address)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/grow-monitor/sht30_exporter/lib/python3.11/site-packages/adafruit_bus_device/i2c_device.py", line 62, in __init__
    self.__probe_for_device()
  File "/home/grow-monitor/sht30_exporter/lib/python3.11/site-packages/adafruit_bus_device/i2c_device.py", line 184, in __probe_for_device
    raise ValueError("No I2C device at address: 0x%x" % self.device_address)
ValueError: No I2C device at address: 0x44

I don't have a lot of experience with this kind of software development, does anybody have any idea how i could debug this issue further?

Thanks a lot in advance :)

juatafe commented 2 weeks ago

Could you try explicitly specifying the I2C address when initializing the sensor in your code? Like this:

sensor = adafruit_sht31d.SHT31D(i2c, address=0x44)

Additionally, check your circuit connections to ensure that: The SDA and SCL lines are correctly connected to the appropriate GPIO pins on the Raspberry Pi. The sensor is properly powered and grounded. Pull-up resistors (typically 4.7k ohms) are present on the SDA and SCL lines.