I/O between arduinos with opto coupling. Sample schematic

How is that any more efficient that putting an (4.7 k/1 uF) RC LPF at the other end and reading it with analogRead ?

Actually, if you want to , there is no reason you can't use RS485 to send your data. I don't know why you chose to send PWM but you can still do that using RS485. Usually, data is sent using a protocol that involves a header, a packet and a checksum but that's beyond my level of S/W expertise. If I just needed to send an 8-bit value I would probably have to do it the same way you are, (because I don't know how to do it any other way , LOL).

raschemmel:
How is that any more efficient that putting an (4.7 k/1 uF) RC LPF at the other end and reading it with analogRead ?

It probably isn't. I actually had to look up what you meant by RC LPF which probably says allot. Being a software engineer i went for the solution that was electronically easier to understand but harder on the programming side of things. Somehow i got the impression that reading pwm has to be done manually in code on a digital pin. So maybe i should use an analogue pin read instead then?

http://www.benripley.com/diy/arduino/three-ways-to-read-a-pwm-signal-with-arduino/

raschemmel:
Actually, if you want to , there is no reason you can't use RS485 to send your data. I don't know why you chose to send PWM but you can still do that using RS485. Usually, data is sent using a protocol that involves a header, a packet and a checksum but that's beyond my level of S/W expertise. If I just needed to send an 8-bit value I would probably have to do it the same way you are, (because I don't know how to do it any other way , LOL).

If it wasn't for the distance problem i would stick with pwm no worries, as i need to connect to four other arduinos. This way would mean everything fits on the one pcb with just a few optos and resistors.

If i only had to connect to one other arduino not four then RS485 could be better. Though i'm only wanting to send a single integer say 4-5 times an hour, so even then a line driver is probably a bit overkill.

If possible i'd prefer to use pwm but i'm not sure about the distance problem. The arduinos will be in a warehouse upto 100 meters from each other. I can write some error/interference tolerance into the code but for all i know pwm at those distances is practically impossible?

So i'm stuck between both solutions and currently not sure which way to go with! lol

If i only had to connect to one other arduino not four then RS485 could be better.

But RS485 is designed to be chained to multiple devices.

But RS485 is designed to be chained to multiple devices.

While this is true, it is also true that an arduino can read analog or pwm on one pin and output it on another so really the distance is the deciding factor for which to use.

Grumpy_Mike:
But RS485 is designed to be chained to multiple devices.

The OP specifies multiple devices.

Clearly, the proper way to perform this communication is with a serial protocol. Any other will end in tears.

Clearly, the proper way to perform this communication is with a serial protocol. Any other will end in tears.

RS485 output at one end is exactly the same as the input at the other end. Is there any valid reason that input can't be serial ? (as far as I can tell it could be anything, including PWM).

raschemmel:
While this is true, it is also true that an arduino can read analog or pwm on one pin and output it on another so really the distance is the deciding factor for which to use.

Since RS485 is reliable at long distances i decided ill probably have to go with that.
I wasn't able to find any definitive info on whether pwm can run stable upto 100 meters. This distances may even need to be more than that.

Do you know what the range is for RS485 ?

raschemmel:
Do you know what the range is for RS485 ?

Apparently upto 1200m if you can deal with a slow 100 kbit/s. Still way overkill for what i need

Back in '87 we ran two computers over a full duplex 422 driver on a campus phone system. I think the distance was close to a mile between buildings over the wire. Can't remember the BAUD rate. May have been 9600, but not sure. Never had any problems.

MikeLittle:
Back in '87 we ran two computers over a full duplex 422 driver on a campus phone system. I think the distance was close to a mile between buildings over the wire. Can't remember the BAUD rate. May have been 9600, but not sure. Never had any problems.

Looks like distance is definitely no issue then which is great. I have to say the issue now is how much more complex it's going to be to get this to work using these line drivers. Seems like RS485 uses protocols that want a master slave setup connected in a bus. Where as i'm needing more of an adhoc type network where each node is equivalent. This may be a subject for another section of the forum but will see how i go! :slight_smile:

Seems like RS485 uses protocols that want a master slave setup connected in a bus. Where as i'm needing more adhoc type network where each node is equivalent. This may be a subject for another section of the forum but will see how i go!

