LED1/2 and BTN on RuuviTag inverted

Posted on
  • Thanks for porting Espruino to the RuuviTag! I was looking forward to doing it myself but this works for me to :-).

    However, it looks like the LEDs and BTN are low-active:

    • LED1.write(false); // => LED is on
    • LED1.write(true); // => LED is off
    • digitalRead(BTN); =0 //if B is pressed

    Not a big issue, can it be fixed?

  • No problem - actually Ruuvi were really good, and have paid me to port Espruino over and to keep producing binaries for them (1v92 will be in the Espruino binary zip file)

    Unfortunately it's a tricky one - the LEDs and Buttons on Ruuvitag really are upside-down. I'm afraid there's no obvious fix, since in Espruino LED1 refers to the actual pin on the chip - so if you write 1 to it, it outputs 1. Changing that would require some pretty far-reaching modifications.

    I'd have to add code to optionally invert specific pins, which would probably end up being really confusing if you tried to access the pin directly, and would definitely slow things down. I think for now that's just something you'll have to live with.

  • Thank you for your explanation.

  • Good thing that things like the Puck object and Puck.light() aren't yet implemented on RuuviTag (right?), since they make assumptions about how on and off are mapped to 1 and 0. One way to mitigate these would be to abstract them:
    var buttonState = buttonPressed();

    … where ledOn, ledOff, and buttonPressed() are mapped to 1 or 0 in platform specific ways.

    But those don't solve the problem of running existing Espruino JS apps on RuuviTag. Maybe the IDE could spot things like LED1 and BTN, and in the case of RuuviTag, tag the line with an informational icon (not quite a warning).

    …… answer = 42;
    💡 btnOn = digitalRead(BTN);
    …… console.log(btnOn);

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

LED1/2 and BTN on RuuviTag inverted

Posted by Avatar for AntiCat @AntiCat