-4

I want to connect 20 serial devices to the same Arduino Mega.How to do this?I know that multiplexing is the way but how to do that

  • How much data needs to move around for each device? do the devices ever need to start their own transmissions or can the arduino get everything done by polling them? how often are they transmitting? – BrettAM Feb 6 '15 at 16:55
  • 1
    What kind of serial communication? SPI, I2C, UART? What devices? Specifics would be helpful here. – Gerben Feb 6 '15 at 17:15
  • all of them are working on RS232 – Abhishek Kulshrestha Feb 6 '15 at 17:20
  • everything is same as GSM , every devices send data at speed of nearly 1 bit per second – Abhishek Kulshrestha Feb 6 '15 at 17:24
  • 1
    Please edit your question and clearly identify the specific protocols you are asking about. I'm not aware of any GSM data rates as slow as 1 bps; most are thousands of bps to hundreds of thousands. – James Waldby - jwpat7 Feb 7 '15 at 2:29
2

You can use the SoftwareSerial library and declare instances to communicate with your serial devices. I am not sure if you can declare 20 such different instances but if at all you do, use the function: listen() to switch between those serial devices. This, probably, is as close as it gets to multiplexing as you mentioned.

I've tried with 2 such SoftwareSerial instances for communicating with GPS module and GSM module and the listen() function worked flawlessly.

Cheers!

1

You say that they are working on RS232 - which is an electrical standard. You may mean that they use standard UART style asynchronous serial communications - perhaps at 0 to 5V electrical levels.

It depends on how fast you need to communicate, and how continuously you need to communicate. If you can choose when to communicate with each device, you may be able to use Soft Serial with multiple pins. Be aware that it cannot both transmit and receive at the same time (one or the other), and it can only communicate with one port at a time. So it might work for you if you can communicate with one device for a while, then ignore it while you check with other devices, one at a time.

Otherwise maybe not. For example, if you need to receive from many devices at times of their choosing so you need an always-on hardware UART for each device. There are 4 hardware UARTs in the MEGA, so 4 would be your limit.

There are things like external UART peripherals, but managing that would likely be very hard for you.

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.