Is it possible to have 2 one-way RS485 connections on a single serial board?

Hi

I’m new to arduino with no prior experience of it. I’m fairly good at picking up new coding languages on the fly and I’m in the ‘research before buy’ stage of a new project which will heavily involve arduinos…
What I’m looking to achieve is kind of like a network of sensor networks (not just a sensor network - see attached, crude image where straight line is hardwired connection, curved line is wireless connection)

The sensors I’m looking at using state an output of RS485 (no info on protocols etc so I’m assuming there’s a single standard RS485 protocol?)

those sensors will output a lot of data constantly so to prevent network congestion I’m thinking of having a ‘sensor arduino’ connected to each sensor using an rs485 module to receive all the data and then any relevant data can be sent via another rs485 module to a ‘control arduino’ which will receive the relevant data from all the connected ‘sensor arduinos’ (and output further data wirelessly via possibly zigbee to the wider network and also bluetooth to a local tablet).

For the ‘control arduino’ I’m looking at a mega as this has 4 serial ports so should be ok to take 3 serial connections. (Please advise me if I’m wrong on this conclusion)

As for the ‘sensor arduinos’ as there will be a lot of them (approx 200 if this were being implemented in the project I’ve just finished) I am looking to keep it as low cost as possible and as receiving RS485 data and relaying a fraction of that on in a formatted manner (adding address etc) in RS485 I wont need any GPIOs (except maybe one for a buzzer and one for a button for setup purposes) I thought an uno (or micro??) would be fine but its the serial in and serial-out-somewhere-else that I’m concerned about.

Initially I considered software serial but that has many comments on here essentially stating ‘avoid as its problematic’, then considered a relay via GPIO to manually switch wires from one RS485 network to another then back again but I can foresee problems in missing data with that solution.
Then I saw a diagram of 2 arduinos communicating via IR and Arduino1 had the transmitter connected to serial out and on Arduino2 the receiver connected to serial in, with no other connections other than 5v and gnd (Cant find the image again sorry). And thought maybe I could connect an RS485 to receive data from the sensor and another separate RS485 to send data as I wouldnt need to send data to the sensor and I wouldnt need to send data to the ‘sensor arduino’ from anything other than the sensor itself…?

At this stage I just after knowing if you guys think it will work and any potential problems I might come across, or alternative solutions (low cost if for the ‘sensor arduinos’)
Sorry for the long post - I’m trying to avoid the x-y problem mentioned in forum tips :wink:

Thanks for your help,

Sam.

You can connect many Arduinos on a single, multidrop RS485 line and there are existing networking protocols that in principle could handle hundreds of nodes on a single line.

I don't know what a realistic limit for the number of physical nodes might be, given existing network adapters. Proper cabling and especially proper termination are critical for reliable performance.

So do some more reading, but don't even think of using software serial for this!

you state "those sensors will output a lot of data constantly"

  1. how much data/second from each sensor? how much in total?
  2. what protocol are you considering, e.g. master/slave such as modbus?
  3. what baud rate are you considering?

to reduce the volume of transmitted bytes you could encode the data in binary

I’m not sure of exact figures but it’s distance sensors so it will be constantly giving updated readings - I’m only interested in it sending me a reading every 5 mins or if there is a change >50mm (it’s a 150m sensor)…

Since its going to be sent to another arduino to handle the data i figured i wouldn’t need an existing protocol i could just send a string of data like “SU001R500E” (SU001 = sensor unit 001, R500=reading 500mm,E=End) and the receiving arduino would receive data and read the string to the E character and process it as required? But it would follow master/slave format as all (relevant and formated) data is passed from these slave arduino modules to the master arduino to deal with.

Baud rate is speed of transmission correct? I figured (probably rather naively) i would experiment to figure out what works ok… I was thinking 9600 as a starting point as I’ve seen it mentioned before as max reliable speed for something and tbh reaction times aren’t especially crucial so long as they are sub second (doesn’t need to be as close to instantaneous as possible)

Really showing my lack of knowledge on all things serial here right? Lol

Thanks for your replies

Sam

sounds like traffic would be low - assuming 10bits to transmit a character (byte plus start/stop bits) 9600baud is approx 960 characters/second
I would suggest the Arduino master polls each slave sensor in turn with a timeout in case a sensor is not operational
have a look at modbus which is probably overkill for your application

