Keybow via node?


#1

Hope I’m posting this in the right place, So I’ve been trying to set up the Keybow to just work within node on base Raspbian.

const Gpio = require('onoff').Gpio;
const button17 = new Gpio(17, 'in', 'both');
const button27 = new Gpio(27, 'in', 'both');
const button23 = new Gpio(23, 'in', 'both');
const button22 = new Gpio(22, 'in', 'both');
const button24 = new Gpio(24, 'in', 'both');
const button5  = new Gpio(5 , 'in', 'both');
const button6  = new Gpio(6 , 'in', 'both');
const button12 = new Gpio(12, 'in', 'both');
const button13 = new Gpio(13, 'in', 'both');
const button20 = new Gpio(20, 'in', 'both');
const button16 = new Gpio(16, 'in', 'both');
const button26 = new Gpio(26, 'in', 'both');
const button7  = new Gpio(7,   'in', 'both');
const button8  = new Gpio(8,   'in', 'both');

button17.watch((err, value) => { console.log("but17:",value); });
button27.watch((err, value) => { console.log("but27:",value); });
button23.watch((err, value) => { console.log("but23:",value); });
button22.watch((err, value) => { console.log("but22:",value); });
button24.watch((err, value) => { console.log("but24:",value); });
button5.watch((err, value) =>  { console.log("but5:",value); });
button6.watch((err, value) =>  { console.log("but6:",value); });
button12.watch((err, value) => { console.log("but12:",value); });
button13.watch((err, value) => { console.log("but13:",value); });
button20.watch((err, value) => { console.log("but20:",value); });
button16.watch((err, value) => { console.log("but16:",value); });
button26.watch((err, value) => { console.log("but26:",value); });
button7.watch((err, value) =>  { console.log("but7:",value); });
button8.watch((err, value) =>  { console.log("but8:",value); });

I’m using the onoff library and initially I had it just to read the pins 1-12 and only got events from 5 and 6. Then I noticed this part in keybow.c

add_key(RPI_V2_GPIO_P1_11, 0x27, 3);
add_key(RPI_V2_GPIO_P1_13, 0x37, 7);
add_key(RPI_V2_GPIO_P1_16, 0x28, 11);
add_key(RPI_V2_GPIO_P1_15, 0x1e, 2);
add_key(RPI_V2_GPIO_P1_18, 0x1f, 6);
etc

So used the corrosponding pin references from bcm2835.h

/* RPi Version 2 */
RPI_V2_GPIO_P1_03     =  2,  /*!< Version 2, Pin P1-03 */
RPI_V2_GPIO_P1_05     =  3,  /*!< Version 2, Pin P1-05 */
RPI_V2_GPIO_P1_07     =  4,  /*!< Version 2, Pin P1-07 */
RPI_V2_GPIO_P1_08     = 14,  /*!< Version 2, Pin P1-08, defaults to alt function 0 UART0_TXD */
etc

As you can see above, but still only 5 and 6 worked. Anyone know where I’m going wrong?


#2

You should probably eliminate connection issues by installing “wiringpi” (sudo apt install wiringpi) and running gpio readall to see the pin states. You can run gpio readall periodically using something like - iirc - watch -n 0.1 gpio readall and then press each button and check for a response.

Otherwise I can’t see anything obviously wrong with your code- those are the right pins although you don’t need 7 and 8 (unless you’re using them for something else) since there are only 12 keys wired to the other pins.