Arduino Forum

Using Arduino => Project Guidance => Topic started by: nicov on Nov 12, 2012, 08:00 pm

Title: Communicating with an Arduino that is relatively far away
Post by: nicov on Nov 12, 2012, 08:00 pm
For my latest project, I need to have a PC communicate with an Arduino that is going to be relatively far away, up to about 150 feet cable length or a 75 feet straight line if I were to communicate wireless.
We won't be able to boost the signal anywhere in between, if it needs to be done we'll have to do it either at the PCs end or the Arduinos end, or both ends. To make matters worse we're going to be in a noisy environment too..

Communication needs to go both ways and must obviously be reliable. Speed is less important, even 2400 baud would be okay, altho 9600 would be nice for fast response times. But data integrity is the most important thing here.

As far as I understand, communicating anywhere over 16 ft using a plain USB cable is not going to work so I guess we can scrap that right away.
USB over CAT5/6 looks pretty interesting and from the sound of it it would handle distance too. But I have no experience whatsoever with it, it definitely sounds like the easiest solution.

RS232 would work probably work fine too if we could get a real RS232 connection over a CAT6 cable, I'm not so sure about TTL and its low voltages, but again no experience. The PC doesn't have a real RS232 port so we're stuck with either having another Arduino there or a USB-serial adapter, and neither of those give a real 12V serial signal. That can be solved with some circuitry but I would ideally want to use as little parts as possible to keep the clutter down.
Wireless might be a problem because we're in noisy environment, and there will be lots of cellphones and what not around too. On top of that it'd probably be the most expensive solution.

What do you suggest would be the best way to do this?
Thanks in advance :)


Edit: I should add that the Arduino will have its own power supply and does not need to be powered by USB.
Title: Re: Communicating with an Arduino that is relatively far away
Post by: Coding Badly on Nov 12, 2012, 08:07 pm

RS-485
CANBUS
Ethernet

Quote
To make matters worse we're going to be in a noisy environment too


As in...
• People shouting at each other?
• 16,500 volt motors going on and off?
• Run-of-the-mill 110 volt lines?
Title: Re: Communicating with an Arduino that is relatively far away
Post by: nicov on Nov 12, 2012, 08:27 pm
Quote
To make matters worse we're going to be in a noisy environment too

As in...
• People shouting at each other?
• 16,500 volt motors going on and off?
• Run-of-the-mill 110 volt lines?

Thanks for the suggestions, gives me something more to read up about!

Noisy both sound wise (racing engines with undampened exhausts, anything from 50cc mopeds to huge V8s) and probably worse than that: electromagnetic interference from the ignition systems on those engines.
Title: Re: Communicating with an Arduino that is relatively far away
Post by: Coding Badly on Nov 12, 2012, 08:39 pm

You are welcome.

electromagnetic interference from the ignition systems on those engines


Distance from the ignition wires to the communications wires?
Title: Re: Communicating with an Arduino that is relatively far away
Post by: nicov on Nov 12, 2012, 08:46 pm
Distance from the ignition wires to the communications wires?

The distance will vary but will in some cases be as little as a couple of feet if we need to have the wire go over one of the lanes or dig it into the ground if for some reason we can't hang it. That'd just be a spot though, most of the cable will be at least 10 feet away from any ignition wires.
Title: Re: Communicating with an Arduino that is relatively far away
Post by: nicov on Nov 12, 2012, 08:59 pm
Right now we're using a Labjack at the PC end, and parallel communication so basically one wire+ground to every sensor and output. This solution has been working trouble-free but the wiring is a complete mess.
We're using 3 CAT6 cables at the moment which is bad enough, we're adding more sensors now and would need a 4th one to have enough leads.

We figured it'd be much nicer to have all communication from and to the PC go through a single cable. We need the Arduino anyway to control the 16 7-segment displays we're adding as well, so I figured we might as well switch to some form of serial communication while we're at it.
Title: Re: Communicating with an Arduino that is relatively far away
Post by: PeterH on Nov 12, 2012, 11:06 pm
There are lots of options, and I think the main choice comes down to what sort of technology you're most comfortable using.

