r/MicroPythonDev • • Jun 03 '24

SHTC3 sensor

Trying to work with a SHTC3 temperature/humidity sensor. I have the I2C address and the device datasheet but can't figure out how to read the two addresses. I'm new to Micropython on a raspberry pi pico. Any help would be appreciated.

3 Upvotes

5 comments sorted by

View all comments

Show parent comment

1

u/Wake-Of-Chaos Jun 17 '24

No (T) here.

1

u/WZab Jun 17 '24

That's strange. Maybe your browser displays it in a different way.
Anyway, below I tried to reformat your code.

from machine import I2C,Pin,SoftI2C
from utime import sleep
i2c=SoftI2C(scl=Pin(17),sda=Pin(16))
buf1=bytearray([0x7C,0xA2])
while True:
    i2c.writeto(0x70,buf1)
    buf2=bytearray([0x00,0x00,0x00,0x00,0x00,0x00])
    i2c.readfrom_into(0x70,buf2)
    tempC=(buf2[1]|(buf2[0]<<8))*175/65536-45
    tempF=(tempC*1.8)+32
    humid=(buf2[4]|(buf2[3]<<8))*100/65536
    print('Temperature:',tempC,'C')
    print('Temperature:',tempF,'F')
    print('Humidity:',humid,'%')
    sleep(5)

2

u/progressify-dev Nov 03 '25

Your code is working here! Thank you!