Skip to content

Commit 793e63e

Browse files
authored
Merge pull request adafruit#1133 from andydoro/master
creating new AHT20 OLED learn guide
2 parents 152c41f + 078437f commit 793e63e

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

AHT20_OLED/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# AHT20_OLED

AHT20_OLED/code.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
""" Example for using the AHT20 and OLED with CircuitPython and the Adafruit library"""
2+
3+
import time
4+
import board
5+
import busio
6+
import adafruit_ahtx0
7+
8+
# OLED
9+
import displayio
10+
import terminalio
11+
from adafruit_display_text import label
12+
import adafruit_displayio_ssd1306
13+
14+
displayio.release_displays()
15+
16+
i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)
17+
18+
# Create library object using our Bus I2C port
19+
#i2c = busio.I2C(board.SCL, board.SDA)
20+
aht20 = adafruit_ahtx0.AHTx0(i2c)
21+
22+
23+
#OLED
24+
display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
25+
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32)
26+
27+
# Make the display context
28+
splash = displayio.Group(max_size=8)
29+
display.show(splash)
30+
31+
text = "hello world"
32+
text_area = label.Label(terminalio.FONT, color=0xFFFF00, x=15, y=0, max_glyphs=200)
33+
splash.append(text_area)
34+
35+
while True:
36+
text_area.text = "temp: %0.1fC \nhumid: %0.1f%%" % (aht20.temperature, aht20.relative_humidity)
37+
print(text_area.text)
38+
time.sleep(1)

0 commit comments

Comments
 (0)