EspruinoWifi - digitalWrite triggers setWatch event

Posted on
  • Hi Gordon

    • Espruino Wifi is powered by VUSB and GND Pin, 5v (Not USB)
    • Wifi is connected
    • Relay is connected to the same powersource, 5v, trigger on A5 (Nothing connected to the relay on the load side)
    • A6 is monitored by setWatch, nothing connected to A6


    pinMode(A6, "input_pulldown");
    setWatch(function(e) { do something }


    When i switch the relay width "digitalWrite(A5,1)" on, relay will be triggered as expected.

    Sometimes the A6 setWatch is triggered in the same moment as the relay is triggered. Not allways, it is reproduceable out of 25 on/off switches of the relay.

    I was not able to reproduce it when i have the setWatch on A1.
    I was also not able to reproduce it then i powered the EspruinoWifi by USB.

    Is this becuase A5 and A6 are neighbors ?


  • How are you driving the relay? Does it have its own transistor?

    If you're driving it direct then I could imagine that the voltage spike from the relay coil could definitely affect surrounding pins (I imagine it would be out of spec for the chip).

    The other problem could be that while the pins are 5v tolerant as inputs, they only produce a 3.3v output voltage - so if you're powering the relay off 5v, and you output digitalWrite(A5,1), the pin's being connected to 3.3v - which is actually raising the voltage of the 3.3v line via the relay!

    To fix that you could try setting the output type if A5 to opendrain? It depends if your relay turns on when you output 0 (most do) or 1.

  • I'd be pretty sure its what I'd said then - I've had issues with that in the past.

    Either setting opendrain or writing with:

    if (on) digitalWrite(A5,0);
    else digitalRead(A5)

    will probably fix it

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

EspruinoWifi - digitalWrite triggers setWatch event

Posted by Avatar for Sacha @Sacha