Multiple arduino serial output via one serial output

Hi All,

I am trying to do a project where i have multiple micro-controllers. Each micro controller (Teensy with arduino) collect data from multiple sensors (analog to digital conversion). I woul like to cummulatively collect the information of individual micro controllers and transmit them via a single serial or wifi port. The idea from what i am looking for is something shown in the picture below. Could you kindly help me.

Your plan looks very sensible and practical: have one device collect all the data and then send it out.

It's common to have Arduinos communicate with one another over the i2c bus (a serial protocol that can address multiple devices on a single two-wire bus) - do a search on this forum for suggestions. Not sure what option your TEENSY has available that could talk to your fourth microprocessor.

Why use the teensys at all? There are ADC modules you can buy that have plenty of channels and can be accessed with I2C.

Image from Reply #NN Original Post so we don't have to download it. See this Image Guide

...R

You have not said if you need to feed the outputs from the 3 Teensies to a single Serial port on Microcontroller. If you do then you will need a few external parts to prevent them interfering with each other. The receiving microcontroller needs to have a resistor (perhaps 5600 ohms) pulling its Rx line to Vcc. And each of the transmitting Teensies needs to have a diode on its Tx line oriented to prevent the HIGH from the Tx getting to the Rx.

If they are sharing a Serial port you will also need a system to prevent more than one sending at any one time. The simplest system would probably be for the Microcontroller to ask for data from each Teensy in turn. You can include an ID number in every message so there is no confusion about who it is for or where it came from.

And have a look at the examples in Serial Input Basics - simple reliable ways to receive data. The system in the 3rd example will be the most reliable.

...R

Power_Broker:
Why use the teensys at all? There are ADC modules you can buy that have plenty of channels and can be accessed with I2C.

The problem is that i dont really know how to code micro controllers besides arduino environment. My over project has atleast 40 sensors. And im seperating the teensy to access 8 sensors each. The thing is the Teensy is controlling the 8 channel amplifier of the Teensy with i2c, so that means that the master controller would slow down the simultaneous capture of the 40 + sensors

fieryfire:
The problem is that i dont really know how to code micro controllers besides arduino environment. My over project has atleast 40 sensors. And im seperating the teensy to access 8 sensors each. The thing is the Teensy is controlling the 8 channel amplifier of the Teensy with i2c, so that means that the master controller would slow down the simultaneous capture of the 40 + sensors

This explanation makes no sense to me.

1.) You don't "code" an ADC module, you interface with it. Therefore, this reason for using a teensy over an external ADC is ridiculous:

fieryfire:
The problem is that i dont really know how to code micro controllers besides arduino environment.

2.) Also, with I2C, you can connect as many external ADCs to your single Arduino as you want since they use I2C (that is, as long as you have a unique address for each ADC). Therefore, this reason for using a teensy over an external ADC is also ridiculous:

fieryfire:
My over project has atleast 40 sensors.

3.) What is this 8 channel amplifier you mention? Is that an audio amplifier?

fieryfire:
The thing is the Teensy is controlling the 8 channel amplifier of the Teensy with i2c

