Controlling grounding buttons

Hello, sorry for the noob question, I have a device that is controlled by 6 inputs, when an input is momentarily shorted to ground, the device acts. right now i’m using regular normally open momentary pushbuttons. I would like to use the IMP to make these buttons online.

Heres what I have so far, but i’m not sure how to do the hardware side or if my code is on the right path.
`function on_command(command) {
if (command == “1”) {
hardware.pin1.write(1);
imp.sleep(0.1);
hardware.pin1.write(0);
} else if (command == “2”) {
hardware.pin2.write(1);
imp.sleep(0.1);
hardware.pin2.write(0);
} else if (command == “3”) {
hardware.pin5.write(1);
imp.sleep(0.1);
hardware.pin5.write(0);
} else if (command == “4”) {
hardware.pin7.write(1);
imp.sleep(0.1);
hardware.pin7.write(0);
} else if (command == “5”) {
hardware.pin8.write(1);
imp.sleep(0.1);
hardware.pin8.write(0);
} else if (command == “6”) {
hardware.pin8.write(1);
imp.sleep(0.1);
hardware.pin8.write(0);
}
agent.send(“reply”, “button " +command + " pressed”);
}

hardware.pin1.configure(DIGITAL_OUT);
hardware.pin2.configure(DIGITAL_OUT);
hardware.pin5.configure(DIGITAL_OUT);
hardware.pin7.configure(DIGITAL_OUT);
hardware.pin8.configure(DIGITAL_OUT);
hardware.pin9.configure(DIGITAL_OUT);

agent.on(“command”, on_command);`

Looks like you’re passing a textual command vs a numeric one (and command 5 and 6 both write pin 8, which I suspect isn’t what you want). These will drive the pins high then low for 0.1s, which would be the right thing to do if you have a transistor or FET connected to the imp which is being used to short the buttons on the target device to ground.

If you make the command numeric you can tighten things up a bit, and also you could make the system non-blocking, eg:

`
// Make an array of the pins
pins <- [ hardware.pin1, hardware.pin2, hardware.pin5, hardware.pin7, hardware.pin8, hardware.pin9 ];

// Configure them all as outputs, default low
foreach(pin in pins) pin.configure(DIGITAL_OUT, 0);

agent.on(“command”, function(v) {
// Arrays start at zero, not 1
pins[v-1].write(1);
imp.wakeup(0.1, function() { pins[v-1].write(0); });
});
`

…then call from the agent with, eg:

device.send("command", 1);

…to toggle pin 1 for 100ms.

Can you tell us more about the device?

Example, when you measure voltage across an open pushbutton it reads 5vdc … or what does it read?

Or what the device actually is.

thank you for the reply hugo,

I have this from an old project and was hoping that I could use it? I connected all the imp outputs to the corresponding darlington inputs and the corresponding darlington outputs to the device’s inputs, also connected ground. But its not working, do I have to connect common pin 10 of the darlington array to something?

Also I added this line to help build a full responsive webpage.
agent.send("reply", "button " + v + " pressed");

mlseim, the device is a custom device that acts on button presses (MCU’s pin shorted to ground). Measuring the input pin to ground revealed 0v.

Just jumping in here … Taking a really quick look, it ‘seems’ like you should be ok without connecting the COM pin. But what do your inputs look like (i.e. where your pushbuttons were connected) … do they have some sort of pullup? If so, I would think it should work. Have you put a meter on it and taken a look at what the inputs to your device look like when you manually (or via code) toggle the darlington inputs?

Edit: sorry, I do note you indicate you measure 0v. What voltages do you measure then with the original pushbuttons open/closed? Also, I don’t see any harm trying to connect the COM pin to your open state voltage to try that out.

(Also, which device are you using … the 2801, 2, 3, or 4? Looks like some different Vin specs for the different variants. Might be something going on here).

Maybe this will help clear a lot up.

On J4 I momentarily connect either pin 7 / 9 / 11 / 13 / 15 / 17 to ground to activate the device.

Hmmm … kinda. But those devices would appear to primarily function as an input voltage clamp rather than serving a pullup function that you would work against with your pushbutton to ground. So, I’m not sure if there’s some sort of post-header pullup on your MCU making things work for you.

At any rate, you might want to advise exactly which darlington variant you’re using … and again, I don’t see any harm trying to connect COM to your Vcc to see if that might work.

Ya the MCU has its internal pullups enabled.

Oops i missed that, ULN2803A.

COM to Vcc had no luck.

Hmmm. Ok, the 2803 looks like it should be ok, and able to be driven from an imp. It’s interesting though that you say you measure 0v … if anything I would guess that it wouldn’t be able to pull down and you’d measure the high state voltage. Do you just measure 0v at your MCU input pin irregardless of your darlington input (i.e. 0v or 3.3v)?

Maybe something with using the darlington though as a switch that’s just getting past me that someone else might pick up on. Have you tried just using something like a good old garden variety 2N3904 on one of the inputs to see if you can get it to switch?

I connected a LED - leg to the array output, and the + to Vcc, I was able to see the LED turn on and off like the code should behave, however I couldn’t get it to control the device.

From what you’re describing, it sounds as if your transistors perhaps aren’t able to pull hard enough to ground to trigger your MCU input … i.e. Vce_sat is a bit too high … (though this seems unlikely). You might not be able to tell this with an LED … it would be interesting to know what voltage you actually meter. Also, I’m assuming you’re still connected to the MCU input while monitoring the LED?

I’ll do a quick look into some possible alternate transistors, but again, you might just give the 3904 a shot if you have something like that handy. Seems like you just need something to pull those inputs low enough.

No harm in connecting COM to Vcc if Vcc is available.

Without the ULN connected, can you look with a meter at the switch inputs and confirm the voltage on them when the button is pressed and not pressed?

Then, take a multimeter, set it to current mode (and plug the leads in correctly for that) then short out a switch.

a) Does the device operate as if the switch was pressed?
b) What current does the meter indicate is flowing?

Hey guys, thank you so much for all your input. I was able to get it working. Turns out I made a very stupid mistake. I was using an old schematic sheet and had mixed up input vs ground. I corrected my wiring and the imp is able to control the I/O’s directly with now added hardware.

Now I can pair the imp with my emotiv headset and things will be great! :slight_smile:

Thanks Again!