Exercise of using
CircuitPython 7.2.0 on ESP32-C3-DevKitM-1
with 1.44" 128x128 ST7735 SPI TFT (KMR1441_SPI V2):
- display bmp in
slideshow
- display bmp using OnDiskBitmap/adafruit_imageload
The
display module used in this exercise is a with 1.44" 128x128 SPI TFT marked
"KMR1441_SPI V2".
Connection:
Firstly, connect the display to ESP32-C3-DevKitM-1.
ST7735 ESP32-C3-DevKitM-1
------------------------------
VCC 3V3
GND GND
CS IO10
RESET IO1
A0 IO0
SDA IO3
SCK IO2
LED 3V3
Library:
Visit
CircuitPython Library page
to download Bundle for Version 7.x, and extract it.
Copy the
libraries to lib folder in Circuit device.
- adafruit_st7735r.mpy
-
adafruit_display_text folder
- adafruit_slideshow.mpy
-
adafruit_imageload folder
Exercise code:
cpyESP32C3_st7735_128x128.py, functional testing.
"""
CircuitPython 7.2.0 exercise run on ESP32-C3-DevKitM-1
with 1.44" 128x128 (KMR1441_SPI V2)
ref:
adafruit/Adafruit_CircuitPython_ST7735R
https://github.com/adafruit/Adafruit_CircuitPython_ST7735R
"""
from sys import implementation as sysImplementation
import time
import os
import board
import busio
import displayio
import terminalio
from adafruit_st7735r import ST7735R as TFT_ST7735
from adafruit_st7735r import __name__ as ST7735_NAME
from adafruit_st7735r import __version__ as ST7735_VERSION
from adafruit_display_text import label
# Release any resources currently in use for the displays
displayio.release_displays()
#Connection between ESP32-C3 and SPI ST7735 display
#marking on display
tft_sck = board.IO2 #SCK
tft_mosi = board.IO3 #SDA
tft_dc = board.IO0 #A0
tft_reset = board.IO1 #RESET
tft_cs = board.IO10 #CS
#Backlight (LED) connect to ESP32-C3 3V3
#TFT VCC - ESP32-C3 3V3
#TFT GND - ESP32-C3 GND
tft_spi = busio.SPI(clock=tft_sck, MOSI=tft_mosi)
display_bus = displayio.FourWire(
tft_spi, command=tft_dc, chip_select=tft_cs, reset=tft_reset)
display = TFT_ST7735(display_bus, width=128, height=128,
rotation=90,
bgr=True)
strSys = sysImplementation[0] + ' ' + \
str(sysImplementation[1][0]) +'.'+ \
str(sysImplementation[1][1]) +'.'+ \
str(sysImplementation[1][2])
print("==========================================")
print(strSys)
print('run on ' + os.uname()[4])
print('using', ST7735_NAME, ST7735_VERSION)
print("==========================================")
print(type(display))
print("display.width: ", display.width)
print("display.height: ", display.height)
# Make the display context
splash = displayio.Group()
display.show(splash)
color_bitmap = displayio.Bitmap(display.width, display.height, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0x000000
time.sleep(1)
bg_sprite = displayio.TileGrid(color_bitmap,
pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)
for c in [["RED", 0xFF0000],
["GREEN", 0x00FF00],
["BLUE", 0x0000FF]]:
print(c[0], " : ", hex(c[1]))
color_palette[0] = c[1]
time.sleep(2)
splash.remove(bg_sprite)
#---
# Make the display context
#splash = displayio.Group()
#display.show(splash)
color_bitmap = displayio.Bitmap(display.width, display.height, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0x00FF00
bg_sprite = displayio.TileGrid(color_bitmap,
pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)
# Draw a smaller inner rectangle
inner_bitmap = displayio.Bitmap(display.width-2, display.height-2, 1)
inner_palette = displayio.Palette(1)
inner_palette[0] = 0x0000FF
inner_sprite = displayio.TileGrid(inner_bitmap,
pixel_shader=inner_palette, x=1, y=1)
splash.append(inner_sprite)
# Draw a label
text_group1 = displayio.Group(scale=1, x=5, y=10)
text1 = "ESP32-C3"
text_area1 = label.Label(terminalio.FONT, text=text1, color=0xFF0000)
text_group1.append(text_area1) # Subgroup for text scaling
# Draw a label
text_group2 = displayio.Group(scale=1, x=5, y=25)
text2 = strSys
text_area2 = label.Label(terminalio.FONT, text=text2, color=0xFFFFFF)
text_group2.append(text_area2) # Subgroup for text scaling
# Draw a label
text_group3 = displayio.Group(scale=1, x=5, y=40)
text3 = ST7735_NAME
text_area3 = label.Label(terminalio.FONT, text=text3, color=0x0000000)
text_group3.append(text_area3) # Subgroup for text scaling
# Draw a label
text_group4 = displayio.Group(scale=1, x=5, y=55)
text4 = ST7735_VERSION
text_area4 = label.Label(terminalio.FONT, text=text4, color=0x000000)
text_group4.append(text_area4) # Subgroup for text scaling
text_group5 = displayio.Group(scale=1, x=5, y=70)
text5 = str(display.width) + " x " + str(display.height)
text_area5 = label.Label(terminalio.FONT, text=text5, color=0x000000)
text_group5.append(text_area5) # Subgroup for text scaling
splash.append(text_group1)
splash.append(text_group2)
splash.append(text_group3)
splash.append(text_group4)
splash.append(text_group5)
time.sleep(3.0)
rot = 90
while True:
time.sleep(5.0)
rot = rot + 90
if (rot>=360):
rot = 0
display.rotation = rot
cpyESP32C3_st7735_slideshow.py, Test with exercise in "Creating Slideshows in CircuitPython".
"""
CircuitPython 7.2.0 exercise run on ESP32-C3-DevKitM-1
with 1.44" 128x128 (KMR1441_SPI V2)
- slideshow
ref:
adafruit/Adafruit_CircuitPython_ST7735R
https://github.com/adafruit/Adafruit_CircuitPython_ST7735R
"""
from sys import implementation as sysImplementation
import time
import os
import board
import busio
import displayio
import terminalio
from adafruit_st7735r import ST7735R as TFT_ST7735
from adafruit_st7735r import __name__ as ST7735_NAME
from adafruit_st7735r import __version__ as ST7735_VERSION
from adafruit_display_text import label
# Release any resources currently in use for the displays
displayio.release_displays()
#Connection between ESP32-C3 and SPI ST7735 display
#marking on display
tft_sck = board.IO2 #SCK
tft_mosi = board.IO3 #SDA
tft_dc = board.IO0 #A0
tft_reset = board.IO1 #RESET
tft_cs = board.IO10 #CS
#Backlight (LED) connect to ESP32-C3 3V3
#TFT VCC - ESP32-C3 3V3
#TFT GND - ESP32-C3 GND
tft_spi = busio.SPI(clock=tft_sck, MOSI=tft_mosi)
display_bus = displayio.FourWire(
tft_spi, command=tft_dc, chip_select=tft_cs, reset=tft_reset)
display = TFT_ST7735(display_bus, width=128, height=128,
rotation=90,
bgr=True)
strSys = sysImplementation[0] + ' ' + \
str(sysImplementation[1][0]) +'.'+ \
str(sysImplementation[1][1]) +'.'+ \
str(sysImplementation[1][2])
print("==========================================")
print(strSys)
print('run on ' + os.uname()[4])
print('using', ST7735_NAME, ST7735_VERSION)
print("==========================================")
print(type(display))
print("display.width: ", display.width)
print("display.height: ", display.height)
#===============================
# SPDX-FileCopyrightText: 2019 Anne Barela for Adafruit Industries
#
# SPDX-License-Identifier: MIT
# CircuitPython Slideshow - uses the adafruit_slideshow.mpy library
#import board
from adafruit_slideshow import PlayBackOrder, SlideShow
# Create the slideshow object that plays through once alphabetically.
slideshow = SlideShow(display,
folder="/images",
loop=True,
order=PlayBackOrder.ALPHABETICAL,
dwell=5)
while slideshow.update():
pass
cpyESP32C3_st7735_OnDiskBitmap.py, test with OnDiskBitmap example in "Display a Bitmap".
"""
CircuitPython 7.2.0 exercise run on ESP32-C3-DevKitM-1
with 1.44" 128x128 (KMR1441_SPI V2)
- OnDiskBitmap
ref:
adafruit/Adafruit_CircuitPython_ST7735R
https://github.com/adafruit/Adafruit_CircuitPython_ST7735R
"""
from sys import implementation as sysImplementation
import time
import os
import board
import busio
import displayio
import terminalio
from adafruit_st7735r import ST7735R as TFT_ST7735
from adafruit_st7735r import __name__ as ST7735_NAME
from adafruit_st7735r import __version__ as ST7735_VERSION
from adafruit_display_text import label
# Release any resources currently in use for the displays
displayio.release_displays()
#Connection between ESP32-C3 and SPI ST7735 display
#marking on display
tft_sck = board.IO2 #SCK
tft_mosi = board.IO3 #SDA
tft_dc = board.IO0 #A0
tft_reset = board.IO1 #RESET
tft_cs = board.IO10 #CS
#Backlight (LED) connect to ESP32-C3 3V3
#TFT VCC - ESP32-C3 3V3
#TFT GND - ESP32-C3 GND
tft_spi = busio.SPI(clock=tft_sck, MOSI=tft_mosi)
display_bus = displayio.FourWire(
tft_spi, command=tft_dc, chip_select=tft_cs, reset=tft_reset)
display = TFT_ST7735(display_bus, width=128, height=128,
rotation=90,
bgr=True)
strSys = sysImplementation[0] + ' ' + \
str(sysImplementation[1][0]) +'.'+ \
str(sysImplementation[1][1]) +'.'+ \
str(sysImplementation[1][2])
print("==========================================")
print(strSys)
print('run on ' + os.uname()[4])
print('using', ST7735_NAME, ST7735_VERSION)
print("==========================================")
print(type(display))
print("display.width: ", display.width)
print("display.height: ", display.height)
#===============================
# SPDX-FileCopyrightText: 2019 Carter Nelson for Adafruit Industries
#
# SPDX-License-Identifier: MIT
#import board
#import displayio
#display = board.DISPLAY
# Future method for CircuitPython 7 onwards
# Setup the file as the bitmap data source
bitmap = displayio.OnDiskBitmap("images/002.bmp")
# Create a TileGrid to hold the bitmap
tile_grid = displayio.TileGrid(bitmap, pixel_shader=bitmap.pixel_shader)
# Create a Group to hold the TileGrid
group = displayio.Group()
# Add the TileGrid to the Group
group.append(tile_grid)
# Add the Group to the Display
display.show(group)
# Loop forever so you can enjoy your image
while True:
pass
cpyESP32C3_st7735_ImageLoad.py, test with example of ImageLoad in "Display a Bitmap"
"""
CircuitPython 7.2.0 exercise run on ESP32-C3-DevKitM-1
with 1.44" 128x128 (KMR1441_SPI V2)
- ImageLoad
ref:
adafruit/Adafruit_CircuitPython_ST7735R
https://github.com/adafruit/Adafruit_CircuitPython_ST7735R
"""
from sys import implementation as sysImplementation
import time
import os
import board
import busio
import displayio
import terminalio
from adafruit_st7735r import ST7735R as TFT_ST7735
from adafruit_st7735r import __name__ as ST7735_NAME
from adafruit_st7735r import __version__ as ST7735_VERSION
from adafruit_display_text import label
# Release any resources currently in use for the displays
displayio.release_displays()
#Connection between ESP32-C3 and SPI ST7735 display
#marking on display
tft_sck = board.IO2 #SCK
tft_mosi = board.IO3 #SDA
tft_dc = board.IO0 #A0
tft_reset = board.IO1 #RESET
tft_cs = board.IO10 #CS
#Backlight (LED) connect to ESP32-C3 3V3
#TFT VCC - ESP32-C3 3V3
#TFT GND - ESP32-C3 GND
tft_spi = busio.SPI(clock=tft_sck, MOSI=tft_mosi)
display_bus = displayio.FourWire(
tft_spi, command=tft_dc, chip_select=tft_cs, reset=tft_reset)
display = TFT_ST7735(display_bus, width=128, height=128,
rotation=90,
bgr=True)
strSys = sysImplementation[0] + ' ' + \
str(sysImplementation[1][0]) +'.'+ \
str(sysImplementation[1][1]) +'.'+ \
str(sysImplementation[1][2])
print("==========================================")
print(strSys)
print('run on ' + os.uname()[4])
print('using', ST7735_NAME, ST7735_VERSION)
print("==========================================")
print(type(display))
print("display.width: ", display.width)
print("display.height: ", display.height)
#===============================
# SPDX-FileCopyrightText: 2019 Carter Nelson for Adafruit Industries
#
# SPDX-License-Identifier: MIT
#import board
#import displayio
import adafruit_imageload
#display = board.DISPLAY
bitmap, palette = adafruit_imageload.load("images/003i.bmp",
bitmap=displayio.Bitmap,
palette=displayio.Palette)
# Create a TileGrid to hold the bitmap
tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette)
# Create a Group to hold the TileGrid
group = displayio.Group()
# Add the TileGrid to the Group
group.append(tile_grid)
# Add the Group to the Display
display.show(group)
# Loop forever so you can enjoy your image
while True:
pass
No comments:
Post a Comment