pimoroni / button-shim Goto Github PK
View Code? Open in Web Editor NEWPython library and examples for the Pimoroni Button SHIM
Home Page: https://shop.pimoroni.com/products/button-shim
License: MIT License
Python library and examples for the Pimoroni Button SHIM
Home Page: https://shop.pimoroni.com/products/button-shim
License: MIT License
As far as I see, the LED on the button shim is the same RGB LED pixel that is used on the Blinkt! pHAT. It would be easier to program with both shims/pHATs if the API would be more uniform, if possible.
The Blinkt! pHAT allows control of the PWM pixel brightness via set_brightness(brightness)
with the brightness
parameter ranging from 0.0 to 1.0. In contrast, the button shim has the PWN brightness hardcoded as "level" 31 (11111b).
Also, the Blinkt! pHAT has set_pixel(x, r, g, b, brightness=None)
which allows the brightness to be controlled independently from the RGB channel values. This actually gives better control, especially in the low brightness region -- the RGB pixel LEDs are very bright, so this better control is desirable.
I have uploaded some example code which illustrates passing a global variable from the button handlers in order to control the main program. I am new to GitHub, so I'm not sure you will be able to get to my repository. Had I had a simple example like this, it would have saved me a lot of time in development. Hope this helps someone.
Hey,
when I run the keyboard.py example the following error happens:
Traceback (most recent call last):
File "keyboard.py", line 32, in
@buttonshim.on_press([buttonshim.BUTTON_A, buttonshim.BUTTON_B, buttonshim.BUTTON_C, buttonshim.BUTTON_D, buttonshim.BUTTON_E])
File "/usr/lib/python2.7/dist-packages/buttonshim/init.py", line 294, in on_press
setup()
File "/usr/lib/python2.7/dist-packages/buttonshim/init.py", line 186, in setup
_bus = smbus.SMBus(1)
IOError: [Errno 2] No such file or directory
Does anybody have an idea what the failure is?
Since on_held
triggers after on_press
, and binding an action to hold
and press
events isn't intuitive or obvious, add an example to document how to accomplish this using a simple single-variable state monitor, and triggering the buttons primary (press) action within the release handler.
See: https://forums.pimoroni.com/t/button-shim-hold-issue/10157
When browsing through button-shim/library/buttonshim/__init__.py
to learn new tricks, I noticed something that looks odd to me, but I might be wrong here: near the end there's a "while True:" and this loop contains function definitions. Shouldn't these definitions go before the while loop?
...or am I missing a hardware upgrade here? ;) According to the product photos and the library code there are only five hardware buttons A to E present. Can I get a nitpicking
label, please?
It may be good to know to users of the buttonshim library that the button callbacks (handlers) are called from a new thread.
Hi,
I'm using raspbian stretch lite and after entering the one line installer my simple script won't run, saying smbus is not installed. Here is the error message:
Traceback (most recent call last): File "/home/pi/Scripts/Seismograph/Button-shim-test.py", line 1, in <module> import buttonshim File "/usr/local/lib/python3.6/site-packages/buttonshim/__init__.py", line 1, in <module> import smbus ModuleNotFoundError: No module named 'smbus'
I looked online how to install smbus and I have conflicting answers. I tried
sudo pip3 install smbus
and I get
Could not find a version that satisfies the requirement smbus (from versions: ) No matching distribution found for smbus
Which I don't really understand. Can you help me find a way around this issue?
Thanks!
Hi, I've noticed a bug on this line.
button-shim/examples/volume.py
Line 38 in 2279b2b
After trying the original command in terminal I believed the wrong value was used.
"amixer get 'Master' | awk '$0~/%+/ {print $5;exit}' | tr -d '[]%'"
Changing $4 to $5 returned 100 twice. Adding ;exit only returns the first value.
As is setting mute and unmute work fine but changing the volume does not.
Maybe upgrading to the alsaaudio module would be an improvement.
When I did get this working before keeping the button pressed cause the sound to distort.
Shorting pins 5 and 6 (GPIO3 and GND) together will wake the Pi up from a halt state. Is there a way to use these buttons to do so?
Source:
https://howchoo.com/g/mwnlytk3zmm/how-to-add-a-power-button-to-your-raspberry-pi
Make them just A
, B
, etc? Seems redundant to also have BUTTON_
...
Hello,
After doing a fresh install, using Buster image, and following your README instructions, the ButtonShim produces the following I/O error:
pi@rpiz-inky-phat:~/Pimoroni/button-shim/examples` $ python rainbow.py
Button SHIM: rainbow.py
Light up the LED a different colour of the rainbow with each button pressed.
Press Ctrl+C to exit.
Traceback (most recent call last):
File "rainbow.py", line 16, in <module>
@buttonshim.on_press(buttonshim.BUTTON_A)
File "/usr/local/lib/python2.7/dist-packages/buttonshim/__init__.py", line 294, in on_press
setup()
File "/usr/local/lib/python2.7/dist-packages/buttonshim/__init__.py", line 188, in setup
_bus.write_byte_data(ADDR, REG_CONFIG, 0b00011111)
IOError: [Errno 121] Remote I/O error
pi@rpiz-inky-phat:~/Pimoroni/button-shim/examples $
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.