Plasma 2040 and i2c to Qwiic GPIO

Hi all. Rather loving the Plasma 2040, which I’ve got in order to providing lights inside a prop for my teenage daughter’s school play. (The whole 5m of LED strip was probably a bit excessive, but hey.)

Anyway, they need to trigger a bunch of different lighting effects, so I’d planned to use a numeric keypad. That means scanning it, which means some kind of GPIO in order to have enough pins. So I’ve got a Qwiic GPIO attached via I2C. The Plasma 2040 can see the Qwiic exists:

from machine import Pin, I2C
i2c = I2C(0, sda=Pin(20), scl=Pin(21), freq=100000)

connectedstuff = i2c.scan()

print(connectedstuff)

This returns [39] in Thonny, which is the expected address according to the Qwiic docs.

However, I don’t think I’m able to install their Qwiic GPIO Python package on the Plasma2040. So how do I read from the I/O pins? Naively using print(i2c.readfrom(39,1)) throws an OSError: [Errno 5] EIO.

Bit stuck, so any help over this hump would be amazing. Then I can go back to making lights do pretty things using more than just the two onboard buttons!

I can’t help you with the i2c stuff.
But it looks like you can add two more buttons, SWC and SWD. Counting the Boot Select (which can be used as a user button) that’s 5.
Then do a “if A and B pressed” , “if B and C pressed”, etc for more options.

I don’t have one of the plasma boards, but from what I know you should be able to use the SDA/SCL/INT pins as GPIO, as well as A0-A2. As well as SWC and SWD? That should be plenty of buttons.

Just be aware that the keypad is a matrix, so you need to constantly be changing the pin you’re driving, as well as the pins you’re testing. That will be technically possible with the Qwiic Go, but the Go will need a whole stack of other code on top of it to control it, so doing it directly from the plasma will be easier.

The Go almost has a mini Arduino built in, so you’d need to set pins as outputs, set them as inputs, read them, and then swap the outputs for the keypad matrix. Bypassing that should make it more straightforward.

Oooh, that might work. And one less moving part too!

Thank heavens this stuff is considerably cheaper than my previous modular synth habit. :-)

Another newbie question - I’m guessing that connecting GPIO pins together without resistors is a no-no if you don’t want to fry the processor. However breadboard and raw components probably won’t survive theatre stage use. Particularly not by teenagers.

What’s the connoisseur’s choice for adding a bunch of inline resistors to a ribbon cable in the real world? Heatshrink?

Hi Tom!

I expect I may be too late to help you out with this. But in case anyone from the future is reading this, I would recommend getting an IO expander (very cheap and made by pimoroni) which can be easily put right on to the 5 pins on the top of the Plasma2040. the IO expander has 14 numbered pins, so that’s 14 buttons.

I am a former recovering modular synth addict so I understand your issue! But whenever the question “how do I solder X to Y?” comes into my head, I’ve learnt to take a step back and see if there’s another tool for the job.

The following code is used to read the inputs (connect a numbered pin to ground to “press” that button)

import time
import math
import plasma
from plasma import plasma2040
from pimoroni_i2c import PimoroniI2C
from pimoroni import RGBLED
from breakout_ioexpander import BreakoutIOExpander

# I2C config
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
i2c = PimoroniI2C(**PINS_PICO_EXPLORER)
ioe = BreakoutIOExpander(i2c, address=0x18)
for i in range(14):
    ioe.set_mode(i+1, BreakoutIOExpander.PIN_IN_PU)
buttonpress = 0

def pincheck():
    global buttonpress
    for i in range(1,15):
        if (ioe.input(i)) == 0: #button i is down 
            if (buttonpress != i): #this is a new button being pressed. 
                buttonpress = i
                
                if buttonpress == 1:
                                print("button 1 is being pressed")
                elif buttonpress == 2: 
#etc...


while True:
    pincheck()

There is this, which you can plug the Pimoroni IO expander into.
STEMMA QT / Qwiic to Breakout Garden Adapter - Pimoroni
Then into the Plasma with this cable.
JST-SH cable - Qwiic / STEMMA QT compatible - Pimoroni
And this if you need more.
SparkFun Qwiic MultiPort - Pimoroni

I’m using the cables, Hub and the following with my Pico Lipo.
Breakout Garden to STEMMA QT / Qwiic Adapter - Pimoroni
I have multiple breakouts on a proto board with the above adapter soldered on it.
And a BME688 that has a qwicc connector already on it.

Hi!

The IOexpander connects straight to the 5 pins on top of the plasma. No expanders, adaptors, or connecters needed. If all you need is 14 buttons, the IOexpander (and the short & sweet code I included) is the way to go ☺️

Having said that I am sure there are other advantages of doing it your way. I am not an expert by any stretch of the imagination, but I am very good at finding the path of least resistance 🌞

I should said, if you don’t want to have to solder. There is this option… ;)

There are usually multiple ways to get it done. Some are simple and some take a bit of work. In my case, the BME688 is going to be mounted externally to the bottom of my enclosure. Away from any heat given off by the electronics in the enclosure. And the proto board will be facing up under a glass cover. It has LUX and UV sensors on it.