serial port unreliable

I've had an Arduino-based circuit controlling a solar hydronic installation for one and a half years now (it's an Arduino NG with an ATMEGA168 chip). This system is completely reliable, making sure water gets heated when the sun is out and turning off everything when the water coming from the panel is too cool to be useful. I can monitor this Arduino remotely using a 150 foot USB cable (they used to be available for cheap from PacificGeeks.com until that company started charging a minimum of $35 for shipping and handling). My question concerns the reliability of the Arduino serial port. It seems to work for awhile (a few hours) and then it inevitably locks up, requiring the board to be rebooted in order to resume communications. I've seen this behavior with several NG boards, connected to both Windows and Debian machines. At least on the Windows machine, I'm running the latest version of the FTDI USB Drivers. Does anyone know how to improve the reliability of the serial port?

I'd say it has more to do with your USB cable length. 150ft far exceeds the limits of the specification. Can you try running it on a short cable to see if you experience the same problems?

http://www.usb.org/about/faq/ans5

i've hooked up a laptop near the Arduino to see if the problems are cable related, but...

The 150 foot USB cable has hardware repeaters built into it and is exactly what it is -- a prebuilt USB cable, but it is cheap and Chinese, so perhaps it is the problem. But why should the serial port require an Arduino reboot when there is a problem? Shouldn't it be able to handle issues more gracefully? I don't mind occasional occurrences of bad data -- I just can't handle the lockups.

Maybe you’re causing a buffer overrun somewhere that puts the Arduino in a bad state? Otherwise you’re right, serial errors should not lock up the mega168. I don’t know enough about how the Arduino handles serial communication to give you any useful advice beyond suggesting that if you need more reliable serial communication or more graceful error handling, you could consider writing your own serial handler as serial communication with the mega168 is fairly straightforward.

  • Ben

I should add, by the way, that the serial port lockups I'm talking about only affect the Arduino's serial port - the program it's looping through is unaffected. But when this happens, my communication with the Arduino is cut off until I reboot it.

Maybe you could try restarting the serial communication in your Arduino code if it fails to get a response?

Restarting the serial port from the Arduino would actually be an ideal way to handle the problem. I could do it every hour even, since in this application constant communication isn't essential, but eventual communication is. Is there an easy way to do this? I know how to do all the usual things with the serial port, but I've never seen an example of someone restarting it.

I'm not sure if it actually restarts anything, but I was thinking just calling another Serial.begin(speed) might do the trick.

It's possible it's the ftdi chip freaking out, I'm not sure if that gets reset with the Arduino reset or not.

But when this happens, my communication with the Arduino is cut off until I reboot it.

When you say "reboot" the Arduino, are you just pressing the 'reset' button or are you removing power and reapplying it? Are you powering the NG via it's regulator or over USB?

Your question intrigued me, so I grabbed a 125ft USB extender (w/ repeaters) and also spooled out 150ft of CAT6 w/ USB connectors on it. The results (w/ both a Diecimila and an iDuino) show that the ATMega is ticking along happily, but one of three things happens to the FT232: - The line voltage on the repeater cable drops below 3.3V and the FT232 can't communicate. - The propagation delay occasionally vastly exceeds the USB signal rate and the FT232 drops too many packets. (again, only the repeater cable) - The 150ft of cable makes some nasty reflections, causing too many dropped packets. (only the bare CAT6).

In general though, the spool of CAT6 w/ USB ends worked far better than the 'high-tech' repeater cable. I have a feeling re-programming the FT232 to pure low-speed USB1 mode might solve some of the reflection issues (or just adding some terminating resistors).

As a matter of curiosity, I also ran out 150ft of CAT6 terminated in DB9 connectors and hooked up a MaxSerial. Using just the generic serial port on my desktop, I had no issues over the same time. Sometimes old-fashion works better. Assuming you could find some RS485 converters, I think you get a few KM of distance?

