PiPico and breakout_rgbmatrix5x5 (HELP ME)

Ok I’ve flashed the latest version of the custom MicroPython firmware 0.2.1 (the non adafruit version) to my Pico.
I’ve opened the breakout_rgbmatrix5x5 demo.py in Thonny.
I’ve connected my (working) 5x5 RGB Matrix Breakout to the Pico (3-5v to 3V3_out, SDA to pin 4, SCL to pin 5 and GND to pin 3).

I press run and nothing happens!

Do I need to specify which pins I am using for SDA and SCL? In desparation I tried this

i2c = PimoroniI2C(**{“sda”: 4, “scl”: 5})
matrix = BreakoutRGBMatrix5x5(i2c)

Still nothing BUT Thonny didn’t throw up any errors!

Thanks
Andrew

PS I’ve tried the breakout on multiple Picos

Have a look at the example, maybe it will help?
pimoroni-pico/micropython/examples/breakout_rgbmatrix5x5 at main · pimoroni/pimoroni-pico · GitHub

Ops, looks like that’s the file your running. How do you have it hooked up and what pins are you using?

I am using short jumper leads to connect the 3-5v to 3V3_out, SDA to pin 4, SCL to pin 5 and GND to pin 3 (I’ve also tried SDA to pin 1 and SCL to pin 2). There is nothing wrong with the leads as I used them to connect the breakout to a pi400.

Thonny set to the correct interpreter?
Have you run any other code on a PICO?

Near as I can tell, wired up as you have it, the stock demo file should work as its written.

PINS_BREAKOUT_GARDEN = {“sda”: 4, “scl”: 5}
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)

The interpreter is MicroPython (Raspberry Pi Pico).

And this blink script works fine

from machine import Pin, Timer
led = Pin(25, Pin.OUT)
timer = Timer()

def blink(timer):
led.toggle()

timer.init(freq=8, mode=Timer.PERIODIC, callback=blink)

OK, that’s good news, it eliminates a lot of what could have been an issue.
Maybe this will help?

I tried using the Raspberry Pi Pico I2C Scanner Code (from hackster.io) earlier but I kept getting

%Run -c $EDITOR_CONTENT
Traceback (most recent call last):
File “”, line 10
SyntaxError: invalid syntax

The code from your link (How To Electronics) was the same apart from the indents.

if len(devices) == 0:
print(“No i2c device !”)
else:
print(‘i2c devices found:’,len(devices))

for device in devices:
print("Decimal address: “,device,” | Hexa address: ",hex(device))

So that is one thing I’ve learnt today … make sure of your indents! I now get

Scan i2c bus…
i2c devices found: 1
Decimal address: 116 | Hexa address: 0x74

Yippee!!

Of course I also learnt that Pin(8) isn’t pin 8!! in the Raspberry Pi Pico I2C Scanner Code

sda=machine.Pin(8)
scl=machine.Pin(9)

But … Pin(8) is not the physical pin 8 but GP8 which is physical pin 11 (ergo Pin(9) = physical pin 12)

So for non programmers where Demo.py has

PINS_BREAKOUT_GARDEN = {“sda”: 4, “scl”: 5}
PINS_PICO_EXPLORER = {“sda”: 8, “scl”: 9}

it might be better written as

PINS_BREAKOUT_GARDEN = {“sda”: 4, “scl”: 5}
#sda = physical pin 6, scl = physical pin 7
PINS_PICO_EXPLORER = {“sda”: 8, “scl”: 9}
#sda = physical pin 11, scl = physical pin 12

To cut a loooooonnnggg story short IT WORKS!!!

Thanks to alphanumeric for all his/her help!!

Andrew

I’m a he. ;)

I do believe if you use “board” instead of “machine”, it will be the physical pin number.
It’s like Board versus BCM on a Pi.

Indents are a big deal in python. Just FYI code tags are three ` before and after your block of code. Use code tags when posting and it will retain the indents etc.

According to the pinout for the Explorer Base i2c uses
physical pin 27 / GPIO 21 for SCL and
physical pin 26 / GPIO 20 for SDA

That does not jive with what is in that demo example file?

I have an Explorer Base here and will have a try doing an i2c scan tomorrow. I also have a Breakout Garden Base on the way that I will try and remember to do the same thing on.

This worked on my PICO Explorer Base, machine = GPIO number

import machine
sda=machine.Pin(20)
scl=machine.Pin(21)
i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)
 
print('Scan i2c bus...')
devices = i2c.scan()
 
if len(devices) == 0:
  print("No i2c device !")
else:
  print('i2c devices found:',len(devices))
 
  for device in devices:  
    print("Decimal address: ",device," | Hexa address: ",hex(device))

I got the following with an RV3028 RTC plugged in. Its address is 52.
Scan i2c bus…
i2c devices found: 1
Decimal address: 82 | Hexa address: 0x52

So at the end of the day my simple version of demo.py is

import time
from pimoroni_i2c import PimoroniI2C
from breakout_rgbmatrix5x5 import BreakoutRGBMatrix5x5

i2c = PimoroniI2C(**{“sda”: 0, “scl”: 1})
#sda = board pin 1 a sc; = board pin 2
matrix = BreakoutRGBMatrix5x5(i2c)

colors =
colors.append((200, 0, 0))
colors.append((0, 255, 0))
colors.append((0, 0, 255))
colors.append((128, 128, 128))

x = 0
y = 0
col = 0

while True:
matrix.set_pixel(x, y, colors[col][0], colors[col][1], colors[col][2])
matrix.update()

x += 1
if x >= matrix.WIDTH:
    x = 0
    y += 1
    if y >= matrix.HEIGHT:
        y = 0
        col += 1
        if col >= len(colors):
            col = 0
        time.sleep(0.5)

time.sleep(0.01)

Why does left square bracket and right square bracket copy and paste and quote as a square?
LSB no space RSB
LSB one space RSB
[ ] LSB two spaces RSB
That is a bit annoying!!

That I don’t know, it’s likely something to do with the forum software?
As far as I know things like that don’t happen if you use code tags.

colors = []
colors.append((255, 0, 0))
colors.append((0, 255, 0))
colors.append((0, 0, 255))
colors.append((128, 128, 128))

If your not using an Explorer base or a Breakout Garden base, you could remove this,

from pimoroni_i2c import PimoroniI2C

PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}

i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)

and replace it with

import machine
sda=machine.Pin(20) # edit Pin number to GPIO you want to use
scl=machine.Pin(21)  # edit Pin number to GPIO you want to use. 
i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)