Please help this newbie. Puck.js on Raspberry Pi 3B

Posted on
  • Sorry for this newbie question, first day playing with this.
    Everything is latest. Have EspruinoHub started in systemctl.
    I can connect to the raspberrypi EspruinoHub ide, connect to Puck and upload code.
    Puck firmware 2v00
    Found some code in tutorials and hacked it together. All I want to achieve is to have a button press result in a keyboard type the letter p

    After sending the code I disconnect and reconnect
    Click on the puck and console says

    Uncaught Error: Got BLE error 0x8 (INVALID_STATE)
     at line 1 col 104
    in function "tap" called from line 6 col 36
        kb.tap(kb.KEY.P, 0,function(){});
    in function called from system

    If I click the puck again I get

    Click 2

    Here is the full code:

    var kb = require("ble_hid_keyboard");
    NRF.setServices(undefined, { hid : });
    var clickcount = 0;
    var clickevent = null;
    setWatch((e) => {
      if (clickevent !== null) clearTimeout(clickevent);
      if (clickcount === 1) {
        setLEDS(false, true, false);
        kb.tap(kb.KEY.P, 0,function(){});
      } else if (clickcount === 2) {
        setLEDS(true, false, false);
        //kb.tap(kb.KEY.Z, 0);
      } else if (clickcount === 3) {
        setLEDS(false, false, true);
        //kb.tap(kb.KEY.S, 0);
      } else {
        setLEDS(true, true, true);
      clickevent = setTimeout(() => {
        if (clickcount === 1) {
          console.log("Click 1");
        } else if (clickcount === 2) {
          console.log("Click 2");
        } else if (clickcount === 3) {
          console.log("Click 3");
        clickcount = 0;
      }, 350);
    }, BTN, {
      edge: "rising",
      debounce: 50,
      repeat: true
    setWatch((e) => {
      setLEDS(false, false, false);
      setTimeout(() => {
        clickevent = null;
      }, 400);
    }, BTN, {
      edge: "falling",
      debounce: 50,
      repeat: true
    const setLEDS = (LED1on, LED2on, LED3on) => {
      if (LED1on) LED1.set();
      if (LED2on) LED2.set();
      if (LED3on) LED3.set();

    Thank you for helping me. I'm totally confused.

  • One additional piece of info. I tested this while connected bluetooth to my mac, everything worked without error. This only occurs when puck is connected to raspberry pi.
    I also used a much simpler code

    var kb = require("ble_hid_keyboard");
    NRF.setServices(undefined, { hid : });
    function btnPressed() {
      // Send 'a'
      kb.tap(kb.KEY.A, 0, function() {
        // Followed by capital 'A'
        kb.tap(kb.KEY.A, kb.MODIFY.SHIFT);
    // trigger btnPressed whenever the button is pressed
    setWatch(btnPressed, BTN, {edge:"rising",repeat:true,debounce:50})­;

    got the exact same error.
    there is something wrong with ble_hid_keyboard on the raspberry pi.

  • replacing tap with

    NRF.sendHIDReport([2,0,4], function() {

    results in the same error. so probably not ble_hid_keyboard issue.

  • I believe the issue is just that when you connect to Puck.js from the EspruinoHub IDE on the Raspberry Pi, it is connecting to just the Bluetooth Serial port. It's not connecting as a Keyboard device, so when you go to send keypresses the command fails.

    If you don't connect from the EspruinoHub IDE and instead connect via the Raspberry Pi's Bluetooth GUI, it'll might start treating it as a keyboard and it'd work fine.

    However looking at this post from a year ago, it's possible the Raspberry Pi doesn't support Bluetooth HID devices at all:­opic.php?t=176808

    Things may have changed in the last year though.

  • [Puck.js a766]# info E5:DD:7B:99:A7:66
    Device E5:DD:7B:99:A7:66
        Name: Puck.js a766
        Alias: Puck.js a766
        Paired: yes
        Trusted: yes
        Blocked: no
        Connected: yes
        LegacyPairing: no

    still doesnt work.
    What confuses me is that I can connect using EspruinoHub and send code to the device so I know that the Raspberry Pi is supporting BLE but it doesnt seem to support HID.
    Does anyone know why?

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Please help this newbie. Puck.js on Raspberry Pi 3B

Posted by Avatar for user95552 @user95552