5 button shim

#1

Hi i have a 5 button shim attached to a raspberry pi zero w.
I installed the software but have no idea how to run it, should I be doing it from the cmd line or python? Can someone help please. Also when I look in the pimoroni dashboard I can’t see anything option for a button shim!

0 Likes

#2

You code it in python. For testing you should be able to run commands from a terminal window.

The function reference is here
http://docs.pimoroni.com/buttonshim/

Just about any interactive pHat or Hat does its thing from python.
The button shim pinout is here

It’s using i2c

0 Likes

#3

Thanks I will try it later, one more thing the led on the button shim comes on and stays on when the picton is booted but if I boot it another time it doesn’t!

0 Likes

#4

I don’t own one myself so I don’t know if that LED is supposed to be on or not? What is a “picton” typo?
Do you have another pHat or Hat attached to your Pi? Something else using i2c maybe?

0 Likes

#5

Sorry yes picton is a typo meant to be pi, I have an inky phat on it as well which is working ok

0 Likes

#6

Inky pHat uses SPI so it shouldn’t be an issue using it with the button shim. Once you write your code for the button shim you could just put a command in to turn the LED off. Not ideal but one way around your issue. Or just ignore it.
Phil @gadgetoid may know what to look at. If it was me I’d just rerun the installer script for the button shim.

0 Likes

#7

Hi Alphanumeric, thanks for the advice. I will have trouble ignoring the LED as it is super bright and can probably be seen from space! I have now found the examples in /home/pi/Pimoroni/button-shim/examples so will check them out and see how I get on.

0 Likes

#8

I had one LED on my Phat Beat that would stay on full bright when I shut my Pirate Radio down. I think all I did was rerun the installer. That was a long time ago now, and hasn’t happened again since.
buttonshim.set_pixel(0, 0, 0) should turn the LED off.

0 Likes

#9

Thanks for that the led has decided to stay off at the moment! But I will adjust your code to see if I can get it to come on.

0 Likes

#10

Its really 3 LED’s a Red a Green and a Blue very close together in the one shell.
It should go something like this buttonshim.set_pixel(R, G, B). 0 is off and 255 is full bright for that LED
buttonshim.set_pixel(255, 0, 0) < Red
buttonshim.set_pixel(0, 255, 0) < Green
buttonshim.set_pixel(0, 0, 255) < Blue
buttonshim.set_pixel(255, 255, 0) < Yellow
buttonshim.set_pixel(255, 255, 255) < White
The number you use can be any number between 0 and 255.
https://www.w3schools.com/colors/colors_rgb.asp

0 Likes

#11

I am just guessing but maybe the reason for my LED to be on sometimes and off others is due to the values not yet being set, so maybe they are floating hence why the LED is on after a reboot and off after another reboot.
Once again thanks for the info

0 Likes

#12

I honestly don’t know? It uses i2c so I would double check your soldering especially pins 3 and 5. You would think the chip would default to off, and only turn the LED(s) on when told to? The way it works is serial data is sent to that chips address. And that data tells it which LED to turn on and how bright to make it, etc. It sounds like something isn’t initializing correctly? Thats why I suggested rerunning the installer.
If you run sudo i2cdetect -y 1 from a terminal window it should show up at address 3f

0 Likes

#13

I was seeing leds staying on, too. In my case, I had the i2c bus configured too fast.
I normally crank the i2c bus up to 400K because I’m also using an Adafruit OLED Bonnet, which uses i2c for the display and cranking the rate really helps fps. From the TCA9554 data sheet, it appears that the button shim’s gpio expander only goes to 400K max.
Turning it down to 350K eliminates the problem for me.

0 Likes

#14

Hi Alphanumeric and BeauSlim,

Thanks for the advice, the 5 button shim is now working, I don’t know why the LEDS came on randomly but since I have run some example codes they respond as they should, I think it was just a case that when I first turned it on I had no code running so the LEDS may have been floating at a logic level high enough to be a 1 and not a 0.
I went back to the beginning read the “Read me” etc and run an example (source code for button shim) using Python and it works, when I press a button it prints the text to say which button has been pressed and then released. All I have to do now is learn to program then I can assign buttons to run bash scripts which will change the display on the Inky Phat that is sitting on the PI, for example if I press button a it will show the current weather and button b will show a calendar.

0 Likes

#15

Most of the time, one of the first things I do is run one or two of the example scripts. Or do something up quick and simple to test what ever it is I just hooked up. Just to be sure its working as it should. Once thats done I can take all the time I need to code in what I bought it to do. ;)
Nice to hear that its now working as it should. I’ve had a few “is it broken, or is it just me not knowing what to do” moments. Especially when it comes to python coding.

1 Like