Skip to content

Instantly share code, notes, and snippets.

@jfurcean
Last active January 1, 2021 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfurcean/77d20ced1ccc896f9258c5ab75aaba08 to your computer and use it in GitHub Desktop.
Save jfurcean/77d20ced1ccc896f9258c5ab75aaba08 to your computer and use it in GitHub Desktop.
Using a QT PY (Haxpress), Sensor, and OLED
import time
import board
import busio
import adafruit_tlv493d
import math
import displayio
import adafruit_displayio_ssd1306
import terminalio
from adafruit_display_text import label
WIDTH = 128
HEIGHT = 32 # Change to 64 if needed
displayio.release_displays()
i2c = board.I2C()
tlv = adafruit_tlv493d.TLV493D(i2c)
display_bus = displayio.I2CDisplay(i2c, device_address=0x3c)
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32)
splash = displayio.Group(max_size=10)
display.show(splash)
# Draw a labels
text = " "
x_label = label.Label(terminalio.FONT, text=text, color=0xFFFFFF, x=0, y=4)
y_label = label.Label(terminalio.FONT, text=text, color=0xFFFFFF, x=0, y=15)
z_label = label.Label(terminalio.FONT, text=text, color=0xFFFFFF, x=0, y=26)
splash.append(x_label)
splash.append(y_label)
splash.append(z_label)
while True:
x_label.text = (f"x: {tlv.magnetic[0]}")
y_label.text = (f"y: {tlv.magnetic[1]}")
z_label.text = (f"z: {tlv.magnetic[2]}")
print("X: %s, Y: %s, Z: %s mT" % tlv.magnetic)
#time.sleep(.1)
@gragib
Copy link

gragib commented Jan 1, 2021

import board
from displayio import (
    FourWire,
    Group,
    release_displays,
)
import terminalio
from adafruit_display_text import label
from adafruit_displayio_ssd1306 import SSD1306
# import adafruit_bme280

release_displays()

oled_reset = board.D9

spi = board.SPI()
oled_cs = board.D5
oled_dc = board.D6
display_bus = FourWire(
    spi,
    command=oled_dc,
    chip_select=oled_cs,
    reset=oled_reset,
    baudrate=24_000_000,
)

WIDTH = 128
HEIGHT = 32

display = SSD1306(
    display_bus,
    width=WIDTH,
    height=HEIGHT,
)

splash = Group(max_size=10)
display.show(splash)

text = 'Hello World!'
text_area = label.Label(
    terminalio.FONT,
    text=text,
    color=0xFFFFFF,
    x=0,
    y=3,
)
splash.append(text_area)

while True:
    pass

This works. Then uncomment line 10, and

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Traceback (most recent call last):
  File "code.py", line 10, in <module>
  File "adafruit_bme280.py", line 507, in <module>
MemoryError: 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment