1- """
2- Simple badge script for Adafruit 2.13" 212x104 tri-color display
3- Supported products:
4- * Adafruit 2.13" Tri-Color Display Breakout
5- * https://www.adafruit.com/product/4086 (breakout) or
6- * https://www.adafruit.com/product/4128 (FeatherWing)
7-
8- This program requires the adafruit_il0373 library and the
9- adafruit_display_text library in the CIRCUITPY /lib folder
10- for CircuitPython 5.0 and above which has displayio support.
11- """
12-
13- import time
14- import board
15- import displayio
16- import adafruit_il0373
17- import terminalio
18- from adafruit_display_text import label
19-
20- BLACK = 0x000000
21- WHITE = 0xFFFFFF
22- RED = 0xFF0000
23-
24- # Change text colors, choose from the following values:
25- # BLACK, RED, WHITE
26-
27- TEXT_COLOR = BLACK
28- BACKGROUND_COLOR = WHITE
29-
30- # Used to ensure the display is free in CircuitPython
31- displayio .release_displays ()
32-
33- # Define the pins needed for display use
34- # This pinout is for a Feather M4 and may be different for other boards
35- spi = board .SPI () # Uses SCK and MOSI
36- epd_cs = board .D9
37- epd_dc = board .D10
38- epd_reset = board .D5
39- epd_busy = board .D6
40-
41- # Create the displayio connection to the display pins
42- display_bus = displayio .FourWire (spi , command = epd_dc , chip_select = epd_cs ,
43- reset = epd_reset , baudrate = 1000000 )
44- time .sleep (1 ) # Wait a bit
45-
46- DISPLAY_WIDTH = 212
47- DISPLAY_HEIGHT = 104
48- # Create the display object - the third color is red (0xff0000)
49- display = adafruit_il0373 .IL0373 (display_bus , width = DISPLAY_WIDTH ,
50- height = DISPLAY_HEIGHT ,
51- rotation = 90 , busy_pin = epd_busy ,
52- highlight_color = 0xff0000 )
53-
54- # Create a display group for our screen objects
55- g = displayio .Group ()
56-
57- # Set a background
58- background_bitmap = displayio .Bitmap (DISPLAY_WIDTH , DISPLAY_HEIGHT , 1 )
59- # Map colors in a palette
60- palette = displayio .Palette (1 )
61- palette [0 ] = BACKGROUND_COLOR
62-
63- # Put the background into the display group
64- bg_sprite = displayio .TileGrid (background_bitmap ,
65- pixel_shader = palette ,
66- x = 0 , y = 0 )
67- g .append (bg_sprite )
68-
69- # Display a picture from the root directory of the CIRCUITPY drive
70- # Picture should be HEIGHTxHEIGHT square idealy for a portrait
71- # But could be the entire WIDTHxHEIGHT for a non-portrait
72- f = open ("/picture.bmp" , "rb" )
73-
74- pic = displayio .OnDiskBitmap (f )
75- # Create a Tilegrid with the bitmap and put in the displayio group
76- t = displayio .TileGrid (pic , pixel_shader = displayio .ColorConverter ())
77- g .append (t )
78-
79- # Draw simple text using the built-in font into a displayio group
80- # For smaller text, change scale=2 to scale=1
81- text_group = displayio .Group (max_size = 10 , scale = 2 ,
82- x = DISPLAY_HEIGHT + 10 ,
83- y = int (DISPLAY_HEIGHT / 2 ) - 13 )
84- first_name = "Limor"
85- text_area = label .Label (terminalio .FONT , text = first_name ,
86- color = TEXT_COLOR )
87- text_group .append (text_area ) # Add this text to the text group
88- g .append (text_group )
89-
90- # Draw simple text using the built-in font into a displayio group
91- text_group = displayio .Group (max_size = 10 , scale = 2 ,
92- x = DISPLAY_HEIGHT + 10 ,
93- y = int (DISPLAY_HEIGHT / 2 ) + 13 )
94- last_name = "Ladyada"
95- text_area = label .Label (terminalio .FONT , text = last_name ,
96- color = TEXT_COLOR )
97- text_group .append (text_area ) # Add this text to the text group
98- g .append (text_group )
99-
100- # Place the display group on the screen
101- display .show (g )
102-
103- # Refresh the display to have it actually show
104- # NOTE: Do not refresh eInk displays more often than 180 seconds!
105- display .refresh ()
106-
107- # Wait the minimum 3 minutes between refreshes. Then loop to freeze.
108- time .sleep (180 )
109- while True :
110- pass
1+ """
2+ Simple badge script for Adafruit 2.13" 212x104 tri-color display
3+ Supported products:
4+ * Adafruit 2.13" Tri-Color Display Breakout
5+ * https://www.adafruit.com/product/4086 (breakout) or
6+ * https://www.adafruit.com/product/4128 (FeatherWing)
7+
8+ This program requires the adafruit_il0373 library and the
9+ adafruit_display_text library in the CIRCUITPY /lib folder
10+ for CircuitPython 5.0 and above which has displayio support.
11+ """
12+
13+ import time
14+ import board
15+ import displayio
16+ import adafruit_il0373
17+ import terminalio
18+ from adafruit_display_text import label
19+
20+ BLACK = 0x000000
21+ WHITE = 0xFFFFFF
22+ RED = 0xFF0000
23+
24+ # Change text colors, choose from the following values:
25+ # BLACK, RED, WHITE
26+
27+ TEXT_COLOR = BLACK
28+ BACKGROUND_COLOR = WHITE
29+
30+ # Used to ensure the display is free in CircuitPython
31+ displayio .release_displays ()
32+
33+ # Define the pins needed for display use
34+ # This pinout is for a Feather M4 and may be different for other boards
35+ spi = board .SPI () # Uses SCK and MOSI
36+ epd_cs = board .D9
37+ epd_dc = board .D10
38+ epd_reset = board .D5
39+ epd_busy = board .D6
40+
41+ # Create the displayio connection to the display pins
42+ display_bus = displayio .FourWire (spi , command = epd_dc , chip_select = epd_cs ,
43+ reset = epd_reset , baudrate = 1000000 )
44+ time .sleep (1 ) # Wait a bit
45+
46+ DISPLAY_WIDTH = 212
47+ DISPLAY_HEIGHT = 104
48+ # Create the display object - the third color is red (0xff0000)
49+ display = adafruit_il0373 .IL0373 (display_bus , width = DISPLAY_WIDTH ,
50+ height = DISPLAY_HEIGHT ,
51+ rotation = 90 , busy_pin = epd_busy ,
52+ highlight_color = 0xff0000 )
53+
54+ # Create a display group for our screen objects
55+ g = displayio .Group ()
56+
57+ # Set a background
58+ background_bitmap = displayio .Bitmap (DISPLAY_WIDTH , DISPLAY_HEIGHT , 1 )
59+ # Map colors in a palette
60+ palette = displayio .Palette (1 )
61+ palette [0 ] = BACKGROUND_COLOR
62+
63+ # Put the background into the display group
64+ bg_sprite = displayio .TileGrid (background_bitmap ,
65+ pixel_shader = palette ,
66+ x = 0 , y = 0 )
67+ g .append (bg_sprite )
68+
69+ # Display a picture from the root directory of the CIRCUITPY drive
70+ # Picture should be HEIGHTxHEIGHT square idealy for a portrait
71+ # But could be the entire WIDTHxHEIGHT for a non-portrait
72+ f = open ("/picture.bmp" , "rb" )
73+
74+ pic = displayio .OnDiskBitmap (f )
75+ # Create a Tilegrid with the bitmap and put in the displayio group
76+ t = displayio .TileGrid (pic , pixel_shader = displayio .ColorConverter ())
77+ g .append (t )
78+
79+ # Draw simple text using the built-in font into a displayio group
80+ # For smaller text, change scale=2 to scale=1
81+ text_group = displayio .Group (max_size = 10 , scale = 2 ,
82+ x = DISPLAY_HEIGHT + 10 ,
83+ y = int (DISPLAY_HEIGHT / 2 ) - 13 )
84+ first_name = "Limor"
85+ text_area = label .Label (terminalio .FONT , text = first_name ,
86+ color = TEXT_COLOR )
87+ text_group .append (text_area ) # Add this text to the text group
88+ g .append (text_group )
89+
90+ # Draw simple text using the built-in font into a displayio group
91+ text_group = displayio .Group (max_size = 10 , scale = 2 ,
92+ x = DISPLAY_HEIGHT + 10 ,
93+ y = int (DISPLAY_HEIGHT / 2 ) + 13 )
94+ last_name = "Ladyada"
95+ text_area = label .Label (terminalio .FONT , text = last_name ,
96+ color = TEXT_COLOR )
97+ text_group .append (text_area ) # Add this text to the text group
98+ g .append (text_group )
99+
100+ # Place the display group on the screen
101+ display .show (g )
102+
103+ # Refresh the display to have it actually show
104+ # NOTE: Do not refresh eInk displays more often than 180 seconds!
105+ display .refresh ()
106+
107+ # Wait the minimum 3 minutes between refreshes. Then loop to freeze.
108+ time .sleep (180 )
109+ while True :
110+ pass
0 commit comments