Arduino xbee communications problems and corruptions

This document is out of date. The arduino core has changed so the attached can only be safely applied to early arduino ide versions.


I have encountered a few problems with xbee. Recent problems have concerned ArduCopter but there have been others. Other people have also reported problems.

I have used arducopter for this example but, as you will see, this problem applies to the arduino cpu and not to the arducopter software or apm hardware

Using a serial trace it was possible to see that data from the arduino/apm was corrupted. Both the config tool and the apm could “hang” which meant that data sent to the arduino was also being corrupted.

If the config tool did not hang immediately then incorrect and erratic values were displayed on the screen. A low xbee “packetization timeout” setting made the problem worse. Calibration was not possible.

I have yet to understand why some users were unaffected by the issue however, for me, it was such a problem that I was unable to use the arducopter configuration tool without some other apm code adjustments.

Those code adjustments were for testing purposes and were not practical for a “real” project so I looked for a better solution...


Over the past year or two there was a change to the Serial.Begin() method in arduino core code file called HardwareSerial.cpp, This code change affects the calculation of the best way for the arduino cpu to communicate over serial (at the required speed)

If we replace this small piece of arduino code with the code from an arduino version prior to the change then the serial xbee works perfectly ALL of the time


This solution requires testing by people who do not currently have a problem communicating via xbee. However, as I have said, the solution worked in the past, is an arduino coded solution (not mine) and I believe that this is an arduino bug introduced by an attempt to optimize the arduino serial output.

You can grab a copy of the altered HardwareSerial.cpp here or in zip from here. It should replace the existing file in <arduino install path>\hardware\arduino\cores\arduino.

Still got problems but much smaller?

I noticed that with xbee, every so often, all of the values in the arducopter config tool would still jump, although very briefly. The fix for this is to set the "packetization timeout" in the xbee (x-ctu) settings to 20


A tip to xbee users who have configured coordinator and associated pairs. The coordinator should power up first. For this reason I make the coordinator the airbourne unit because the battery power it switched on/off more frequently than the xbee powered by usb/pc

Motto of the story: If it ain’t broke don’t fix it

Read about how to create Arduino to Arduino communication