I need to add 20 UART sensors to a Raspberry Pi - any thoughts?

Discussion in 'Embedded Systems and Microcontrollers' started by joshctaylor, May 17, 2017.

  1. joshctaylor

    Thread Starter New Member

    May 17, 2017
    6
    1
    Dear All,
    I need to run a comparison study of 20 sensors which currently only come with a UART interface. They send a 3 byte message at 10 Hz with 9600 baud, 3.3v logic level. Does anyone have experience of setting up a lot of serial devices? Any suggestions / help is very welcome.

    Options I am aware of to start discussion:
    - USB converters - I'm not too keen on this as I will need a 20 port hub
    - RS485 or similar - The sensor does not have an address, does anyone know of a device which will add an address to multiple serial streams?
    - I2C convertors, I have seen I2C chips with 4 UART interfaces
    - bitbanged serial
    - <the magic perfect solution I don't know about>
     
  2. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,968
    616
    Get a bunch of Chinese 3.3V arduino boards. Use Software Serial (standard feature in current arduino software) to use two digital pins for UART. This way you can hook up 3 or more sensors to each arduino board.

    Usually arduino boards have dedicated UART pins, use them to connect to RPi. Or use Software Serial to use any two digital pins for UART to talk to RPi (just like you did with the sensors).

    Arduino Due has 54 digital pins. Two digital pins per sensor for UART. Save a few pins for just in case, figure you have 40-48 digital pins, that is 20-24 sensors. Do more research, you might be able to fit all 25 sensors on one Due.
     
    joshctaylor likes this.
  3. joshctaylor

    Thread Starter New Member

    May 17, 2017
    6
    1
    thanks, I've done a little more research now and rather than attaching many more UARTs I'm looking at multiplexing a single UART using CD74HC4067.
     
    JohnInTX likes this.
  4. crutschow

    Expert

    Mar 14, 2008
    16,513
    4,444
    That should work fine as long as you can time-share the information from the sensors.
    How fast will you read all 20 sensors?
     
    joshctaylor and JohnInTX like this.
  5. joshctaylor

    Thread Starter New Member

    May 17, 2017
    6
    1
    I need to poll the sensors every 0.1 - 1 sec, I'm hoping I can achieve that.
     
  6. LesJones

    Active Member

    Jan 8, 2017
    644
    132
    Do you trigger each sensor to take a reading or are they free running sending out reading every 0.1 second ?

    Les.
     
  7. JohnInTX

    Moderator

    Jun 26, 2012
    2,941
    1,405
    If you can poll the sensors, I kind of like the multiplexer approach as well.

    If the sensors don't wait for polling, I'd consider using a little PIC at each sensor and bussing them with I2C or CAN. I2C could be multi master or the host could poll each slave. Since the PIC has memory, it could coordinate the timing of the sensor reads and buffer multiple readings as necessary, sending several points to the host when polled. CAN would be a little more expensive but the protocol is built in. The sensor PIC would again read the sensor and use CAN to send the readings. The host just reads the CAN messages and determines which sensor by the COB_ID. I have implemented large 'smart point' systems using both I2C and CAN with great success.

    I don't like the multiple Arduino with multiple firmware UARTs as a data switch.

    Just my .02

    Thinking more, PICs with 2-wire RS-485 would work and be pretty cheap and easy. Local PICs would manage and buffer the sensors. The host would poll each by sending the address of the desired slave and that one would transmit its data.
     
    Last edited: May 18, 2017
    joshctaylor likes this.
  8. dendad

    Active Member

    Feb 20, 2016
    613
    145
    I too would vote for an RS485 or CAN network.
    What are the actual sensors? If they are just temperature, you could use "1 wire" temperature sensors all wired to the same cable.
    The cheap Arduino way is good, but with a network so you just use 4 wires, +5V, Net+, Net- and 0V.
    https://arduino-info.wikispaces.com/SoftwareSerialRS485Example
    You will probably have to Google for more detailed info.
    RS485 is used extensively in industrial applications, often running Modbus protocols.
    All you would need to do is an a MAX485 chip to each Arduino. An Ebay board will be the easiest way to go with that too.

    I've not read this all but it may help a bit...
    https://github.com/4-20ma/ModbusMaster
    http://4-20ma.io/ModbusMaster/





    And many others.
     
    Last edited: May 18, 2017
  9. joshctaylor

    Thread Starter New Member

    May 17, 2017
    6
    1
    Thanks for all your suggestions. The sensor is a PMS5003 particle sensor. Its a cheap Chinese sensor but it seems that they might have stumbled on something that works with a little more modelling - hence the comparison. It does support polling so I'm thinking multiplexing is the way to go as it has the least parts and cost.
     
  10. dendad

    Active Member

    Feb 20, 2016
    613
    145
  11. Sensacell

    Senior Member

    Jun 19, 2012
    1,511
    403
Loading...