Go Down

Topic: I/O between arduinos with opto coupling. Sample schematic  (Read 5228 times) previous topic - next topic

jeffez

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

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.

jeffez

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! :)

raschemmel

Quote
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.
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

jeffez

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.

jeffez

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?

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.
Whst is the definition of Master or Slave ?
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

jeffez

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.

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.

jeffez

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.

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.

Quote
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 ?
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

jeffez

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.




raschemmel

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.
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

jeffez

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.
I now can see major mistakes i did there, pretty embarrassing :D took me a while to get back due to other work etc. But i think i've now got this right (or at least close). I missed the termination resistors on the previous diagram because the rs485s i was going to use were on a small pcb that already had the resistors on them.

Anyway this diagram i did with max485 chips and would utilise a software serial library to allow tx and rx to work on normal digital pins.

jeffez

I noticed that on this RS485 board which uses the max485 chip, there's extra vcc applied and resistors in extra places.




I based my diagram off the schematic in the first page off the datasheet which didn't show these, but that may be because the datasheet only shows a part of the full circuit needed for use with an arduino.  Should i add these into my schematic with the max485s?

Here's another example but there's no 10k resistors on R0 RE DE D1 and the resistors on the other side are only 680 ohms where as on the one above uses 20K ones.
http://www.gammon.com.au/forum/?id=11428

raschemmel

I can't read a schematic the size of a postage stamp. I don't know what you did but that file is resized into oblivion . Start over and don't resize it unless you have to and then only 20% at a time .


Quote
I noticed that on this RS485 board which uses the max485 chip, there's extra vcc applied and resistors in extra places.
There is only one Vcc. The Green screw terminals are for the A & B lines. Also, RS485 convention dictates one termination resistor at each end . You don't need all those other resistors. I've never used them and never seen them used any where else. It won't work with only one termination resistor. I told you it needs one at each end of the main trunk. If you can't post the photo of the schematic then post a link.
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

Go Up