Team2 display

From Sketching with Hardware at LMU Wiki
Jump to navigation Jump to search

Waveshare 1.28inch LCD Module with Raspberry Pi Pico[edit]

On this wiki page there is an instruction to setup the display and a Raspberry Pi Pico and run an example code, which shows a small animation on the screen.

Specifications[edit]

  • Operating voltage: 3.3V/5V
  • Interface: SPI
  • LCD type: IPS
  • Controller: GC9A01
  • Resolution: 240 (H)RGB x 240(V)
  • Display size: Φ32.4mm
  • Pixel size: 0.135(H)x 0.135(V)mm
  • Dimension: 40.4 × 37.5(mm) Φ37.5(mm)

Pinout[edit]

  • VCC: Voltage at the common collector
  • GND: Ground
  • DIN: Data In
  • CLK: Clock
  • CS: Chip Select
  • DC: Data command pin
  • RST: Reset
  • BL: Backlight

Advantages and Disadvantages[edit]

Advantages[edit]

  • Cheap (~22€)
  • Small and flat design
  • Clock shaped

Disadvantages[edit]

  • Does not work with Raspberry Pi natively, needs tinkering in that regard
  • The delivered wires are very long for a smartwatch

How to get it to work[edit]

In this section the display and the Raspberry Pi Pico will be set up to work together.

Setup[edit]

Before starting, make sure you have Micropython installed on your Pi Pico and the Thonny IDE on your PC.

Boot the Pico with necessary firmware[edit]

The first step to get the display to work with the Raspberry Pi Pico is to install a GC9A01 driver on the Pico.

  • Therefore you have to download firmware.uf2
  • Press and hold BOOTSEL pin of Raspberry Pi Pico and connect the USB cable, it will create a drive as RPI-RP2.
  • Now drag and drog/copy firmware.uf2 file from firmware folder to RPI-RP2 Drive. It will reboot your raspberry pi pico.
Wiring[edit]

You can just plug in the delivered cable into the display and this tutorial we connected the display with the Pico this way: \n LCD Pins to Pi Pico pins

  • VCC to 3V3
  • GND to GND
  • DIN to GP11
  • CLK to GP10
  • CS to GP9
  • DC to GP8
  • RST to GP12
  • BL to GP13

Example code (Flying toasts)[edit]

For this example you have to download all files except the Toaster.py from here and upload it to the Pi Pico.

Then you can copy the following file to your Pi Pico. As you can see, this code uses bitmaps to print the animations on the screen. The other files are including the position and the look of those bitmaps.

 1 """
 2 toasters.py
 3     An example using bitmap to draw sprites on the display.
 4     Spritesheet from CircuitPython_Flying_Toasters
 5     https://learn.adafruit.com/circuitpython-sprite-animation-pendant-mario-clouds-flying-toasters
 6 """
 7 
 8 import random
 9 from machine import Pin, SPI
10 import gc9a01
11 import t1, t2, t3, t4, t5
12 
13 TOASTERS = [t1, t2, t3, t4]
14 TOAST = [t5]
15 
16 class toast():
17     '''
18     toast class to keep track of a sprites locaton and step
19     '''
20     def __init__(self, sprites, x, y):
21         self.sprites = sprites
22         self.steps = len(sprites)
23         self.x = x
24         self.y = y
25         self.step = random.randint(0, self.steps-1)
26         self.speed = random.randint(2, 5)
27 
28     def move(self):
29         if self.x <= 0:
30             self.speed = random.randint(2, 5)
31             self.x = 240 - 64
32 
33         self.step += 1
34         self.step %= self.steps
35         self.x -= self.speed
36 
37 
38 def main():
39     """
40     Initialize the display and draw flying toasters and toast
41     """
42     spi = SPI(1, baudrate=40000000, sck=Pin(10), mosi=Pin(11))
43     tft = gc9a01.GC9A01(
44         spi,
45         240,
46         240,
47         reset=Pin(12, Pin.OUT),
48         cs=Pin(9, Pin.OUT),
49         dc=Pin(8, Pin.OUT),
50         backlight=Pin(13, Pin.OUT),
51         rotation=0)
52 
53     tft.fill(gc9a01.BLACK)
54     # create toast spites in random positions
55     sprites = [
56         toast(TOASTERS, 240-64, 0),
57         toast(TOAST, 240-64*2, 80),
58         toast(TOASTERS, 240-64*4, 160)
59     ]
60 
61     # move and draw sprites
62     while True:
63         for man in sprites:
64             bitmap = man.sprites[man.step]
65             tft.fill_rect(
66                 man.x+bitmap.WIDTH-man.speed,
67                 man.y,
68                 man.speed,
69                 bitmap.HEIGHT,
70                 gc9a01.BLACK)
71 
72             man.move()
73 
74             if man.x > 0:
75                 tft.bitmap(bitmap, man.x, man.y)
76             else:
77                 tft.fill_rect(
78                     0,
79                     man.y,
80                     bitmap.WIDTH,
81                     bitmap.HEIGHT,
82                     gc9a01.BLACK)
83 
84 main()

After uploading all required files and starting the script in the ThonnyIDE, you should see flying toast and toasters. Congratulations.

Instructional Video[edit]