4.) Since I2C is a very, very fast communication protocol (much faster than UART like you're planning to use), this statement is also ridiculous:

fieryfire:
The thing is the Teensy is controlling the 8 channel amplifier of the Teensy with i2c, so that means that the master controller would slow down the simultaneous capture of the 40 + sensors

Is there a good reason for your project not to use external ADCs? I'm not saying you don't have a good reason, it's just that you haven't posted one yet.

An Arduino Mega has 4 Serial channels, if you really want to use serial (RS-232) transmission.

If you use I2C instead, you can connect multiple controllers or ADC to the master controller, using the same I2C bus. Your code then has to address and handle these devices as appropriate for their device types.

Hi,
What sort of physical distances are you dealing with between each of the components?
Is the any electrical interference, such as electric motors, fluorescent lighting etc nearby?

What are you measuring, what is the application?

Thanks.. Tom... :slight_smile:

Power_Broker:
This explanation makes no sense to me.

1.) You don't "code" an ADC module, you interface with it. Therefore, this reason for using a teensy over an external ADC is ridiculous:
2.) Also, with I2C, you can connect as many external ADCs to your single Arduino as you want since they use I2C (that is, as long as you have a unique address for each ADC). Therefore, this reason for using a teensy over an external ADC is also ridiculous:
3.) What is this 8 channel amplifier you mention? Is that an audio amplifier?
4.) Since I2C is a very, very fast communication protocol (much faster than UART like you're planning to use), this statement is also ridiculous:

Is there a good reason for your project not to use external ADCs? I'm not saying you don't have a good reason, it's just that you haven't posted one yet.

  1. I realize my ignorance here. My Apologies. To interface an i2c with an ADC module would mean that i would be adding extra strain on the i2c, by that i mean that i would not be able to get 1000Samples/Sec/Channel.

Let me explain. The amplifier im using is the XR18910, which is an 8:1 bridge wheatstone amplifier. That that can be controlled at 400KHz Max with i2c. It has one output, and the teensy would have to switch the so that i get 1000Samples/Sec/ Channel. I am aware that i am using the one adc of the Teensy at 13 bit. I could perhaps use an external ADC which is also controlled by the i2c bandwidth, but im not sure if i would see more of a benefit from this. Unless i would get more accuracy, higher resolution or faster sampling rate. Could you suggest a fast ADC that fullfills this critieria?

  1. that would be the XR18910 bridge sensor Amplifier for strain amplification. Here is a link - http://www.mouser.com/pdfdocs/XR18910.pdf

  2. From the math, i observe that atleast half of the 400KHz would technically go for communication protocol then i am left with 200KHz. This leaves me to only so much to talk with another 8 channels. Moreover, if i am to use multiple of these XR18910 amplifiers, each having to have atleast 1000Samples/Sec/Channel. I would need about 32 to 40 strain acquisitions in total. So i would be using multiple XR18910, each with its own Teensy. and then a final microcontroller that collects the data sequentially from 4 or 5 of the Teensy and send it via Serial or Wifi to cloud,etc.

TomGeorge:
Hi,
What sort of physical distances are you dealing with between each of the components?
Is the any electrical interference, such as electric motors, fluorescent lighting etc nearby?

What are you measuring, what is the application?

Thanks.. Tom... :slight_smile:

Hi Tom,

I am measure strain from a quarter bridge. The distances are at about 10 meters(Maximum). The final application that the sensors would be place along the side of roads. In cities or highways. I would need a total of 32 to 40 strain acquisitions, each at 1000Samples/Sec.

DrDiettrich:
An Arduino Mega has 4 Serial channels, if you really want to use serial (RS-232) transmission.

If you use I2C instead, you can connect multiple controllers or ADC to the master controller, using the same I2C bus. Your code then has to address and handle these devices as appropriate for their device types.

This seems like a good idea. I would be having 4 serial outs from 4 Teensys. I could connect it to a Mega from which i could serial out. Could you advice me on how i can proceed? For example certain links that i can take a look at ?

You're going to have to take a good look at how you're going to handle all that data. As pointed out before, the serial bus is slower than I2C so if you think I2C can't handle it, you'll have to look at different protocols, such as SPI. It allows for high data rates but needs 3 pins for the data bus and a separate pin for each connected device to select whose turn it is to talk. So five slaves (8-channel ADCs or your Teensy's) would require a total of 8 digital pins on your master.

For ADC, there's the MCP3008 8-channel 10-bit external ADC that uses SPI for data transfer, and which can do up to 200k samples per seconds. The ADS1015 can do 3,300 samples per second at 12 its, but has only 4 ADC channels. It uses i2c for communication.

You're talking about connecting at least 40 sensors, and taking 1000 samples per second of each. That's a total of at least 40,000 samples per second, at 16-bit resolution that's 78 kB (625 kb) of data per second, not counting protocol overhead - the part where you tell the receiver which byte belongs to which sensor. Way too much for a single I2C bus. You'd need four i2c buses for that, or in your situation even five (one for each ADC or Teensy). Could be done on an ESP8266 (which uses software I2C), not sure about the Arduinos, and anyway it doesn't sound like a great idea as there's so much protocol overhead involved.

To get all your data out to permanent storage (which I assume you want), serial is also out. The protocol supports up to 460k bps, normally not used for speeds over 115,200 bps. It's far too slow for this amount of data. You'll need something like WiFi or ethernet for that. Alternatively, you may add a micro-SD card to store your data, then later transfer it to another system, but that'd use the same SPI bus.

Just see your distance part. 10 meters is too much for i2c, don't know about SPI. Is every single sensor 10 meters from it's host Teensy? Or are it clusters of closely spaced sensors? Do you want access to your data real time, or are you planning on logging and collecting results later?

On the Mega you have not only the standard Serial, but also Serial1 to Serial3. Consider that one of these must be available for output from the Mega.

BTW your assumption about I2C timing is wrong. A byte is transferred in 9 clock ticks, and the first byte of a transmission is the slave address. That's roughly equivalent to the same serial baud rate (400000).

The real bottleneck is not the data input, for which multiple channels can be used, instead it's the output of the collected data, over a single line. If each value consists of 2 bytes, that's at least 80,000 bytes per second, for 40 analog sensors at 1k sample rate each, or 1M bit per second (baud).

DrDiettrich:
An Arduino Mega has 4 Serial channels, if you really want to use serial (RS-232) transmission.

If you use I2C instead, you can connect multiple controllers or ADC to the master controller, using the same I2C bus. Your code then has to address and handle these devices as appropriate for their device types.

My challenge regarding the I2C is that. Each Slave Teensy would need to send atleast 128000Bps of information. And the Slave Teensy is already using its I2C to control an amplifier. Now inorder for 4 Teensy to send data at 128000Bps, it would need a bus speed of atleast 512000bps. But the fastest the Teensy can support is upto 400Kpbs. Hence i would really be unable to use the i2c in this case.

wvmarle:
You're going to have to take a good look at how you're going to handle all that data. As pointed out before, the serial bus is slower than I2C so if you think I2C can't handle it, you'll have to look at different protocols, such as SPI. It allows for high data rates but needs 3 pins for the data bus and a separate pin for each connected device to select whose turn it is to talk. So five slaves (8-channel ADCs or your Teensy's) would require a total of 8 digital pins on your master.

For ADC, there's the MCP3008 8-channel 10-bit external ADC that uses SPI for data transfer, and which can do up to 200k samples per seconds. The ADS1015 can do 3,300 samples per second at 12 its, but has only 4 ADC channels. It uses i2c for communication.

You're talking about connecting at least 40 sensors, and taking 1000 samples per second of each. That's a total of at least 40,000 samples per second, at 16-bit resolution that's 78 kB (625 kb) of data per second, not counting protocol overhead - the part where you tell the receiver which byte belongs to which sensor. Way too much for a single I2C bus. You'd need four i2c buses for that, or in your situation even five (one for each ADC or Teensy). Could be done on an ESP8266 (which uses software I2C), not sure about the Arduinos, and anyway it doesn't sound like a great idea as there's so much protocol overhead involved.

To get all your data out to permanent storage (which I assume you want), serial is also out. The protocol supports up to 460k bps, normally not used for speeds over 115,200 bps. It's far too slow for this amount of data. You'll need something like WiFi or ethernet for that. Alternatively, you may add a micro-SD card to store your data, then later transfer it to another system, but that'd use the same SPI bus.

Can you please suggest me a way on how i can tackle this problem?
Currently from each Teensy, i am able to transfer via its USB (480Mbps) at even upto 2000000bps. Each teensy is carrying (8*1000(samples)*13-bit(resolution)=104,000)+(7 ',' seperators + byte from temperature).
Now my challenge is to capture concatenate this information using a micro-controller or store it into a device and send the data via wifi to the cloud.

I am completely lost as i see that you mentioned SPI and I2C cant be done as if i need data from 4 Teensies to go to one microcontroller. I will need atleast 104,000*4 which is say about 512,000bps maximum. Since each Teensy can't communicate I2C higher than 400kpbs. I am at a lose here since.

My next option is to somehow take those 128,000bps information from each of the teensies, collect it into a chunk and transmit it. Please suggest me a way

I never said SPI can't be used. The distance may be an issue; I don't know how long distance it is designed to handle. It should be fast enough at least.

Otherwise ethernet may be an option. No issues there, speed and distance wise.

Teensy communicates to USB at USB 1.1 speed. Maybe an RPi or laptop can keep up with a few of those.

Look into RS485 for a high speed serial bus that can communicate over 100's of meters.
RS485 modules are available, they connect to Arduino serial.

The distance between the Slave teensy and the master controller wouldnt be more than 50-100cm apart.

But i still wonder will i be able to get synchronous results. Since i am technically trying to capture data from 32 sensors. 8 sensors per teensy. So i would need the timing to be closer to the 1000 samples per second. In either way. Could you kindly give me an idea?