2
\$\begingroup\$

I am a programmer but quite new to electronics.
I am trying to connect more than 16 sensors into a RaspberryPi for analysis, because I'm mainly focusing on computing science's machine learning research.
I don't think I want to find a very complex electric configuration, so I decided to use Arduino as slave interface for sensors. I successfully connected one Arduino with my Pi and executed code, now the real problem comes.

In my system, I need more than 10 sensors (10-16) to be connected to the single RaspberryPi.
Since most of them are accelerometers, I think each one produces 3 analog signals as X,Y,Z axis, so it will consume more than 30 inputs!

I realised that multiplexers can help me while searching the web. I have following concern points, since my the requirements for the sensor data are:

  1. They should be practically 'synchronised', which means data from all sensors should arrive in about the 'same time' (I know it's not possible for perfect synchronisation, but extremely low delay)
  2. No error being generated by the complex wiring solution

Is there any solution can solve this issue? I really appreciate your help!

\$\endgroup\$
4
  • \$\begingroup\$ Welcome to electronics.stackexchange! I made some edits to your post mostly regarding punctuation. Not being a native English speaker is no problem, just do your best! \$\endgroup\$ – WalyKu Feb 10 '15 at 14:03
  • 1
    \$\begingroup\$ You could look into digital sensors. I2C or SPI. Even if you use an Arduino as the middle man, it would still be easier IMHO. \$\endgroup\$ – Passerby Feb 10 '15 at 15:38
  • \$\begingroup\$ What Passerby said - and if they're digital you shouldn't need an arduino in the way, it'll only be a bottleneck, the Pi can do SPI/I2C natively. \$\endgroup\$ – John U Feb 10 '15 at 16:27
  • \$\begingroup\$ Thanks! I'm using analog sensors so I think Abbott's answer should be more suitable :) \$\endgroup\$ – Yank Apr 18 '15 at 20:31
3
\$\begingroup\$

To get the data from all sensors 'simultaneously' you need to read all of them in the sampling time required to get the bandwidth you want. For example to get 100Hz bandwidth you must read each sensor at least 200 times per second, which equates to 6,000 analog readings per second (200 * 3 readings per sensor * 10 sensors). The Arduino can read its analog inputs at a maximum rate of about 10,000 samples per second, which should be fast enough provided other overheads are small. If your bandwidth requirement is lower then it will be easier.

Depending on which Arduino you have it may have 6, 8 or 16 analog inputs. You can expand this to 30 or more using external analog multiplexers, but some digital pins will be required to control the multiplexers. The 74HC4067 is a 16 channel multiplexer with 4 channel select inputs. You could use one of these chips for each accelerometer channel, with the digital inputs of all 3 multiplexers tied together so only 4 Arduino digital pins will be needed. In operation the Arduino would output the 4 bit digital code required to select a sensor, read the 3 analog inputs (using its own internal multiplexer to switch between them) store the results and then switch to the next sensor.

Of course the Arduino also needs to send the results to the Pi. To avoid delays you need a link which can transfer at least 12,000 bytes per second (6,000 * 2 bytes per sample) with minimal overhead. The Arduino has hardware serial ports which can transmit while it is doing other things, so you could send the data for each channel immediately after reading it, and rely on an input buffer in the Pi to handle any delays in processing the results. The minimum bit rate required is about 10 times the byte rate, ie. 120,000 bits/s for reading 10 sensors at 200Hz. The Pi's UART is only good for 115,000 bits/s, which equates to about 190Hz. If this is not fast enough then you will either have to pack the data into fewer bits, or use I2C (set to eg. 400kHz) or SPI.

To synchronize the serial data stream the Pi needs some way to tell which sample relates to which sensor. Arduino Analog reads range from 0 to 1023, leaving the upper 7 bits of each 16 bit word free. So you could start each transmission frame with a unique byte sequence that cannot occur in sample (eg. 0xFF, 0x7F) then the Pi just has to wait for this sequence and it knows the next 2 bytes are the first sample.

If you had I2C or SPI sensors then you could couple them directly to the Pi, but using an Arduino still has certain advantages.

  1. It can be located remotely to make sensor wiring shorter, tidier and less prone to interference. It can also be operated from a separate power supply to avoid ground loops etc., or galvanically isolated from the Pi via opto-couplers or wireless.

  2. The Arduino can read all the sensors in a tight loop without having to worry about other processes interfering with it. You then know that even if the Pi can't receive and process all the samples 'at the same time' at least they were recorded simultaneously. This is particularly important if you are interested in the instantaneous values of readings relative to each other (their 'synchronicity') rather than the absolute time of reception.

\$\endgroup\$
1
  • \$\begingroup\$ Omg it's unlimited helpful by listing all technical details! thanks very much!! \$\endgroup\$ – Yank Feb 10 '15 at 20:24

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.