• Hello,

    I have 3 puckjs devices that I am experimenting with but I have having issues with the new releases of firmware.

    1v91 - Can't save any program by typing "save()" into the terminal using the Espruino Web IDE.
    1v92 - Won't connect to windows 10 if un-paired and re-paired.

    I am using nRF Toolbox on iOS to update the firmware and using the "espruino_1v91_puckjs.zip" and "espruino_1v92_puckjs.zip" firmwares.

    None of these issue present themselves on the two puck devices that are running 1v88. Just the one I have been changing the firmware on.

    Ideally I want to be running 1v92 so that I can use the pucks as a keyboard button. But 1v88 doesn't support windows HID.

  • What actually happens when you type save() on 1v91? What does it display?

    As a sanity check, can you run this on the Puck that's having trouble?

    var f = require("Flash");
    for (var i=119;i>=115;i--) {
      print(i);
      f.erasePage(i*4096);
    }
    

    It'll clear out any saved code, but also the bonding region (which might be causing problems after the 1v92 update)

  • Before running that flash code it was writing to the terminal noticeably slower. Now it is speedy and the save function works! Thank you.

    Does 1v91 support the HID on windows?
    What are in those memory locations?

    It was doing nothing when I typed save() before. Completely froze up.

  • Wow, strange about the crash. Were you doing anything strange before that you think could have caused this?

    Does 1v91 support the HID on windows?

    No, but now you've run that code, 1v92 may well work just fine.

    What are in those memory locations?

    It depends on what firmware you have...

    • 1v91: 117-119 are saved code
    • 1v92: 115-117 are saved code, 118-119 are used for storing the encryption keys for bonded devices
  • OK so i tried updating the firmware from 1v91 to 1v92 and as soon as it was done uploading three leds are blinking at me. I won't connect now. I tried re-flashing 1v92 but the three lights persist.
    I am going to try 1v91 to 1v92 again.

  • At the moment I am using this code and the winnus library on nodejs to connect throught the bluetooth in a crude way to send key commands to demonstrate the capability of the puckjs for our application.

    Puckjs code

    var  on = false;
    var buttonID = "button_left";
    
    var flashLED = function() {
      on = !on;
      LED2.write(on);
      var interval;
      if(on) {
        interval = 5;
      } else {
        interval = 3000;
      }
      setTimeout(flashLED, interval);
    };
    
    flashLED();
    
    
    var buttonWatcher = function() {
      LED2.write(true);
      console.log(buttonID);
    };
    
    setWatch(buttonWatcher, BTN, { repeat:true, edge:'falling', debounce:50 });
    

    Nodejs code:

    var winnus = require("winnus");
    var robot = require('robotjs')
    
    var all_devices = []
    var device;
    
    var name = process.argv[2];
    all_devices = winnus.getDevices();
    
    all_devices.forEach(function(d) {
        if(d.name.includes(name)) {
            device = d;
        }
    });
    console.log(device);
    
    console.log("connecting..");
    winnus.connect(device, (data) => {
        console.log("data: " + JSON.stringify(data));
        if(data.includes('button_c')) {
            robot.typeString('c');
        }
        else if(data.includes('button_left')) {
            robot.keyTap('right');
        }
        else if(data.includes('button_right')) {
            robot.keyTap('left');
        }
    });
    winnus.write('on;\n');
    
    
    

    Obviously not an ideal solution.

  • Ok so i figure out that the three light flashing when I upgraded the firmware is occuring with this code loaded:

    var kb = require("ble_hid_keyboard");
    var on = false;
    
    function onInit() {
      NRF.setServices(undefined, { hid : kb.report });
      setWatch(btnPressed, BTN, {edge:"rising",repeat:true,debounce:50})­;
      flashLED();
    }
    
    function btnPressed() {
      kb.tap(kb.KEY["c"], 0);
    }
    
    var flashLED = function() {
      on = !on;
      LED1.write(on);
      var interval;
      if(on) {
        interval = 5;
      } else {
        interval = 3000;
      }
      setTimeout(flashLED, interval);
    };
    

    But with my other code that I posted there were no lights flashing at me.

    When I loaded this code with 1v92 it then tried to re-pair with windows it fails and the light stopped blinking on the puck. And I get the error "Try connecting your device again."

    It won't re pair no matter what mode I put it in on 1v92.

  • I'm not sure I understand exactly what happens with what code and what firmware...

    When you upload this code on 1v92:

    var kb = require("ble_hid_keyboard");
    var on = false;
    function onInit() {
      NRF.setServices(undefined, { hid : kb.report });
      setWatch(btnPressed, BTN, {edge:"rising",repeat:true,debounce:50})­;
      flashLED();
    }
    function btnPressed() {
      kb.tap(kb.KEY["c"], 0);
    }
    var flashLED = function() {
      on = !on;
      LED1.write(on);
      var interval;
      if(on) {
        interval = 5;
      } else {
        interval = 3000;
      }
      setTimeout(flashLED, interval);
    };
    

    did you type save() after uploading? And when you do that, disconnect and try and pair, pairing fails and the light stops blinking? but you don't get the 3 LEDs all lighting up together at any point?

  • Also, can you try running 1v92, then copy/pasting this code on to the left-hand side of the ide again:

    var f = require("Flash");
    for (var i=119;i>=115;i--) {
      print(i);
      f.erasePage(i*4096);
    }
    

    and then uploading your last bit of code and save() ing?

  • Sorry Gordon I am mixing in three different issues.

    1st issue was the not saving issue which was fixed with the Flash code.

    2nd issue was the pairing issue when i'm using the 1v92 code pairing with windows 10. It just won't pair no matter what I do. This is the real issue for me.

    3rd issue was something I noticed when upgrading from 1v91 to 1v92 that made the 3 lights blink. When I had the HID code loaded on 1v91 and then upgraded to 1v92 it made the 3 lights blink continuously. Not really a big problem if the code isn't loaded when upgrading firmware.

    All three are I think are independent of each other.

    I will have to wait till Monday to give it a try as I left everything at the office.

  • Ahh - right. Hopefully that code above might help with the pairing.

    I've got an issue open in GitHub at the moment to make the new firmware image wipe existing code - so hopefully with the upgrade to 1v93 you won't get that.

  • That definitely sounds like the right strategy, starting from a known state.

    I ran the flash in code #9 and loaded the new firmware, then ran the code again and initially eveything was ok. It paired after being un-paired everything worked as expected, yay. Then I loaded the HID code in #8 and then un-paired and re-paired, everything seemed to be working it appeared as a keyboard device but I tested it and the button was not registering key commands. Un-paired it and tried to repair but this time it wasn't re-pairing, damn.

    Seems to be something to do with being a HID device.

  • Got it I think. You're doing:

    function btnPressed() {
      kb.tap(kb.KEY["c"], 0);
    }
    

    but c doesn't exist - it's C that you want:

    function btnPressed() {
      kb.tap(kb.KEY["C"], 0);
    }
    

    There is no concept of upper of lower case keys - just a letter itself, and then whether you apply the SHIFT modifier itself. Confusingly C is actually lowercase c though - I didn't think that through :)

    If you upload the modified code then it might start working? Failing that, please could you try using the HID example unmodified, direct from the website in case there's something I missed?

  • Ah yep that is likely the reason it didn't register when it did connect.

    But I just can't connect 1v92 reliably to windows 10.

    My procedure:

    1. upload 1v90 (No issues connecting with this version)
    2. pair with puckjs
    3. run web ide and connect to puckjs
    4. run flash code in #9 in left hand side of web ide.
    5. clear saved code by deleting everything in the code box on the right hand side and uploading.
    6. save() in left hand side.
    7. upload 1v92
    8. puckjs is still paired at this point, in the web ide disconnect and reconnect. Run the flash code in #9.
    9. un-pair
    10. re-pair - Fail. Won't reconnect.

    Didn't even get to the part where I upload the HID code. What am I doing wrong?


    1 Attachment

    • puck_error.png
  • Are you sure the IDE itself has disconnected? It could be it's still hanging on to the connection?

    After you run the flash code, could you try resetting the puck? So just lift the edge of the battery a bit and when you release it the red LED should flash.

    Since you're basically deleting all the saved data, it's possible that the Puck's software gets confused when you then try and pair straight away.

  • ahah! Yes the IDE was holding on to the connection.

    So now it connects with 1v92. And I am now trying the HID software from your example:

    var kb = require("ble_hid_keyboard");
    NRF.setServices(undefined, { hid : kb.report });
    
    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})­;
    
    1. Device is connected with 1v92 to the web ide.
    2. run flash code in left side.
    3. upload the HID from you example.
    4. save()
    5. disconnect from Web IDE. !
    6. un-pair
    7. re-pair
    8. press puck button with pc cursor in a text box... nothing happens

    NB the device is not appearing in the list of keyboard devices


    1 Attachment

    • puck_bluetooth.png
  • Also tried resetting the puck with no differences, and turning the bluetooth off and on.

  • If I reconnect to the device using the WEB IDE then push the button I get this error:

    Uncaught Error: BLE HID not enabled
     at line 1 col 104
    ...0,0,0],function(){a&&a()})})
                                  ^
    in function "tap" called from line 9 col 4
      });
       ^
    in function called from system
    

    This should be normal through as the HID is not enabled if it is not connected as a HID device.

    unpairing, re-pairing doesn't enable it.
    unpairing, reseting the puck, re-pairing doesn't enable it.

  • Ahh, ok - the code you posted (with onInit()) needs a save() to take effect, but the example code from the keyboard doesn't - and in fact the save() might mess it up (I'll look into that for 1v93).

    Also, as before - you need to reboot after running the flash code. But hopefully now it's done you'll have no need for it.

    Try:

    • Device is connected with 1v92 to the web ide.
    • upload this code from right hand side:

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

    it's different from the example (as it initialises stuff in onInit)

    • type save() on left hand side
    • disconnect from Web IDE.
    • un-pair
    • re-pair
    • press puck button with pc cursor in a text box... should print aA

    I've literally just tried it here and it works for me.

    If you wanted to use the BLE example code you should be able to do the same steps without typing save() (I just tried here and it works), but then if you ever remove the battery it'll default to whatever was saved on it.

  • It works! Thank you for your help!

    So the way it runs is different when it is saved vs just uploaded ?

    I'm guessing the onInit function is called on start up of the device, but not called if just uploaded.

  • Great!

    Yes, that's the idea. Normally, you upload to RAM and onInit isn't called - it's almost as if you copy/pasted the code into the left-hand side.

    When you type save() it saves it all to flash memory and then restarts, and onInit() gets called.

    Ideally it should reload all the HID stuff (the call to NRF.setServices) automatically, even without you sticking it in onInit - but right now it appears that it doesn't. It's something I'll try and fix for the 1v93 firmware.

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

Saving on 1v91 and pairing on 1v92 with windows 10

Posted by Avatar for Boydy @Boydy

Actions