Plasma 2040 Button & Code Assistance

Hi, apologies if this is very basic. I’ve looked everywhere, and I can’t see to find (or perhaps understand) the answer on my own.

I recently picked up a Plasma 2040 to learn with. I have my micropython code working with the buttons on the board, along with some LEDs (woohoo)! However, I’d like to attach separate buttons, and I’m having issues.

Physical Connection Question:
I have two Adafruit Metal Pushbutton – 16 mm 6V RGV Momentary that I want to connect. How do I connect these? This is my first project and I’m a bit lost. From what I gather from the datasheet I should be connecting the C+ to power, and one of the non-RGB legs to my data pins? Reading the Plasma datasheet I thought that this might work: SWC and SWD for my data pins, and 5V and 3V3 for my power pins? I don’t need RGB at this time.

Is this how they should be connected? Apologies again, I have no idea how to read these datasheets and my search for answer to these questions didn’t result in much.

Coding Question:

My current code is as follows:


from plasma import plasma2040
from pimoroni import RGBLED, Button

button_a = Button(plasma2040.BUTTON_A)
button_b = Button(plasma2040.BUTTON_B)

…etc…

if button_a.read():

…etc…

I tried looking for the equivalent of the “BUTTON_A” or “BUTTON_B” for SWC and SWD, but I can’t seem to find it. Alternatively, I tried finding what GPIO pins they were, but I don’t understand the schematic.

Can someone let me know the best way to add this to my code?

Thanks for the assistance, and for your time. I really appreciate it. Have a wonderful day!

Hi!

I’ve been working with the plasma 2040 and buttons for some time now. There are a few ways to do it, but the easiest is this:

with that, you can attach up to 14 buttons. You have to solder it to the plasma 2040, and then you can attach the buttons to the IOs (there are 14) and the GND. From there, you can read button presses very easily.

1 Like

Great, thanks for the information. I appreciate it!

Is there any way that I can make the buttons work with what I have already?

1 Like

Hi! I just saw this is your first project. My advice would be that you splash out and buy the IO expander and some female to male jumper cables (you’ll also need a soldering iron, but you’d need that however you decide to connect the buttons…).

I’ve been working with the plasma 2040 for around two years and I wouldn’t know how to do what you’re suggesting - although I am sure it would be easy for someone with more knowledge than me.

The IOExpander has clearly labelled GPIO pins. You should connect the buttons to GPIO1 and GPIO2 on one side, and GND on the other. When the button is pressed, you can read if those pins are connected in your micropython code.

You’ll also need to connect the 5v (on the plasma2040) and GND to the LEDs on the buttons. Don’t connect the 3v3 connector to anything - you don’t need it.

If you get the IOexpander let me know and I’ll share some code, if I can find it. It’s a great bit of kit for your first project, I hope you are able to get it working.

I think you can do:

from machine import Pin
help(Pin.board)

to get a list of available pins in MicroPython?

1 Like

@hel
Can you do something like this?

from pimoroni import Button

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

while True:
    if button_a.is_pressed:    


Edit the button = to match the GPIO used?

Yep, I think you can use either the pin number or the name.

SDA and SCL on the extension header are wired to GP20 and GP21.

1 Like

Thank you all for the help, I really appreciate it!

To clarify what @hel said:

SDA and SCL on the extension header are wired to GP20 and GP21

and what @alphanumeric said:

button_x = Button(14, invert=True)
button_y = Button(15, invert=True)

Does this meant that if I do something like this:

button_x = Button(20, invert=True)
button_x = Button(21, invert=True)

With the wires from my button going to the SDA and SCL labels on the Plasma 2040 it should work? Or, is this assuming that I have bought the IOExpander that was suggested previously?

Thanks again for your patience and assistance. Have a wonderful day!

Yes, though you’ll want to give your buttons different names (and you might not need the invert=True).

No ioexpander required if you just want to use the SDA / SCL pins for standard digital I/O, though if you use the pins like this you won’t also be able to use them with I2C devices like sensors.

Hel and Alphanumeric are these people and will be much more helpful than me😗👌

Send photos of your finished project!!

1 Like

Thank you all for the help!

I’m still having a bit of trouble getting the button to register any response in Thonny.

