Receive data from 40 serial lines with an arduino

Hello,
I am currently working on a project where I must be able to read data from 40 serial lines (1200 baud) with a microcontroller (RX only, no TX) .
I do not need to be able to read them all at the same time, reading one after another is OK, because the senders are continously sending the same data.

Do you have any hint about how I can map 40 lines to the arduino serial port? Would a good multiplexer do the job?
Is there any better option than using an arduino uno?

Thanks

How many bytes does the data contain, can you distinguish where the start of the data occurs from the stream? Do you have a check sum to show that the data has been received correctly? If the answer is yes then a multiplex will work fine.

Otherwise get an external serial port chip. You can get two in a chip with its own fifo buffer, so you get a little slack with the reading.

Yes, a message always begins with STX and always ends with ETX and there is a checksum just before the ETX char. The length of the message is variable, but never more than 150 bytes.
I already implemented the code to read and parse the messages (and validate the checksum) from a single serial line and it works great. Now I have to find out how I can use this for several lines.

Do you know a good multiplexer which would fit my needs with 40 inputs?

You won’t find a multiplexer with 40 inputs, like most electronics they come in numbers of powers of two. I know there is a 32 input one and a 16 input one as well a number of 8 input ones. Your best bet is to make a compound multiplexer with an an 8 to 1 being fed with the outputs of five others. That will take you up to 40.

No multiplexer with 64 inputs? :slight_smile:
So this would be multiplexing multiplexers?

Would some 74hc4051 work? Or any better alternative?

ludovic815:
Would some 74hc4051 work? Or any better alternative?

74HC4067 has 16 inputs and by using the enable pins you can easily have multiple in parallel and only open one at a time.
A ProMicro "Arduino" may be a better device to use, it has separate USB and serial ports.

You would need 5 x 74hc4051, but only 3 x 74hc4067. All 3 chips can share the same 4 Arduino pins as address selector pins but would each need a separate Arduino pin for the output enable pins.

Thanks a lot! I love this solution!
If I understand correctly, the attached wiring should work:
-The output of each multiplexer to the same arduino pin (Pin 0 - RX)
-S0, S1, S2, S3 to the same arduino pins (D4, D5, D6, D7)
-Each ENABLE pin to a separate arduino pin (D8, D9, D10). I should then switch the pin to low to read from a given multiplexer and for the two other multiplexer the pin should be high.

Will the multiplexer which is not enabled have any influence on the readings?


Looks ok, but you will have to disconnect the multiplexers from pin 0 each time you want to upload a new version of the sketch, which will become a pain during the debugging process.

The alternative would be to use an Arduino with a second serial Rx pin, such as Pro Micro as has already been suggested, or use another digital pin on Uno and use software serial. As the baud rate is only 1200, software serial should be fine.

Or save a pin by connecting the enable pins to 5V and connect the outputs of the 3 multiplexers to 3 Arduino pins, each set up with software serial. You won't be able to read all 3 serial inputs at the same time, but that's no different than using a single serial input.

Thank you for your suggestions about the issue with pin 0. I know this issue about programming. I will use the software serial library with another pin.

PaulRB:
multiplexing_74hc4067.png
Expand

Looks ok, but you will have to disconnect the multiplexers from pin 0 each time you want to upload a new version of the sketch, which will become a pain during the debugging process.

No you don't! :roll_eyes:

Just put 22k pulldowns pullups on each enable pin. After reset, all are reliably disabled. :grinning:

Good idea! Should I put pull down or pull up resistors? I think it should be pull up!

ludovic815:
Good idea! Should I put pull down or pull up resistors? I think it should be pull up!

OK, that diagram was not very specific and did not correctly specify the ~EN pin. Checked the datahsheet, It is in fact active LOW so you need a pull-up.

The internal pull-ups on the Arduino are not enabled until code programs them such so they are of no use to you, Just write the pins HIGH before setting them to OUTPUT. :grinning:

Good remark! I have to make sure that there is never more than one pin set to low, otherwise bad things could happen. This means also that the pull up are mandatory, otherwise I could have a short circuit during the boot process. Sorry for the datasheet, I should have added it.