That's what i was originally thinking but if i separate the rx and tx of the serial pins to two separate rs485 networks the sensor arduino wouldn't be able to receive data from the master (ie wouldn't be able to receive a poll request)

Do i need to select a protocol? If so modbus sounds good except it states it should be a call and reply format... If i separate the serial so comms to the master are one way i won't be able to use call and reply as it will never "hear" anything from the master...

Sam

could you explain the project in more detail? e.g. how are the sonsors connected to the salve arduinos?
why would one require more than one RS485 connection unless there is too much traffic and you are considering a Mega which has three spare serial ports hence could support three RS485 connections?
Or are you using serial ports for Zigbee and bluetooth ?

Ok so there are essentially two different arduinos with two very different requirements, master and slave.

So the master:
It will receive data from the slaves via rs485 (and issue commands via the same rs485 connection elsewhere).
It will transmit and receive Bluetooth data with an android tablet with custom app as a user interface.
It will communicate to a wider network of other "master arduinos" via zigbee (back to a "grand master arduino" if you like)

Because of this I'm definitely looking at a mega because of the extra serial ports.

The slave :
Data in via rs485 from a sensor
Formated and selected data out via rs485 to the master arduino.
Also need 2 gpios for a button and buzzer for "field setup".

Because there are going to be alot of these slaves I want to keep them as low cost as possible.

Also because data will only need to travel from the sensor to the slave and from the slave to the master, is this possible to split a single serial into "one way in rs485 board 1 (to the sensor) " and "one way out rs485 board 2 (to the master) " or an i barking up the wrong tree here?

Sam

samyoue:
Also because data will only need to travel from the sensor to the slave and from the slave to the master, is this possible to split a single serial into "one way in rs485 board 1 (to the sensor) " and "one way out rs485 board 2 (to the master) " or an i barking up the wrong tree here?

I have no idea if that is possible or how one would code it?
if the sensors communicate via RS485 why do you require the slave microcontrollers?
can you tell us what the sensors are?

The sensors are jrt rxtx 605b.
Jrt is a Chinese company and it states arduino compatibility as part of their specs...

Well I wasn't going to originally but I've seen distance modules on a serial monitor outpouring data constantly and was worried about network congestion if there are 16 on one bus line... What's more i need some way of addressing them so i know which module is sending which data...

Anyone know of a non arduino product that could do what I'm after (don't want to go heavily down this route if there's more suited equipment i haven't thought of)

As for the programming i figured i could just program it like a normal serial port as the arduino doesn't need to know its receiving from one source but sending somewhere else... As far as the slave arduino would be concerned it would receive serial data, then send formated and selected data back as a response (except in reality it would go to the other rs485 module)

From the sounds of things i might have to just get one and try it out...

Sam

I think the simplest thing is to talk to jrt tell them yor requirements and see what they suggest
There is a lack of technical details on on the jrt web page
e.g. what is the detailed spcification of the Arduino Laser Distance Measurement Sensor Module
certainly worth getting one to experiment with
if you are using a master/slave protocol you will require both tx and rx to communicate, e.g. for the master to poll the slaves

I think I'll probably go down the route of using a mega as the master and creating my own slave with 2 at328 chips (thus 2 serials) connected on a custom pcb via i2c. One chip receives data and decides what data to send, passes it to the other chip for formatting and sending on via the other serial... Either with ability to plugon the rs485 boards or if its easy enough maybe incorporate the components onto the custom board (in for a penny in for a pound).

That way i can have 2 way polling to /from master, address set by the master arduino and not preset, minimal rs485 traffic, learn button on pcb, buzzer on pcb, minimal assembly and at £3.16 per chip (appreciate there will be other components and cost of custom pcb creation but by panellising the pcb design i can get that cost down too)... Pretty low cost too...

From the sounds of it I think this will probably be the most suitable way to achieve what i need?

Thanks again for all your help and input horrace

Sam

it may be worth looking a microcontrollers with 2 USARTs, e.g. ATmega324A
I find the MICROCHIP ADVANCED PART SELECTOR very useful when looking for combinations of devices

Even better, thank you so much for your help I can't wait to start building now!

Sam

Hmmm ok in Reading up on the atmega 324a for pin out details I came across the TWI. My understanding is that by connecting the two pins sclk and sda to the corresponding pins on another chip I can send data in the form of one data bye and an acknowledgement bit.
1 If I had the master sequentially poll every device on the bus line it could receive data from the slave is that correct?
2 Would this be affected by mixed daisy chain and star wiring configurations? (2a would rs485 be affected by mixed wiring configs?)
3 is comms 2way with twi? Ie. Always initiated by master but I’d the master send data to the slave AND receive data back?

Thanks again,

Sam