In this case I'm powering it with USB and "reboot" means to completely disconnect the USB cable, which kills the power to the board. When I'm programming it remotely, I use a relay to jumper the reset button (in these old Arduino NGs you must reboot before reprogramming, though there's too much noise in a line that long to run the reset wire 150 feet without getting constant reboots - thus the relay). This setup allows me to update software on the Arduino from my computer at the other end of the house as I add more routines and nuances to the solar panel control algorithm.

When you say "CAT6 with USB ends" - you mean just the connectors, no repeater hardware? And that actually worked (albeit imperfectly) across 150 feet? And without shielding? I've actually thought about doing a simple serial link, since I have no need for high speed communications. I could just remove the repeater hardware and the USB connectors and use DB9 instead. The cable is shielded and the individual conductors are twisted - even with primitive RS232 tech it should be able to work reliably for 150 feet.

I'm pretty sure from my tests that all my reliability issues come from the cable. I guess this is why it was discontinued.

Does anyone know where I could buy an old Serial Arduino? I could hook up a MaxSerial or retrofit one of my Arduino-capable & serial-equipped Olimex boards, but a Serial Arduino would plug right in and require a minimum of work. If anyone here has one, are you interested in selling it? It doesn't even need to come with a working Atmega processor.

In this case I'm powering it with USB...

The easiest solution may just be to pickup a 9V adaptor and power your NG externally instead. Both 'repeater' cables I have here (10ft and 125ft) mention on the front they only work with 'self powdered' (sic) devices.

When you say "CAT6 with USB ends" - you mean just the connectors, no repeater hardware?

Yes, just Cat6 (although not the cheapest spool) with $0.45 USB ends; I attached a full pair to each USB signal. And yes, that actually worked (other than some bad reflections). I am as amazed as everyone else.

I've actually thought about doing a simple serial link, since I have no need for high speed communications. I could just remove the repeater hardware and the USB connectors and use DB9 instead. The cable is shielded and the individual conductors are twisted - even with primitive RS232 tech it should be able to work reliably for 150 feet.

Based on my experience, this is the way to go. I will add that this PC's transceiver actually swings a full +/-9V and the MAX232 on the other end swings +/-8 with this much cable; many USB->Serial converters normally only do +/-5V or even just 5V/0V. Obviously you'll need some sort of line driver on the NG's end.

Does anyone know where I could buy an old Serial Arduino? I could hook up a MaxSerial or retrofit one of my Arduino-capable & serial-equipped Olimex boards, but a Serial Arduino would plug right in and require a minimum of work. If anyone here has one, are you interested in selling it? It doesn't even need to come with a working Atmega processor.

Not that I'm in anyway biased in this :P (the MaxSerial is my product), but you should be able to just plug-in a MaxSerial in place of an NG or Diecimila, other than the USB bits, they're basically the same circuitry and same physical dimensions.

Assuming you can power your NG externally, you should be able to hook-up a MAX232+caps to the NG's RX,TX,+5, and GND lines with a minimum of soldering. NCK sells MAX232 boards if thats what you want to do.

These would seem to be cheapest if you need to move to RS485/RS422.

Oh, for some reason I was using the term "MaxSerial" wrong - I meant a serial chip such as the Max232, and your use of it primed my brain with the right idea but the wrong word. I didn't know about MaxSerial - it looks like exactly what I need - a serial version of the Arduino that plugs in where the NG was. Thanks! I'll look further at your stuff to see what's what. You should get yourself listed on this page: http://www.arduino.cc/en/Main/Buy or is it another Iduino-type situation? Sometimes the distinguishing characteristics between different open source licenses and their commercial derivatives gives me a headache.

Oh, for some reason I was using the term "MaxSerial" wrong - I meant a serial chip such as the Max232

This, and your discussion of the Arduino Serial board, brings up an important side note. The MaxSerial is called what it is because it uses a MAX232 for the serial interface instead of official serial boards which use a trick with some transistors. Any of the "transistor serial" boards will not work for your application, you need a MAX232 (or similar) based board to generate the large voltage swings which make RS232 reliable over distance and noise.

I didn't know about MaxSerial - it looks like exactly what I need - a serial version of the Arduino that plugs in where the NG was.

That is exactly what it is, a serial board thats otherwise identical to the Diecimila (and NG) electrical and physical layout.

You should get yourself listed on this page: http://www.arduino.cc/en/Main/Buy or is it another Iduino-type situation? Sometimes the distinguishing characteristics between different open source licenses and their commercial derivatives gives me a headache.

The story here is (in theory) simple, The Arduino Team produced some open source software and hardware, but runs a closed website and has a trademark on the term Arduino. This means you can freely clone and otherwise modify the hardware and software (so long as you share changes and attribute the original design), but you can't use the term Arduino directly to describe it and it's up to them what and how they list information on www.Arduino.cc. This is elaborated on in So you want to make an Arduino. The Freeduino community is, sort of, and answer to this: a name anyone may use and a website with basically everything. (Theres some history regarding cloning the Diecimila design, but it's not relevant to licensing.)

I got the MaxSerial kit today, soldered it together, and then figured out how to get the RS-232 data the 150 feet from my "laboratory" (where my computer is) to the basement (where the Arduino figures out when to circulate water through the solar panel). I'd considered using the 150 feet of shielded USB cable but opted instead to use a few conductors inside a mostly-unused CAT3 cable (I have a lot of CAT3 that I run to sensors and what not). The data to and from the MaxSerial is very reliable, and it's great having the Diecimila-vintage ability to upload software any time without a reboot - I just change the software, upload it, and sit back and watch the effects. It's like communicating with a probe on Mars, but without the speed-of-light latency issues.