Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

One button two Arduinos
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

One button two Arduinos

by KeanResearch on Thu Feb 20, 2020 2:30 pm

I am trying to use a single button to actuate diiferent functions on two Arduinos. The button I am trying to use is similar to this https://i.stack.imgur.com/9Bk0F.png.

I have gotten both circuits to independently run using this button and a 10Kohm R. ( with the ground and analog input //)

I have tried a lot a circits and am running out of wire. Can anyone please provide me a schematic on how to properly wire this?

KeanResearch
 
Posts: 37
Joined: Sat Jan 11, 2020 12:22 am

Re: One button two Arduinos

by dastels on Thu Feb 20, 2020 4:34 pm

I haven't tried it, but this should work.

When you set the input pins, use the internal pullups. I.e. use mode = INPUT_PULLUP.
Connect the grounds of the Arduinos together (and the ground in the attached diagram).
When testing the value of the button, false means it's pushed, true means it's not pushed.

Dave
Attachments
two-arduinos-one-switch.jpg
two-arduinos-one-switch.jpg (403.75 KiB) Viewed 73 times

dastels
 
Posts: 3754
Joined: Tue Oct 20, 2015 3:22 pm

Re: One button two Arduinos

by KeanResearch on Thu Feb 20, 2020 4:42 pm

So then I do not wire a terminal of my switch to 5V? I only ask because every diagram I see with these switches always shows that being done. Then again none of those diagrams have been for two boards either.

Thanks!

KeanResearch
 
Posts: 37
Joined: Sat Jan 11, 2020 12:22 am

Re: One button two Arduinos

by dastels on Thu Feb 20, 2020 4:59 pm

I've only seen the switch wired between an input pin and ground. All MCUs I've used (all the way back to the '328 on the UNO) have an internal pullup... so why wire it to need another external component?

Dave

dastels
 
Posts: 3754
Joined: Tue Oct 20, 2015 3:22 pm

Re: One button two Arduinos

by KeanResearch on Thu Feb 20, 2020 5:04 pm

Ah, I was under the impression that this button functioned more like a 'HIGH'/'LOW' digital input rather than a literal switch, but I'll take your word for it and test it out!

Thanks

KeanResearch
 
Posts: 37
Joined: Sat Jan 11, 2020 12:22 am

Re: One button two Arduinos

by dastels on Thu Feb 20, 2020 5:55 pm

Well, yes. With the pin mode set to INPUT_PULLUP there's an internal resistor between the pin and Vcc (5v for an UNO) keeping it at a logic HIGH. When the switch closes it connects the pin to ground: a logic LOW. The reason to do it this way, rather than with a pulldown and the switch connecting the pin to VCC, i sthat even the simpler MCUs have internal pullups that enabled. Some of the later, more complex MCUs have internal pulldown as well which gives some additional flexibility.

Dave

dastels
 
Posts: 3754
Joined: Tue Oct 20, 2015 3:22 pm

Re: One button two Arduinos

by KeanResearch on Mon Feb 24, 2020 10:10 am

Hello,

I tried this circuit and was met with only one of my arduinos actuating. I use pinMode( #, INPUT_PULLUP)

Then considered the pushed state as LOW.

Any thoughts?

Thanks

KeanResearch
 
Posts: 37
Joined: Sat Jan 11, 2020 12:22 am

Re: One button two Arduinos

by KeanResearch on Mon Feb 24, 2020 10:26 am

Interestingly, when I make the condition for actuation when buttonstate == HIGH the device I intend to actuate runs constantly, nonstop.

KeanResearch
 
Posts: 37
Joined: Sat Jan 11, 2020 12:22 am

Re: One button two Arduinos

by dastels on Mon Feb 24, 2020 11:09 am

Hmm. What model of arduino are you using.

I just did the experiment with 2 UNOs. This code:

Code: Select all | TOGGLE FULL SIZE
void setup() {
  pinMode(8, INPUT_PULLUP);
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
}

void loop() {
  digitalWrite(13, !digitalRead(8));
}


With a push button wired as in the diagram I posted.

It works fine.

I would check and confirm the wiring: one side of the switch to ground *on both Arduinos* and the other side to the input pin on both Arduinos.

Dave

dastels
 
Posts: 3754
Joined: Tue Oct 20, 2015 3:22 pm

Re: One button two Arduinos

by KeanResearch on Mon Feb 24, 2020 11:13 am

I am using an Uno and a Micro.

Let me take a a picture, resize it and also upload my code.

KeanResearch
 
Posts: 37
Joined: Sat Jan 11, 2020 12:22 am

Re: One button two Arduinos

by KeanResearch on Mon Feb 24, 2020 11:28 am

Here we go
Attachments
Microlab02.ino
(6.81 KiB) Downloaded 2 times
ButtonwireEX2.png
ButtonwireEX2.png (675.41 KiB) Viewed 47 times

KeanResearch
 
Posts: 37
Joined: Sat Jan 11, 2020 12:22 am

Re: One button two Arduinos

by KeanResearch on Mon Feb 24, 2020 12:38 pm

I have tried changing to several different pins but no help. For some reason my 'malfunctioning' Arduino is always reading the INPUT_PULLUP pin as LOW and actually pressing the button does not change this.

Thanks again for help

KeanResearch
 
Posts: 37
Joined: Sat Jan 11, 2020 12:22 am

Re: One button two Arduinos

by dastels on Mon Feb 24, 2020 4:06 pm

Other than this, the "nonfunctioning" board works ok?

dastels
 
Posts: 3754
Joined: Tue Oct 20, 2015 3:22 pm

Re: One button two Arduinos

by KeanResearch on Mon Feb 24, 2020 4:11 pm

Yes sir,

I think it is possibly a power issue? I am running both from my laptop and there are myriad sensors/ motors being actuated simultaneously. It got to the point where my other circuit that was operating totally fine began to experience a constantly LOW INPUT_PULLUP.

I had to keep playing around with it and got lucky one time.

if you have any light (or darkness for that matter) to gleam onto this description, i'd be interested to hear it.

Regardless, thank you for your time.

KeanResearch
 
Posts: 37
Joined: Sat Jan 11, 2020 12:22 am

Re: One button two Arduinos

by dastels on Mon Feb 24, 2020 4:33 pm

It could be power. Can you measure the voltage and see if it drops? That can cause various problems.

dastels
 
Posts: 3754
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.