This is what I have physically done so far with the Plasma and the Button. It’s my first time soldering, be kind! I tried to label one of the photos to provide more context.

This is the code that I was using to try and test if the button presses were being recognized:

from pimoroni import Button
button_x = Button(20, invert=True)
button_y = Button(21, invert=True)

while True:
    
    if button_x.is_pressed: 
        print("Button X Pressed")
    
    if button_y.is_pressed: 
        print("Button Y Pressed")

I’m not sure if I have the button pins correct. I was using the datasheet for the button to try and figure it out.

Any idea what I’m doing wrong here?

Thank you all again for your patience, time, and help! Have a wonderul day!

Edit - this was flagged as spam / advertisement. I’m not trying to sell anything, just be helpful and save people some time searching to find information, as they are already taking the time to help me as-is. Please let me know if anything else in the post needs to change.

Try taking out the invert=True part.

Thanks for the suggestion. Unfortunately, that didn’t seem to work. I had tried invert=False before posting, and I just tried to remove it all together. It didn’t seem to change anything.

On my tufty, the number used is the GPIO number.
Pressing a button pulls that pin High, (3.3V).
button_a = Button(7, invert=False)

The number used on my Pico Display Pack is also the GPIO number.
Pressing a Button on that pulls that pin Low, (ground).
button_a = Button(12)

How are your switches / buttons wired? Do you have a multimeter?

Thanks again for your help.

The button itself is an “Adafruit Rugged Metal Pushbutton - 16mm 6V RGB Momentary”. I put the link to the datasheet in a comment above. Unfortunately, I am unable to post the link as it is getting flagged this time for some reason.

Apologies, one of the problems that originally spurred me reaching out is I don’t really know how to read the datasheets.

Additionally, I have photos of how I wired the buttons to the board in the same post above. Again, I’m unable to post the link as it is getting flagged.

I do have access to a multimeter - how would I go about using it in this situation?

Rugged Metal Pushbutton - 16mm 6V RGB Momentary : ID 3350 : $10.95 : Adafruit Industries, Unique & fun DIY electronics and kits

Z:\王文雄\英文图纸\GQ系列\GQ16\GQ16 GQ16F-10E-RGB-12V-S-IP67 (1) (adafruit.com)

The pin marked C+ is the Common for the RGB LED’s
The Pin marked Red is to light up the Red LED
The Pin marked Green is to light up the Green LED
The Pin marked Blue is to light up the Blue LED

The other two pins are the ones we are interested in. When the button is pressed, they are shorted together. Wire one pin to Ground and the other to your GPIO pin. Then, when the button is pressed, that GPIO will be grounded (pulled Low). Release the Button and its an open circuit again. You can verify that with an Ohmmeter. Multimeter set to measure resistance.

1 Like

Thank you so much! This explanation brought it all together for me. I sincerely appreciate you all taking the time to help me complete this. It’s now functioning as intended.

Once I have built the enclosure, I’ll post the finished photos. Thanks again, have a wonderful day!

2 Likes

No problem, happy to help. =)

looking forward to seeing your work!!

Here is the final project completed!

Left button starts a regular session: 60 minute total timer - 30 minutes green, 20 yellow, 10 red, flashing purple for 5 minutes after going over time.

Right button ends the current mode and resets it.

Holding the right button goes into a demo mode. Same color pattern, but condensed into a very short time frame to see the functionality.

The enclosure is a bit rough as I didn’t have small enough steps between the drill bits and there was some tear out. I fixed it as best as I could with sawdust and wood glue.

Likewise, my soldering needs a lot of practice and I didn’t want to fiddle with it too much in a tight space. So, I opted to bean the wires together when I had to get them in the enclosure.

I didn’t know micropython when I started this so there were a few challenges. Getting the colors to fade into one another smoothly - especially with the flashing at the end - was tough for me. Likewise, getting a reliable interrupt and reset was surprisingly difficult.

Overall, I’m really happy with how the project turned out for a first dip into this stuff. Lots of lessons learned. Now, I just need an excuse to build something else.

Thank you all for your incredible patience and help along the way. I literally could not have done this without it.

Happy holidays everyone! Have a wonderful day.

1 Like