The chips don't have any protocol. They send what is sent and receive what was sent to them. Having multiple chips on the same bus demands the existence of a protocol.
Look at the datasheet

You need a 120 ohm termination resistor at each end of the bus to prevent reflected wave. You'll find that with DeviceNet, CANBUS , MODBUS etc...
You haven't provided any design criteria for the bus so no comment is possible. If you had only one sender and one receiver, I don't know how you would call one a Master and the other a Slave unless the software does not allow the Slave to send. Protocols are created to prevent chaos. There is no rule that says you have to use any specific protocol and only you can say what you need a protocol to do in your application. Whatever you do with your software that prevents chaos is , by definition , a protocol.
Get a couple of these chips and connect leds to their receivers and I think you will see that you can send whatever you want , however you want. If you have multiple devices on the same bus, you must write your software so that each device has an ID and only responds to messages sent to their ID, but somehow I think you knew that.

raschemmel:
You haven't provided any design criteria for the bus so no comment is possible. If you had only one sender and one receiver, I don't know how you would call one a Master and the other a Slave unless the software does not allow the Slave to send. Protocols are created to prevent chaos. There is no rule that says you have to use any specific protocol and only you can say what you need a protocol to do in your application. Whatever you do with your software that prevents chaos is , by definition , a protocol.

The basic criteria would be:

The protocol allows for a simple end to end link between two RS485s where both can initiate contact with the other end.

This may have to be a bus containing a master and one slave, as long as the slave can do everything the master can do.

Using software routing and addressing i could then create the adhoc network i need.

I'm also looking into if its possible to achieve this kind of network using a bus based protocol such as modbus. Since the number of connected devices would be dynamic (between 0-4) , is it possible for modbus to have a bus with no slaves as long as i have the termination resistors?

As long as the terminatin resistors are at the extreme ends of the main trunk then it's up to the software, which is not my area of expertise.
Whst is the definition of Master or Slave ?

raschemmel:
As long as the terminatin resistors are at the extreme ends of the main trunk then it's up to the software, which is not my area of expertise.

Ah ok, in this case then the idea i had wouldn't work as it meant having both ends of the bus on a small loop on the pcb and connecting slaves to that which would travel long distances.

raschemmel:
Whst is the definition of Master or Slave ?

Another name might be primary and secondary. Means one device (the primary/master) controls one or more other devices (secondaries/slaves). This is centralized with one device instigating communication.

Since what i'm needing is any device to instigate communication then what i need is a peer to peer or adhoc type protocol which is decentralized. All devices are equal and effectively can play the role of both a master and a slave device.

Actually i'm glad you mentioned CAN bus as i looked it up and i see it was made with the idea of there being no single master or main controller. This may be exactly what i'd need.

Recall that the purpose of termination resistors is to prevent reflected wave. That's why they have to be at the extreme ends of the main trunk.

Another name might be primary and secondary. Means one device (the primary/master) controls one or more other devices (secondaries/slaves). This is centralized with one device instigating communication.

Since what i'm needing is any device to instigate communication then what i need is a peer to peer or adhoc type protocol which is decentralized. All devices are equal and effectively can play the role of both a master and a slave device.

I think what I was trying to convey is that the RS485 devices are identical for Master and Slave so there is nothing in the Hardware that makes one a Master or a Slave. Thus only the software knows "who's who ?" and if you look at some protocols there are packets with headers and then device ID numbers and devices only respond to commands sent to their device ID. On DeviceNet devices, there are rotary switches to set the device number (1 -63 I believe). What makes the Master the Master is that it has the device ID "0".