If you put a remote PC at the Arduino site, you can use various mechanisms to access the remote USB locally at your main PC, or you could leave the USB remote and tunnel the serial port over the network, or do everything you want at the remote PC and access whatever application you want to access remotely using whatever remote session technology you prefer. Or you can use a serial link and a USB-to-serial adapter to bring the serial link in to a virtual serial port.

I would have thought your best chance of getting reliable comms over that distance starting from a noisy environment would be to use the remote PC and a LAN connection.
Title: Re: Communicating with an Arduino that is relatively far away
Post by: graynomad on Nov 13, 2012, 12:50 am
RS-232 is not a good option here. My personal choice would be RS-485, it's designed for industrial environment and simple to use as to the software it's just a serial connection.

Ethernet is probably OK as well (there is an industrial Enet spec isn't their?). I think it would be more complex to get working, but that's probably just my lack of knowledge on it showing through.

______
Rob
Title: Re: Communicating with an Arduino that is relatively far away
Post by: zoomkat on Nov 13, 2012, 02:55 am
Quote
We're using 3 CAT6 cables at the moment which is bad enough, we're adding more sensors now and would need a 4th one to have enough leads.


So have you disconnected a couple of the existing wires and tried TTL/rs232 communication over them? Instead of speculating do some testing.
Title: Re: Communicating with an Arduino that is relatively far away
Post by: runaway_pancake on Nov 13, 2012, 03:13 am
What's your budget?  Fibre-optic is immune to noise.

MAX232 and MAX233 have nominal ±10V outputs.

.
Title: Re: Communicating with an Arduino that is relatively far away
Post by: nicov on Nov 13, 2012, 04:04 am
Using a 2nd PC would definitely make things easier for communication but wouldn't be very practical for us otherwise, and it's probably way more than we need.
This stuff is always outdoors when used (except for the control PC) and needs to be weather proof.

All this is for a portable drag racing timing system that I built together with a couple of friends. Like I said we're using parallel communication at the moment. We have 6 inputs (reaction time, trap speed and elapsed time optical sensors, times 2) and 14 outputs (the lights on the tree). Communication to the outside goes through 3 CAT6 cables which go to our "hub" which is built in in the tree itself. In there the cables are split up and go to whatever destination they're supposed to go to: one of the relay boards for the lights or the connector for the sensors.
We're expanding a bit now and are going to add a time display which would needs another 4 wires that need to go outside, and we also want to add more sensors. In the end we'd probably end up having 5 cables and connectors at the PC end..

These cables are the main problem, they're a pain in the *ss to install every time we go to a different event, especially if the organizer does not have the control room/hut in the middle between the lanes because that means our 3 cables have to cross one of the lanes.
Having a single cable here would make life a whole lot easier on those early saturday mornings when we have to install the stuff :)

We've looked at cables with more leads because just having a single cable instead of 3 seperate ones would help a lot, but they are pricey too. If we had to we could afford it but we get CAT6 for free and now we'd rather have a non-parallel solution so it's future proof.
I guess my budget is around $100, don't want to spend too much money on something that's not essential. The current stuff works and adding more cables for the new stuff would work too, but it would be a lot nicer to have it all go to the tree over one cable.
Title: Re: Communicating with an Arduino that is relatively far away
Post by: graynomad on Nov 13, 2012, 05:27 am
You can get USB to RS-485 dongles for the PC that just look like a serial port.

https://www.sparkfun.com/products/9822 (https://www.sparkfun.com/products/9822)

This is half-duplex but you could make your own full-duplex version easily. The FTDI data sheets have examples but it's pretty simple.

And at the Arduino end you can get an RS-485 shield, once again I think half-duplex but that doesn't really matter and you could make your own full-duplex version for maybe $20.

Full- or half-duplex doesn't matter much, it just determines how you write your code.

______
Rob
Title: Re: Communicating with an Arduino that is relatively far away
Post by: nicov on Nov 13, 2012, 03:28 pm
I've been trying to get my USB-serial cable (PL2303) to work with a Uno but so far no luck with that. Seems like I tried every possible port setting but I always end up getting loads of errors. And this is with about 4 ft of cable.. I'm pretty sure I must be doing something wrong or maybe the cable is just rubbish.
So the next approach was to try and use a Leonardo as a proxy. It forwards whatever it gets on Serial (USB) to Serial1 (RX1/TX1 pins) and vice verca. That actually seems to work so now I got my PC talking to my Uno through the Leo. And more importantly, using a signal that I can do something with.

RS485 sounds like it'll do the job.
I'm looking at half duplex MAX3082 transceivers or maybe full duplex MAX3081. Would that work?
I'm pretty sure I'm not going to need full duplex though. These do 115kbps which is already more than I need. But there's faster versions too, would there be any use in getting a faster one
Title: Re: Communicating with an Arduino that is relatively far away
Post by: retrolefty on Nov 13, 2012, 03:40 pm
RS485 sounds like it'll do the job.

That would be my choice also. Be sure to read up on proper wiring methods for RS-485 links. This usually involves wiring 150 ohm termination resistor across the data+ and data- terminals at the both the local and remote receivers inputs terminals. Also using shield cable is helpful, grounding the overall shield at only one end of the cable run.

I'm looking at half duplex MAX3082 transceivers or maybe full duplex MAX3081. Would that work?
If you go with the two pair full duplex option you won't have to modify the arduino serial library code to properly generate the transmit enable/rec enable signal required to 'turn around' the voltage translator chips. This required serial code modification is now even more tricky sense the arduino serial library has gone to interrupt based transmit buffering. Using two pair full duplex makes the whole link more transparent to the standard arduino software, at the extra expense of a second wire pair of course, a better tradeoff in my opinion as your cable run is not all that long or expensive.
I'm pretty sure I'm not going to need full duplex though. These do 115kbps which is already more than I need. But there's faster versions too, would there be any use in getting a faster one

Probably not, but that really depends on the amount of data you have to move and what you are doing with the data at each end. General advice is to run only as fast as you require and no faster.
Lefty
Title: Re: Communicating with an Arduino that is relatively far away
Post by: nicov on Nov 13, 2012, 04:06 pm
Thanks for the quick reply :)
Full duplex it is then, I guess! The price is about the same but my favorite shop only has the half-duplex version. But I can get the full-duplex ones elsewhere.

The amount of data being sent back and forth is not a whole lot. The PC sends a request which is at most 20 bytes and the Arduino replies to that, the replies' lengths depend on what kind of request was made and will be anywhere from 1 to maybe around 30 bytes.
To eliminate the need for high-speed communication the Arduino does most of the processing. Basically the Arduino does most of the hard work and just sends an event log to the PC so it know's whats going on. A high estimate would be 100 bytes/sec from Arduino->PC and 200 bytes/sec from PC->Arduino (and much less if I move all the scoreboard code to the Arduino).
So even 115kbps is way more than I need.
Title: Re: Communicating with an Arduino that is relatively far away
Post by: dc42 on Nov 13, 2012, 04:22 pm
Here are a couple of other ideas:

1. Emulate the old current loop serial interface using opto isolators connected to the serial port. It wouldn't work at 115200 baud, but should be OK at 9600.

2. Between 2 Arduinos, you could use SPI at a slow clock rate, again with opto isolators.
Title: Re: Communicating with an Arduino that is relatively far away
Post by: retrolefty on Nov 13, 2012, 04:25 pm

Thanks for the quick reply :)
Full duplex it is then, I guess! The price is about the same but my favorite shop only has the half-duplex version. But I can get the full-duplex ones elsewhere.

If you are talking about the RS-485 chips you can use a pair of half duplex chips and just 'hardwire' the enable signal(s) one transceiver chip to receive mode for one cable pair and the other chip to transmit mode cable pair. So maybe four chips to support both ends? I haven't really checked out the chips you are considering but most operate the same.

The amount of data being sent back and forth is not a whole lot. The PC sends a request which is at most 20 bytes and the Arduino replies to that, the replies' lengths depend on what kind of request was made and will be anywhere from 1 to maybe around 30 bytes.
To eliminate the need for high-speed communication the Arduino does most of the processing. Basically the Arduino does most of the hard work and just sends an event log to the PC so it know's whats going on. A high estimate would be 100 bytes/sec from Arduino->PC and 200 bytes/sec from PC->Arduino (and much less if I move all the scoreboard code to the Arduino).
So even 115kbps is way more than I need.

Good, so if you do find you have any intermittent garbled data due to noise you could always try and reduce the speed to see if that eliminates the problem. At the refinery I worked at we used many many RS-485 links, many running over a thousand feet at 9600 baud mostly. However we run the twisted pair through hard electrical conduit and used high quality low capacitance cable with overall shielding. Anyway RS-485 is a very reliable method to route serial data over distances, that's what it was designed for.
Lefty

Title: Re: Communicating with an Arduino that is relatively far away
Post by: nicov on Nov 13, 2012, 05:49 pm
Using 4 would work I guess :)
I'm having a bit of trouble finding a local source for the low speed full duplex versions but the MAX3082E seems to do what I want so I just need 4 of them then.

So if I'm getting this straight this is how I would hook this up:
For the local TX to remote RX:
Local side: DE to Vcc/+5V, DI to TX.
Remote side: RE to Vcc/+5V, RO to RX.
Local A to remote B, local B to remote A. And a resistor between A and B on both sides.
A 0.1 uF condensor between Vcc and +5V, and GND to ground obviously.

(http://howisbabbyformed.info/max3082.gif)
Title: Re: Communicating with an Arduino that is relatively far away
Post by: retrolefty on Nov 13, 2012, 06:10 pm

Using 4 would work I guess :)
I'm having a bit of trouble finding a local source for the low speed full duplex versions but the MAX3082E seems to do what I want so I just need 4 of them then.

So if I'm getting this straight this is how I would hook this up:
For the local TX to remote RX:
Local side: DE to Vcc/+5V, DI to TX.
Remote side: RE to Vcc/+5V, RO to RX.
Local A to remote B, local B to remote A. And a resistor between A and B on both sides.
A 0.1 uF condensor between Vcc and +5V, and GND to ground obviously.

(http://howisbabbyformed.info/max3082.gif)


Well you really need to show four chips wired to two separate cable pairs. One the local side one chip (for the local's transmit signal) has DE wired to Vcc and RE wired to Vcc, and DI wired to serial tx pin. The other local chip (for the receive signal) has it's DE wired to ground and RE wired to ground and it's RO pin wired to arduino rec pin. The remote has a similar setup as long as you keep in mind the direction of data flow through each seperate cable pair. And yes, four 150 ohm resistors wired from A to B on all four chips. And good on remembering about the benefits of bypass caps at the Vcc pins to ground for all four chips. Does that help? English is a poor method to talk electronics as a schematic drawing is the true language of electronics.  ;)
Lefty
Title: Re: Communicating with an Arduino that is relatively far away
Post by: graynomad on Nov 13, 2012, 06:17 pm
Quote
Local A to remote B, local B to remote A

All As together and all Bs together. Have a look in the data sheets, they always have examples.

Quote
And a resistor between A and B on both sides.

Correct.

______
Rob
Title: Re: Communicating with an Arduino that is relatively far away
Post by: nicov on Nov 13, 2012, 07:35 pm
I will try and draw a schematic, but knowing my drawing skills I'm afraid it might not make things a whole lot clearer ;)

So A goes to A and B goes to B. The datasheet did have an example but it was a bit unclear to me how they were supposed to be connected because the schematic showed the wires as being twisted and I couldn't figure out what went to what.
Title: Re: Communicating with an Arduino that is relatively far away
Post by: nicov on Nov 13, 2012, 10:31 pm
Here we go... This is the first time I've ever used Eagle or drawn a schematic and I can't say that I really know what I'm doing ;) So I'm guessing it's not going to be all that great. I found the drawing process a bit frustrating so I only did one side for now.
(http://howisbabbyformed.info/schematic.gif)

Does that look like it would work? Or do I need to connect the unconnected pins to something too?
Title: Re: Communicating with an Arduino that is relatively far away
Post by: Coding Badly on Nov 13, 2012, 10:43 pm

C1 and C2 look suspicious.
Title: Re: Communicating with an Arduino that is relatively far away
Post by: nicov on Nov 13, 2012, 11:27 pm


C1 and C2 look suspicious.

I thought so too.. But the example schematic was a bit unclear again to a schematic noob like myself.

This is what's in the datasheet:
(http://howisbabbyformed.info/3082sample.gif)

If they didn't mean what I had in the previous schematic, how is this one?
(http://howisbabbyformed.info/schematic2.gif)
Title: Re: Communicating with an Arduino that is relatively far away
Post by: Coding Badly on Nov 14, 2012, 12:53 am

That looks better (the capacitors; someone else will have to comment on the rest).
Title: Re: Communicating with an Arduino that is relatively far away
Post by: graynomad on Nov 14, 2012, 01:39 am
RE is active low, on the right-hand chip it's pulled high.

______
Rob
Title: Re: Communicating with an Arduino that is relatively far away
Post by: nicov on Nov 14, 2012, 02:16 am

RE is active low, on the right-hand chip it's pulled high.

______
Rob

Aha, thanks for that hint! I thought something might be up with it, with the slash after the name or the "overscore". Learning by doing, I guess ;)
So I need to connect it to ground on the right side one then.

I found this table in the datasheet:
(http://howisbabbyformed.info/3082table1.gif)

So on the left side, RE can be disconnected, DE to VCC.
On the right side, RE to GND, DE can be disconnected.

Like this?
(http://howisbabbyformed.info/schematic3.gif)
Title: Re: Communicating with an Arduino that is relatively far away
Post by: retrolefty on Nov 14, 2012, 02:28 am
On the remote end you really should ground pin 3, DE, to make sure it's transmit driver is forced off into tri-state mode.

Lefty
Title: Re: Communicating with an Arduino that is relatively far away
Post by: nicov on Nov 14, 2012, 02:35 am

On the remote end you really should ground pin 3, DE, to make sure it's transmit driver is forced off into tri-state mode.

Lefty

According to the table it shouldn't care but I guess better safe than sorry ;)

Version 4 then:
(http://howisbabbyformed.info/schematic4.gif)
Title: Re: Communicating with an Arduino that is relatively far away
Post by: graynomad on Nov 14, 2012, 02:52 am
Quote
the slash after the name or the "overscore"

Also the small circle on the graphic, on chips that means an active low or inverted signal.

Just some notes about schematic layout.

If you mirror image the remote chip the drawing will be a lot clearer.

When things are tied to power rails it's almost always better (clearer) to have VCC going up and GND going down. Your caps go up.

Most beginners make a real dog's breakfast by running the GND wire to every possible place. You haven't done that which is good, in this case however I would argue that because these chips are physically remote from each other you should draw the GND line between the two to reinforce that they have to have a common GND and that that is formed by a GND wire in the cable.

______
Rob
Title: Re: Communicating with an Arduino that is relatively far away
Post by: nicov on Nov 14, 2012, 03:49 am
Thanks for the helpful hints Rob, I appreciate it!

How do you like this? It does look a lot clearer :)
(http://howisbabbyformed.info/schematic5.gif)
Title: Re: Communicating with an Arduino that is relatively far away
Post by: retrolefty on Nov 14, 2012, 03:56 am

Quote
the slash after the name or the "overscore"

Also the small circle on the graphic, on chips that means an active low or inverted signal.

Just some notes about schematic layout.

If you mirror image the remote chip the drawing will be a lot clearer.

When things are tied to power rails it's almost always better (clearer) to have VCC going up and GND going down. Your caps go up.

Most beginners make a real dog's breakfast by running the GND wire to every possible place. You haven't done that which is good, in this case however I would argue that because these chips are physically remote from each other you should draw the GND line between the two to reinforce that they have to have a common GND and that that is formed by a GND wire in the cable.

______
Rob


Actually these don't require a common ground between the local and remote chips, that is one of the advantages of the A/B signals being a true differential signal pair. I'm sure some will disagree with this, but I would say hold off until you actually test such a link using independent power sources at each end, it will continue to work without a common ground wire between the pair.

Lefty
Title: Re: Communicating with an Arduino that is relatively far away
Post by: retrolefty on Nov 14, 2012, 04:00 am


On the remote end you really should ground pin 3, DE, to make sure it's transmit driver is forced off into tri-state mode.

Lefty

According to the table it shouldn't care but I guess better safe than sorry ;)

Version 4 then:
(http://howisbabbyformed.info/schematic4.gif)


Your probably right, but I'm kind of a belt and suspenders kind of guy and like to hardware the control signals when I know they are never going to be switched.
Lefty
Title: Re: Communicating with an Arduino that is relatively far away
Post by: graynomad on Nov 14, 2012, 04:40 am
Welcome to the world of conflicting opinions Nico. This is one of the common dichotomies like Canon/Nikon, Ford/GM etc.

I have experience with RS-485 but Lefty has made a career of using it in very bad environments, so I'll bow to him on this while retaining the right to differ :)

IMO the schematic is much clearer now.

______
Rob
Title: Re: Communicating with an Arduino that is relatively far away
Post by: nicov on Nov 14, 2012, 01:34 pm
Thanks guys, really appreciate your input! :)

One more question then. Over here (http://www.maximintegrated.com/datasheet/index.mvp/id/1522), Icc is specified as 0.375 mA typical, the PDF datasheet I have says max 1.000 mA. So I assume it will be safe to power the chips from the Arduinos 5V if the local Arduino is USB powered?
Title: Re: Communicating with an Arduino that is relatively far away
Post by: retrolefty on Nov 14, 2012, 02:58 pm

Thanks guys, really appreciate your input! :)

One more question then. Over here (http://www.maximintegrated.com/datasheet/index.mvp/id/1522), Icc is specified as 0.375 mA typical, the PDF datasheet I have says max 1.000 mA. So I assume it will be safe to power the chips from the Arduinos 5V if the local Arduino is USB powered?


Certainly.
Title: Re: Communicating with an Arduino that is relatively far away
Post by: radman on Nov 15, 2012, 04:38 pm
Quote
I have experience with RS-485 but Lefty has made a career of using it in very bad environments


Why use RS485 though rather than RS422 if there is no need to multidrop?
Title: Re: Communicating with an Arduino that is relatively far away
Post by: graynomad on Nov 15, 2012, 05:52 pm
I don't think it matters here. 485 has better common-mode voltage specs, and I think the chips are easier to find and there's a larger range, but either is good I think.

_____
Rob
Title: Re: Communicating with an Arduino that is relatively far away
Post by: retrolefty on Nov 15, 2012, 06:10 pm
Yes either can be made to work as long as the driver chip on one end is the same 'flavor' as the receiver chip at the other end.

By the way Wikipedia shows a good three resistor termination method one can use on the receiver end of each path (if using two pair full duplex) which will ensure no false data hits due to noise in case the far end of a link is powered off, it's shown in the first picture showing a series 680 ohm, 120 ohm, 680 ohm resistors wired to the recievers Vcc and ground and A and B signal pins. Good idea.

http://en.wikipedia.org/wiki/EIA-485

Lefty
Title: Re: Communicating with an Arduino that is relatively far away
Post by: nicov on Feb 28, 2013, 10:25 pm
I finally got around to finishing this up.. And wanted to update the thread with some findings.
The first is that the remote/RX end pin 3/DE must in fact be grounded. I just got garbage if I didn't ground it.
The other is that B on one end must be connected to B on the other end, and A to A. Connecting B to A and vice versa also gave garbage.
It seems to work fine without the resistors too, but I assume that may change with longer distances so I put them there anyway.
Figured this stuff might be good to know.

The chips I'm using are MAX3082E. Amazingly everything worked as expected the first time I connected it, I had to actually disconnect some stuff to make sure it wasn't just the software fooling me ;) This weekend we'll test with a longer cable in between.

Thanks again for all the help!
Title: Re: Communicating with an Arduino that is relatively far away
Post by: nicov on Mar 04, 2013, 03:07 pm
Another update.. We put the stuff to the test this weekend. Using 75 meters of cat6 cable between the 2 sides, in an electronically noisy outdoor environment, the chips powered by the Arduinos +5V pin, 2 chips per Arduino/side, no common ground. To top it off temperatures were -15C/5F and there was a blizzard going on.

The result of the test was that everything worked perfectly fine, no trouble whatsoever! :)
Title: Re: Communicating with an Arduino that is relatively far away
Post by: graynomad on Mar 04, 2013, 03:24 pm
Good stuff.

______
Rob