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.

asked Oct 15, 2020 at 15:06
2
  • 1
    you can find projects on the internet .... this may be useful ... pjon.org/SoftwareBitBang.php Commented Oct 15, 2020 at 15:31
  • 1
    Thx @jsotola. Those resources make for an interesting read Commented Oct 15, 2020 at 17:43

3 Answers 3

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.).

answered Oct 16, 2020 at 2:00
3
  • Interesting solution @hcheung. At least I'm going to experiment with it just to explore how it it works Commented Oct 16, 2020 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. Commented Oct 16, 2020 at 7:20
  • @EdgarBonet, oh, yes, you are right. Thanks for pointing out. I have made the correction. Commented Oct 16, 2020 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.

answered Oct 15, 2020 at 18:22
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. Commented Oct 16, 2020 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) Commented Oct 16, 2020 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.

answered Oct 15, 2020 at 15:34
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? Commented Oct 15, 2020 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. Commented Oct 15, 2020 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. Commented Oct 16, 2020 at 13:54
  • Hmm interesting, it seems that I have underestimated the power of I2C Thanks for that recommendation @ocrdu Commented Oct 17, 2020 at 22:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.