File tree Expand file tree Collapse file tree 3 files changed +116
-0
lines changed Expand file tree Collapse file tree 3 files changed +116
-0
lines changed Original file line number Diff line number Diff line change
1
+ - Pull micropython for rp2350 (not yet merged to micropython repo) https://github.com/dpgeorge/micropython/tree/rp2-add-rp2350
2
+ - Pull st7789_mpy from https://github.com/russhughes/st7789_mpy
3
+ - Install tools for building micropython
4
+ - Build micropython for rp2350 with st7789_mpy ` make BOARD=RPI_PICO2 USER_C_MODULES=path/to/st7789_mpy/st7789/micropython.cmake `
5
+ - Flash firmware.u2f
6
+ - Run python code
Original file line number Diff line number Diff line change
1
+ """
2
+ ST7789 example for DC32 badge
3
+ """
4
+ import st7789
5
+ import tft_config
6
+ from machine import Pin
7
+ import neopixel
8
+ import time
9
+
10
+
11
+ num_pixels = 9
12
+ np = neopixel .NeoPixel (machine .Pin (4 ), num_pixels )
13
+ tft = tft_config .config (3 , buffer_size = 4096 ) #rotation 3 for normal orientation, 1 for upside down
14
+
15
+ def wheel (pos ):
16
+ # Input a value 0 to 255 to get a color value.
17
+ # The colours are a transition r - g - b - back to r.
18
+ if pos < 0 or pos > 255 :
19
+ return (0 , 0 , 0 )
20
+ if pos < 85 :
21
+ return (255 - pos * 3 , pos * 3 , 0 )
22
+ if pos < 170 :
23
+ pos -= 85
24
+ return (0 , 255 - pos * 3 , pos * 3 )
25
+ pos -= 170
26
+ return (pos * 3 , 0 , 255 - pos * 3 )
27
+
28
+ def rainbow_cycle (wait ):
29
+ for j in range (255 ):
30
+ for i in range (num_pixels ):
31
+ rc_index = (i * 256 // num_pixels ) + j
32
+ np [i ] = wheel (rc_index & 255 )
33
+ np .write ()
34
+ time .sleep (0.01 )
35
+
36
+ RED = (255 , 0 , 0 )
37
+ YELLOW = (255 , 150 , 0 )
38
+ GREEN = (0 , 255 , 0 )
39
+ CYAN = (0 , 255 , 255 )
40
+ BLUE = (0 , 0 , 255 )
41
+ PURPLE = (180 , 0 , 255 )
42
+
43
+
44
+
45
+ def demo (np ):
46
+ n = np .n
47
+
48
+ for i in range (0 , 4 * 256 , 8 ):
49
+ for j in range (n ):
50
+ if (i // 256 ) % 2 == 0 :
51
+ val = i & 0xff
52
+ else :
53
+ val = 255 - (i & 0xff )
54
+ np [j ] = (val , 0 , 0 )
55
+ np .write ()
56
+
57
+ def main ():
58
+
59
+ # Initial colors
60
+
61
+ np [0 ] = (255 , 0 , 0 )
62
+ np [1 ] = (0 , 128 , 0 )
63
+ np [2 ] = (0 , 0 , 64 )
64
+ np [3 ] = (255 , 0 , 0 )
65
+ np [4 ] = (0 , 128 , 0 )
66
+ np [5 ] = (0 , 0 , 64 )
67
+ np [6 ] = (255 , 0 , 0 )
68
+ np [7 ] = (0 , 128 , 0 )
69
+ np [8 ] = (0 , 0 , 64 )
70
+
71
+ np .write ()
72
+
73
+ png_file_name = f'lhc-320x240.png'
74
+ tft .init ()
75
+ print (f'Displaying { png_file_name } ' )
76
+ tft .png (png_file_name , 0 , 0 )
77
+
78
+ while (True ):
79
+ rainbow_cycle (0 ) # Increase the number to slow down the rainbow
80
+
81
+ main ()
Original file line number Diff line number Diff line change
1
+ """DC32 Badge display config"""
2
+
3
+ from machine import Pin , SoftSPI
4
+ from time import sleep
5
+ import st7789
6
+
7
+ TFA = 40 # top free area when scrolling
8
+ BFA = 40 # bottom free area when scrolling
9
+
10
+ def config (rotation = 0 , buffer_size = 0 , options = 0 ):
11
+ spi = SoftSPI (baudrate = 62500000 ,
12
+ polarity = 0 ,
13
+ phase = 0 ,
14
+ sck = Pin (8 ),
15
+ mosi = Pin (6 ),
16
+ miso = Pin (28 )) #SoftSPI needs a MISO pin, used one of the gpio on the SAO
17
+
18
+ return st7789 .ST7789 (
19
+ spi ,
20
+ 240 ,
21
+ 320 ,
22
+ cs = Pin (9 , Pin .OUT ),
23
+ dc = Pin (5 , Pin .OUT ),
24
+ backlight = Pin (10 , Pin .OUT ),
25
+ rotation = rotation ,
26
+ options = options ,
27
+ buffer_size = buffer_size ,
28
+ color_order = st7789 .RGB ,
29
+ inversion = False )
You can’t perform that action at this time.
0 commit comments