This blog post will explain how to use the Picobricks temperature and air pressure sensor. First, the required libraries have to be imported. Then variables have to be declared to setup the pins on the oled screen and temperature sensor. Then a function is needed to convert celsius to fahrenheit. Variables such as tempSHTC and humiditySHTC hold the values that are polled from the sensors. Then the values from those variable are printed on the oled screen.
from machine import Pin, I2C
from picobricks import SSD1306_I2C, SHTC3
i2c = I2C(0, scl=Pin(5), sda=Pin(4))
oled = SSD1306_I2C(128, 64, i2c, addr=0x3c)
shtc_sensor = SHTC3(i2c)
def celsius_to_fahrenheit(celsius):
fahrenheit = (celsius * 9/5) + 32
return fahrenheit
tempSHTC = shtc_sensor.temperature()
tempSHTC = celsius_to_fahrenheit(tempSHTC)
humiditySHTC = shtc_sensor.humidity()
oled.text("Temperature: ",0,10)
oled.text(str(tempSHTC)+"F",0,20)
oled.text("Humidty: ", 0,40)
oled.text(str(humiditySHTC)+"%",0,50)
oled.show()
The Picobricks zero to hero kit was used to write this blog post.