Programatically connecting 2 pins

Posted on
  • What's the easiest way to "connect" 2 pins? Should I use digitalWrite, pin.write with a timeout, analogWrite, or something else? Also should I use 2 pins, or can I use 1 pin with ground? I'm wanting to use Espruino to "press" the reset button on a PC by wiring the green/black wires to it...


  • Hi Austin,

    You've got two choices really.


    You can use a relay module which is basically just an electrically operated switch (and you then use digitalWrite to control that). You can then connect any two wires together, no matter what they are.

    It's a nice, easy, safe option - and it'll work for replacing almost any switch (even mains) :)


    Or, you can use the Espruino to control the wires directly, but you need to check stuff first:

    Turn the PC off (and unplug it), get a volt meter that'll test for shorts and measure between the chassis of the computer and each one of the wires. Hopefully one of them will be a short.

    If one is actually shorted to the chassis (ground)

    Then the voltage on the reset wire is usually high, and is expecting to be shorted to ground when the button is pressed. (It might be a plan to check this with a volt meter though). All you need to do here is connect the ground (shorted) wire to GND on Espruino, and the other wire to a pin on the Espruino Board that isn't marked as 3.3v in the previous link.

    Then just type digitalWrite(MyPin, 0) to effectively 'press' the button, and it's probably best to just let the pin 'float' to 'release' the button, so just do digitalRead(MyPin).

    If one isn't ground

    This is more tricky as probably the pin is usually at Gnd, and is expecting to be pulled to 5v when the button is pressed. Turn the PC on, and use a volt meter (one side on Gnd, the other on each wire) to figure out which wire has a voltage on it (it'll hopefully be 5v or 3.3v - if it's not then maybe post back here to check) and which one doesn't.

    Then, connect Gnd of Espruino to the chassis of your PC, and connect any output pin to the wire that didn't have a voltage. You can forget about the other wire (just make sure it doesn't short to anything).

    Then, to 'press' the button, do digitalWrite(MyPin, 1), and let the pin 'float' to 'release' the button, so just do digitalRead(MyPin).

  • Awesome, thanks for the very thorough response! I haven't received my Espruino (starter kit) yet, but I had bought an STM32F4Discovery a few months ago that I've been playing with in the mean time. I had written a small program to cycle the state (0 to 1 and back) of the A2 pin every 3 seconds on my board last night, and was checking it with a digital multi-meter to see if it was pulled to ground, but didn't realize that reading the pin value would cause it to float as the voltage never changed much. Guess I should've used an analog meter to see it "bounce" from being pulled to ground. I was doing console.log( immediately after setting the pin, so it was probably too fast for the digital meter to pick up that it gained or lost voltage before floating.

    Hopefully I can wire it directly like you have mentioned above that would be preferable (and what I was attempting last night), if not then I'll go the relay route. I'm pretty sure the 2nd wire on reset is chassis ground, I'll check tonight after work...

  • So I've checked my PC, the reset pin is indeed being grounded from 3v3... And was able to test the Espruino board (just got the "official" one last night), that the C8 pin when trigger will "short" the pin to ground. So that'll work out perfectly! Thanks again for the hlep


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

Programatically connecting 2 pins

Posted by Avatar for Austin @Austin