Most recent activity
-
Trying to get your Puck bluetooth button to connect to your Raspberry Pi (RPi) to control your projects remotely? Frustrated at how difficult it is to program the button and then get the Raspberry Pi to detect Puck button presses?
Since I spent so many hours trying to figure out how to connect the Puck.js bluetooth button, here's an explanation of how I did it so that you can save time:
Youtube Instructional Video:
https://youtu.be/Vmi1eM2KBsg
Code:
https://github.com/beebowman/EspruinoPuck/tree/mainWiring Instructions (in code comments):
https://github.com/beebowman/EspruinoPuck/blob/main/EspruinoButtonLED.py#Wiring instructions:
#1) Attach 5V to the + line on breadboard
#2) Attach GND to the - line on breadboard
#3) Connect pin 16 (GPIO 23) to the pushbutton on side A (one breadboard half)
#4) Connect the same side of pushbutton (side A) to the - of the breadboard
#5) Connect pin 12 (GPIO 18) to the longer side of the LED
#6) Connect longer (positive) side of LED to 220 Ohm resistor, on a second line of breadboard
#7) Connect the other end of resistor to - of the breadboard (GND)
(NOTE: The button wired here is a normal Raspberry Pi breadboard button, and is entirely optional in this case, but can help you troubleshoot to make sure the LED is working properly before trying to connect the Puck.js bluetooth button)
Fritzing Wiring diagram available upon request.Code below, to upload to your Puck.js button using the Espruino Web IDE interface:
(Note: as a bonus, this code also works to allow your Puck to function as a PowerPoint clicker to press through pages when in presentation mode!)
//Instructions at:https://core-electronics.com.au/guides/using-usb-and-bluetooth-controllers-with-python var kb = require("ble_hid_keyboard"); NRF.setServices(undefined, { hid : kb.report }); var reset_timer; var next = "b"; //this is the letter that goes to the terminal function sendNext(){ sendCharNext(); LED2.set(); setTimeout("LED2.reset()",1000); } function sendCharNext(){ if (next == next.toLowerCase()){ sk = 0; } else { sk = 0x02; } // send the "n" keyboard character kb.tap(kb.KEY[next.toUpperCase()], sk); } setWatch(function(e) { if(e.time-e.lastTime < 0.5){ // on short press slide goes one step forward sendNext(); } }, BTN, {edge:"falling", debounce:50, repeat:true});
I thought that "disconnect and reconnect" meant to disconnect the Espruino puck.js from its battery and then put the battery back in again, and/or to disconnect and reconnect it from the Espruino Web IDE.
For anyone out there with the same issue as me, where I just kept seeing that error, just wanted to clarify that the replies above mean to turn on/off the bluetooth on your laptop/computer itself, not the Espruino Web IDE. On a Mac, this means toggling the bluetooth button on/off in the top right menu bar of the Mac, as you would if you were disconnecting and reconnecting your AirPods, for example.
This resolved the issue for me!