As I mentioned, software is not my area of expertise but I can tell you that any "protocol" you "create", (assuming you don't want to learn an existing protocol) that can identify a device ID and respond to it will work, provided the uController acting as the Master is running software that uses a CASE statement or some other S/W mechanism to determine that an incoming message is from a particular device that it is trying to control. You can test that yourself with only three arduinos. (one Master, one slave and one 3rd Party )
It's very simple. If the Slave responds and the 3rd Party doesn't then you're in business.

Take a look at this:

Have you read this ?

raschemmel:
Recall that the purpose of termination resistors is to prevent reflected wave. That's why they have to be at the extreme ends of the main trunk.

I think what I was trying to convey is that the RS485 devices are identical for Master and Slave so there is nothing in the Hardware that makes one a Master or a Slave. Thus only the software knows "who's who ?" and if you look at some protocols there are packets with headers and then device ID numbers and devices only respond to commands sent to their device ID. On DeviceNet devices, there are rotary switches to set the device number (1 -63 I believe). What makes the Master the Master is that it has the device ID "0".

As I mentioned, software is not my area of expertise but I can tell you that any "protocol" you "create", (assuming you don't want to learn an existing protocol) that can identify a device ID and respond to it will work, provided the uController acting as the Master is running software that uses a CASE statement or some other S/W mechanism to determine that an incoming message is from a particular device that it is trying to control. You can test that yourself with only three arduinos. (one Master, one slave and one 3rd Party )
It's very simple. If the Slave responds and the 3rd Party doesn't then you're in business.

Take a look at this:

Have you read this ?

Some good resources. I'd say if i focus on getting the physical connections correct, i can then work on the code after that. It looks like the whole master/slave thing is mainly a collision avoidance thing.

Given that the rs485s long distance ability is only along the bus and not from the bus out the the devices connected onto it i would need to run 4 buses (4 rs485s) to connect to 4 other arduinos at large distances. 8 if i want full duplex.

I made a schematic to upload here which is just a sample showing 3 arduinos connected up. I wasn't able to fit all the connections onto the space provided on the cad software but the arduino on the top shows how the 4 rs485s might connect up to the one arduino. I haven't found any samples of people doing this kind of set up so i'm a bit in unkown territory.

I'm not sure if connecting all 4 to the tx and rx pins is a good idea or not? Collisions would obviously be an issue but i can work around that even if i write my own system to listen before transmitting etc. Also max current draw from the rx and tx pins could be a concern.

Maybe it would be better if each rs485 had its own serial pins using a soft serial setup?

Sorry i couldn't find an rs485 component in the cad program, so i used something else with 8 pins. Obviously id get the proper one on my main project schematic which i use kicad for. I use TinyCad to put together quick sample schematics for this forum.

Take a look at this

That schematic is not an RS485 network. I don't know what it is but it doesn't conform to anything I've ever seen. You can't have multiple processors connected to the same Tx and Rx pins. The maximum is two, (one at each end). If you want a network, you have to use RS485 network devices, like the MAX485 or the LT1481, and it must conform to standard RS485 network configuration, like the link above. What you have posted is not a valid circuit, and doesn't qualify as anything (AFAIK). The bus connections are on the differential A/B bus , not on the TTL serial side. Each RS485 tranceiver can only be connected to one device or microprocessor on the TTL serial side. The 'bus' is the A/B bus. That is the only place you can have multiple devices connected together. You circuit is invalid because of the following:

1- multiple connections on the 'non-bus' TTL serial side.
2- multiple devices on the Tx & Rx lines.
3-no bus
4-no termination resistors
5-no RS485 transceivers

Look at the DATASHEET

You seem to have completely overlooked the fact that what makes it possible to have multiple devices connected to the bus is that each device has a transmit enable, that is used to disable all but ONE of the devices at ANY given moment. If you have 6 devices on the BUS, only one of them is transmitting at any given moment. The rest are disabled via the DE pin. Read the datasheet.

At this point you should be asking yourself "How do you select the one device that is transmitting ?"
The answer is "That's what the RS485 BUS PROTOCOLS are designed to do. (MODBUS, CANBUS, DeviceNet, DMX512) Without them, you would have chaos and multiple bus collisions.

I suggest you do some homework and research RS485 because what you just posted indicates you are a long way from a working circuit. (as far as I can tell).
There are NO RS485 devices in that schematic An RS485 device is a transceiver like a MAX485 or a LT1481. There is no such thing as an RS485 network without RS485 devices.

Take a look at the MODBUS Protocol

Note how there is a slave address, a message length, a start address (Hi, Lo) , data, an error check and much more. Control of the transmit enable is address dependent. In a way, you could say that the "slaves" are only allowed to "speak" when they are "spoken " to.