Can you give us some clues?
How is it wired, draw a diagram if you have to.
What OS is on the Pi?
What code are you trying to run to determine if it works?
Here is a good primer that you NEED to read.
If you want the cheat sheet then:
- install an OOtB OS image on the Raspberry Pi like Raspberry Pi OS here, let me be more prescriptive:
- Install the Raspberry Pi Imager
Raspberry Pi OS – Raspberry Pi - Install Raspberry Pi OS
- Easiest is to connect a USB keyboard and HDMI monitor to the Pi as well as an ethernet cable to your router to give the Pi internet access
- Boot it
- Log in, I think the default login is still pi:raspberry
- in the command line type:
sudo apt-get update
- type:
sudo apt-get upgrade
- type:
sudo apt-get install python3-smbus i2c-tools
- You should wire the sensor up to the GPIO in the following way: NOTE you need to use the standard GPIO pinout diagram. Print it out and stick it on your wall, you are going to be needing this constantly. Also to NOTE, GPIO Pin numbers are different to GPIO names, I have referenced the physical pin number.
Pi Sensor
GPIO PIN 1 VCC
GPIO PIN 6 GND
GPIO PIN 3 SDA (NOTE THE ORDER IS REVERSED ON THE SENSOR TO THE PI)
GPIO PIN 5 SCL (NOTE THE ORDER IS REVERSED ON THE SENSOR TO THE PI)
- type:
i2cdetect -y 1
and you will get an output telling you the address of the sensor that will look something like this
- Save the following code as ‘sht31.py’ file but make sure to adjust the I2C address to what your sensor read in the above.
import smbus
import time
# Get I2C bus
bus = smbus.SMBus(1)
# SHT31 address, 0x44(68)
bus.write_i2c_block_data(0x44, 0x2C, [0x06])
time.sleep(0.5)
# SHT31 address, 0x44(68)
# Read data back from 0x00(00), 6 bytes
# Temp MSB, Temp LSB, Temp CRC, Humididty MSB, Humidity LSB, Humidity CRC
data = bus.read_i2c_block_data(0x44, 0x00, 6)
# Convert the data
temp = data[0] * 256 + data[1]
cTemp = -45 + (175 * temp / 65535.0)
fTemp = -49 + (315 * temp / 65535.0)
humidity = 100 * (data[3] * 256 + data[4]) / 65535.0
# Output data to screen
print ("Temperature in Celsius is : %.2f C" %cTemp)
print ("Temperature in Fahrenheit is : %.2f F" %fTemp)
print ("Relative Humidity is : %.2f %%RH" %humidity)
- Type this from the command line:
sudo python sht31.py
You will get an output similar to this:
$ sudo python sht31.py
Temperature in Celsius is : 26.52 C
Temperature in Fahrenheit is : 79.73 F
Relative Humidity is : 55.24 %RH
That will give you the ability to read the sensor.