3

I'm working on a project where I need to control the light of 5 buttons as well as listen when each button is switched on/off by the user. I would furthermore like to provide feedback on an OLED display. It looks like I'm running out of pins. This https://arduino.stackexchange.com/a/22689/69029 provides several options for that. I would specifically like to explore the option to have several arduinos connected to each other in a master/slave configuration. Where can I learn more about my option to build stuff using several Arduinos connected to each other? I can also forsee scenarios where I could use 3.3V devices as well as 5V devices.

2
3

Among all the options mentioned, using a master/slave should be the last resort, especially when you are new to embedded programming or Arduino, it is not only more complicate but also more expensive to implement.

One potential solution that could free up the precious digital i/o pins that were used by the 5 buttons is using analog input to detect the status of the buttons.

schematic

simulate this circuit – Schematic created using CircuitLab

When sw1 is pressed, the voltage at the A0 will be around 0.83v, and when sw5 is pressed, the voltage at the A0 will be 2.5v. You can write a simple switch...case to determine which switch has been pressed.

The only problem of this circuit is that it can't handle more than one button been pressed simultaneously, but that could be solved by double the value of each resistor like 10k, 20k, 30k...

This will free-up 5 digital pins that can be used for control (such as servo, relay, etc.).

3
  • Interesting solution @hcheung. At least I'm going to experiment with it just to explore how it it works – Johan Sundström Oct 16 '20 at 6:33
  • Re “When sw5 is pressed, the voltage at the A0 will be around 0.83v, and when sw1 is pressed, the voltage at the A0 will be 2.5v.”: I think you got the switch labels backwards. – Edgar Bonet Oct 16 '20 at 7:20
  • @EdgarBonet, oh, yes, you are right. Thanks for pointing out. I have made the correction. – hcheung Oct 16 '20 at 13:49
2

Instead of trying to use multiple Arduino boards, which would be hard, I'd suggest using a bigger Arduino. The mega 2560, for example, has tons of GPIO lines.

2
  • I've since learned about the 74HC595. That seems like a handy solution to free up some pins. I gues in combination with the mega 2560 you would have plenty of pins. – Johan Sundström Oct 16 '20 at 6:37
  • 1
    Sure, you can use a shift register to set multiple output pins using a single serial line. A shift register wouldn't let you increase the number of input pins however. There are also CMOS multiplexer chips you could use to share a single pin to take multiple digital inputs (or outputs, since CMOS MUX chips allow bidirectional data flow) – Duncan C Oct 16 '20 at 12:30
0

I haven't seen this being done much. But that's probably because it isn't the best option in almost all cases.

Having multiple pieces of code, for different boards, that you have to work together. Constantly having to upload to different boards. This sound like a nightmare.

The only use-case I could see is to have each Arduino have a single function that shouldn't change (much) over time, and having it act like just any another sensor IC, or led driver IC.

The best example of this would be some of the SparkFun Qwiic Twist, Quad Relay, and Button board. For these they use an Arduino compatible ATTiny84 IC with custom firmware to expose it's functionality over I2C.

But most of their Qwiic boards use custom ICs, since they are either cheaper, or less work to get working.

4
  • I'm currently learning so my experiments are fairly modest right now. However, I'd like to build my own RC boat with a lot of sensors supporting it and also many servor to make navigable. Since that would be a huge project considering my current experience with the Arduino platform I can already sense that a single microcontroller would not be enough. Perhaps I'm trying to approach this idea from the wrong angle? – Johan Sundström Oct 15 '20 at 17:55
  • I don't feel that's the best solution. I'd probably look into an IC that does the Servo pulse generation for you. That would give you a few extra free pins, and reduce the CPU load on the Arduino. – Gerben Oct 15 '20 at 19:30
  • 1
    @Johan-Sundström: About that boat: if you use sensors that have I2C you can use many with just two wires. You can also replace a display and physical buttons with a web interface on your telephone if you use an Arduino with a WiFi module on it. I've done that with a Nano 33 IoT with the WiFi in AP mode and it works. – ocrdu Oct 16 '20 at 13:54
  • Hmm interesting, it seems that I have underestimated the power of I2C Thanks for that recommendation @ocrdu – Johan Sundström Oct 17 '20 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.