Skip to content

Instantly share code, notes, and snippets.

@baskaufs
Created January 4, 2022 20:07
Show Gist options
  • Save baskaufs/67e4917e3c068b7b9bddf1c71ceb41be to your computer and use it in GitHub Desktop.
Save baskaufs/67e4917e3c068b7b9bddf1c71ceb41be to your computer and use it in GitHub Desktop.
CircuitPython script to run temperature and RH sensor with 0.91 OLED display on QT Py RP2040
import time
import board
import busio # contains an interface for using hardware-driven I2C communication from your board
# board
import adafruit_hts221
# display
import displayio
import adafruit_displayio_ssd1306
displayio.release_displays()
oled_reset = board.D9
i2c = busio.I2C(board.SCL1, board.SDA1)
display_bus = displayio.I2CDisplay(i2c, device_address=0x3c)
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32)
hts = adafruit_hts221.HTS221(i2c)
# read the rel humidity and temp every second
while True:
print() # this generates a newline to make up for the missing one at the end of the loop
print() # this generates another newline to clear the text off the top of the display
print("RH: %.2f %%" % hts.relative_humidity)
print("Temp: %.2f C" % hts.temperature, end ="") # suppress newline to prevent text shifting up on display
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment