Click Puck registered on Raspberry Pi

Posted on
  • Hey all,

    Is there a simple way for the Puck to notify a Raspberry Pi once it has been clicked with relative low latency?

    I have a Marantz AVR and unfortunately, the remote isn't great, however it's got a good API and I've managed to code together some modes using Node JS.

    What I'd like to do is when the Puck is pressed, either a HTTP endpoint is called or the Puck communicates directly with the Pi which in turn would run the relevant NodeJS code.

    What's the best way for a low latency click being registered on a Pi?

  • There's some code specifically for Node.js in this tutorial that might help you out: http://www.espruino.com/Puck.js+AdvertisĀ­ing

    There are other ways of doing it (like with a connection) but this way is nice and easy and doesn't require any pairing or connection. When using NRF.setAdvertising on the Puck you can choose a low interval (as low as 7.5ms) which would get the latency down, but that will hurt your battery life so you might want to think about having the Puck lower the interval down to 300ms or so after an hour of inactivity.

    Hope that helps!

  • Hi Gordon,

    That's quite nifty! I had gone through the tutorials but totally missed that one!

    I saw that it's possible to emit IR from the Puck. Would it be possible for the Pi to listen to IR events and respond accordingly? Would this be faster?

    Thanks!

  • Yes, you could put an IR receiver on the Pi - the Puck isn't that long-range with IR though (around a meter).

    Thing is, a normal IR signal contains a ~9ms start pulse (http://www.espruino.com/Puck.js+InfraredĀ­) and data pulses are usually ~1ms so if you transfer any data chances are it's actually going to be slower than the Bluetooth. You could send a single 1ms pulse but it's not going to be that much faster and you may get false positives.

    You could actually do:

    setWatch(function() {
      NRF.wake();
      setTimeout(function() {
        NRF.sleep();
      }, 100);
    }, BTN, {repeat:true});
    

    This stops Bluetooth advertising and then restarts it when the button is pressed, for 100ms. I just tested and it sends an advertising packet immediately - however there's no guarantee that the packet will get received by the Pi because Bluetooth advertising isn't guaranteed.

  • Thanks Gordon. I'll have a play around tonight on my Mac to broadcast a Bluetooth signal and see how quickly the pi picks it up.

    If it's within 1s, that's great, if it's longer then I might go down the IR route since I only want to register that a button has been pressed, not really sending any extra data.

  • Oh wow, no - I mean normally the Puck will broadcast within ~0.3 sec and it'll be picked up almost instantly. If you set the interval to 7.5 it'll broadcast within 0.0075 sec - so it's going to be well within 1s without IR!

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

Click Puck registered on Raspberry Pi

Posted by Avatar for Gurmukh @Gurmukh

Actions