Skip to content

Instantly share code, notes, and snippets.

@Neradoc
Created March 3, 2021 16:15
Show Gist options
  • Save Neradoc/71ba212b77ec0f9671f939e09fb7fc4c to your computer and use it in GitHub Desktop.
Save Neradoc/71ba212b77ec0f9671f939e09fb7fc4c to your computer and use it in GitHub Desktop.
Display a temperature sensor on an I2C OLED REPL with the QT PY Haxpress
import time
import board
print("I2C")
i2c = board.I2C()
while not i2c.try_lock():
i2c.unlock()
#i2c.unlock()
try:
scan = i2c.scan()
print((scan,[hex(x) for x in scan]))
finally:
i2c.unlock()
print("HTS221")
from adafruit_hts221 import HTS221
sensor = HTS221(i2c)
# import neopixel
# pix = neopixel.NeoPixel(board.NEOPIXEL,1)
print("DISPLAY")
import displayio
from adafruit_displayio_ssd1306 import SSD1306
displayio.release_displays()
# connect to display
print("Connect to display")
display_bus = displayio.I2CDisplay(i2c, device_address=0x3c)
oled = SSD1306(display_bus, width=128, height=32, rotation=180)
# display_bus = displayio.I2CDisplay(i2c, device_address=0x3d)
# oled = SSD1306(display_bus, width=128, height=64, rotation=0)
# display context
from adafruit_display_text.bitmap_label import Label
import gc
try:
while True:
# relative_humidity
temperature = sensor.temperature
texte = "\n\nFree Mem: %02d\nTemperature %.1fC" % (gc.mem_free(),temperature)
print(texte,end="")
time.sleep(1)
gc.collect()
finally:
displayio.release_displays()
i2c.deinit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment