【Follow me Season 2 Episode 1】Optional Task: Using SH1107 OLDE Screen
[Copy link]
This post was last edited by disk0 on 2024-8-18 17:29
Task understanding
During the ordering phase, the difference was placed on M5's SH1107
Because CPX has no display module, the sensor reading can be more intuitive
Code section
import board
import displayio
import terminalio
from adafruit_display_text import label
import adafruit_displayio_sh1107
import gc
import os
import busio
import random
import time
import analogio
import adafruit_thermistor
gc.enable()
# release any currently configured displays
displayio.release_displays()
# Setup I2C
i2c = busio.I2C(board.SCL, board.SDA) # uses board.SCL and board.SDA
display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
# SH1107 is vertically oriented 64x128
WIDTH = 128
HEIGHT = 64
display = adafruit_displayio_sh1107.SH1107(
display_bus, width=WIDTH, height=HEIGHT, rotation=0
)
splash = displayio.Group()
display.root_group = splash
default_text = " "*7
text_area = label.Label(terminalio.FONT, text=default_text, scale=2, color=0xFFFFFF, x=0, y=10)
display.root_group =text_area
sensor_light = analogio.AnalogIn(board.LIGHT)
sensor_temp = adafruit_thermistor.Thermistor(board.TEMPERATURE, 10000, 10000, 25, 3950)
while True:
gc.collect()
print('mem_free',gc.mem_free())
temp_value = str(round(sensor_temp.temperature,1))
light_value = str(sensor_light.value)
show_value = temp_value + '/' + light_value
# show_value = 'T/L' + '\n' + show_value
text_new= show_value
text_area.text = text_new
time.sleep(1)
Main logic
1. The main part is sensor reading, please refer to
2. The headers need to be imported into the lib folder: adafruit_display_text and adafruit_displayio_sh1107
3. Line 33~42 mainly instantiates the display part, and finally in the large loop periodically updates the sensor value to the text in the display area
exhibit
|