Pico Display Pack 2.8" - micropyton firmware

I’m setting up a generic display interface on a Pico 2 W. The display and switches are working but I can’t figure out how to control the LED. Is there any documentation on the LED interface? The LED pins may have changed on the pico 2 w as the switch pins were not the same as the pico 1.

Thanks for the help,
Curt

It’s easy to miss, but it is mentioned on the product page.
Note that the RGB LED is hooked up to different pins on 2.8" (26, 27 and 28) so you may need to adjust for this in your code.
EDIT: There is also a link to the schematic, which should really help you out.
What Pico is attached has no bearing on the pins used. The Display pack dictates what pins are used.

Thanks for the quick reply. I looked at the schematic but it doesn’t show how to use the pins to set the LED color. I’m not a hardware guy so I might be missing something. Couldn’t find any coding examples.

Curt

That I can help with as I like to turn them off if I’m not using them. I’ll also throw in some button code just for fun. =)
EDIT: Let me know if the button code acts up, I seem to remember having issues with a PICO 2?

from pimoroni import RGBLED, Button
led = RGBLED(26, 27, 28)
led.set_rgb(0, 0, 0)

button_a = Button(12)
button_b = Button(13)
button_x = Button(14)
button_y = Button(15)

while True:

    if button_a.is_pressed:
        led.set_rgb(255, 0, 0) 
                
    if button_b.is_pressed:
        led.set_rgb(0, 255, 0)

    if button_x.is_pressed:
        led.set_rgb(0, 0, 0) 
                
    if button_y.is_pressed:
        led.set_rgb(0, 0, 255)





Just plugged in a Pico 2 / Display Pack 2 setup and found this in my main.py. You already have the buttons working, but I thought I’d post it for anybody else that might read this thread. ;)

button_a = Pin(12, Pin.IN, Pin.PULL_UP)
button_b = Pin(13, Pin.IN, Pin.PULL_UP)
button_x = Pin(14, Pin.IN, Pin.PULL_UP)
button_y = Pin(15, Pin.IN, Pin.PULL_UP)

while True:
    
    if button_a.value() == 0:
        led.set_rgb(255, 0, 0)
    elif button_b.value() == 0:
        led.set_rgb(0, 255, 0)
    elif button_x.value() == 0:
        led.set_rgb(0, 0, 0)
    elif button_y.value() == 0:
        led.set_rgb(0, 0, 255)

OK - we’re getting close. I am not using Pimoroni firmware. What does ‘led.set_rgb (…)’ do to change the color output?

Also in order to get the pins to match the display labels I have to use these settings:

SWA_PIN = const (15)
SWB_PIN = const (13)
SWX_PIN = const (14)
SWY_PIN = const (12)

Curt

The way it works is, led.set_rgb (red, green, blue). 0 is off and 255 is full bright.
led.set_rgb (255, 255, 0) is yellow for example.
led.set_rgb (255, 255, 255) is white.
(rgb color values for led - Search Videos

Here is what I was looking for:

from time import sleep
from machine import Pin, PWM

PIN_RED = const (27)
PIN_GREEN = const (28)
PIN_BLUE = const (26)
FREQ = const (100)

pin_red = PWM (Pin (PIN_RED), freq = FREQ)
pin_green = PWM (Pin (PIN_GREEN), freq = FREQ)
pin_blue = PWM (Pin (PIN_BLUE), freq = FREQ)

def set_rgb (r, g, b) :
    pin_red.duty_u16 (int (r * 65535 / 255))     # RED: 
    pin_green.duty_u16 (int (g * 65535 / 255)) # GREEN:
    pin_blue.duty_u16 (int (b * 65535 / 255))  # BLUE:


print ("red")
set_rgb (255, 0, 0)
sleep (5)

print ("green")
set_rgb (0, 255, 0)
sleep (5)

print ("blue")
set_rgb (0, 0, 255)

As with the buttons, the pins don’t match the schematic.

Colors look kind of weird but that may be the nature of an RGB LED.

Curt

Looking at the schematic,
SWA is GP12 physical pin 16
SWB is GP13 physical pin 17
SWX is GP14 physical pin 19
SWY is GP15 physical pin 20

Which is what I used above. I just double checked my setup and the buttons are doing what I programed them to do on a version 2 Display Pack. I’ll hunt up my version 2.8 and check that one also.

LED R is GP28 physical pin 31
LED G is GP27 physical pin 32
LED B is GP26 physical pin 34

I think you have yours mixed up?
PIN_RED = const (27)
PIN_GREEN = const (28)
PIN_BLUE = const (26)

This my sort of test code. My buttons are working correctly and my LED is showing the correct colors. Display Pack 2.8 on a Pico 2.

import time
import random
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY_2, PEN_P8
from pimoroni import RGBLED, Button

display = PicoGraphics(display=DISPLAY_PICO_DISPLAY_2, pen_type=PEN_P8)
display.set_backlight(1.0)

WIDTH, HEIGHT = display.get_bounds()

led = RGBLED(26, 27, 28)
led.set_rgb(0, 0, 0)

from machine import Pin

button_a = Pin(12, Pin.IN, Pin.PULL_UP)
button_b = Pin(13, Pin.IN, Pin.PULL_UP)
button_x = Pin(14, Pin.IN, Pin.PULL_UP)
button_y = Pin(15, Pin.IN, Pin.PULL_UP)


# We're creating 100 balls with their own individual colour and 1 BG colour
# for a total of 101 colours, which will all fit in the custom 256 entry palette!


class Ball:
    def __init__(self, x, y, r, dx, dy, pen):
        self.x = x
        self.y = y
        self.r = r
        self.dx = dx
        self.dy = dy
        self.pen = pen


# initialise shapes
balls = []
for i in range(0, 100):
    r = random.randint(0, 10) + 3
    balls.append(
        Ball(
            random.randint(r, r + (WIDTH - 2 * r)),
            random.randint(r, r + (HEIGHT - 2 * r)),
            r,
            (14 - r) / 2,
            (14 - r) / 2,
            display.create_pen(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)),
        )
    )

BG = display.create_pen(40, 40, 40)

while True:
    
    if button_a.value() == 0:
        led.set_rgb(255, 0, 0)
    elif button_b.value() == 0:
        led.set_rgb(0, 255, 0)
    elif button_x.value() == 0:
        led.set_rgb(0, 0, 0)
    elif button_y.value() == 0:
        led.set_rgb(0, 0, 255)
    else:
        display.set_pen(BG)
        display.clear()        
    
        for ball in balls:
            ball.x += ball.dx
            ball.y += ball.dy

            xmax = WIDTH - ball.r
            xmin = ball.r
            ymax = HEIGHT - ball.r
            ymin = ball.r

            if ball.x < xmin or ball.x > xmax:
                ball.dx *= -1

            if ball.y < ymin or ball.y > ymax:
                ball.dy *= -1

            display.set_pen(ball.pen)
            display.circle(int(ball.x), int(ball.y), int(ball.r))

        display.update()
        time.sleep(0.01)

Looks like both our implementations work. Pimoroni may be fiddling with the pin numbers to maintain backward or cross compatibly.

Good discussion,
Curt

1 Like

In case you are curious, here is the code I used to interface to the Display Pack:

import display_modules.st7789py as st7789

SPI_ID = const (0)
BAUDRATE = const (40000000)
SCK_PIN = const (18)
MOSI_PIN = const (19)
MISO_PIN = None
RESET_PIN = const (11)
CS_PIN = const (17)
DC_PIN = const (16)
BACKLIGHT_PIN = const (20)
HEIGHT = const (320)
WIDTH = const (240)

st_display = st7789.ST7789 (
        SPI (SPI_ID ,
             baudrate = BAUDRATE ,
             sck = SCK_PIN ,
             mosi = MOSI_PIN ,
             miso = MISO_PIN) ,
        WIDTH ,
        HEIGHT ,
        reset = Pin (RESET_PIN, Pin.OUT) ,
        cs = Pin (CS_PIN, Pin.OUT) ,
        dc = Pin (DC_PIN, Pin.OUT) ,
        backlight = Pin (BACKLIGHT_PIN, Pin.OUT) ,
        rotation = ROTATION)

Link to st7789 driver

Demo output:

1 Like

It is an interesting conversation. You doing it with plain old vanilla Micro Python does make it interesting. There are a few others here that like doing it that way when possible. I’m too lazy and impatient to go that route. ;)