Okay, Internet, tell me more about wireless bootloading.

One of my perennial bad electrical engineering habits is black-boxing electronics and software – not making much of an effort to understand how a (usually software) system works, just accepting that a solution is available and not extensively exploring it unless needed. Historically, I did this to electronic hardware too, coming from a more R/C hobbyist background (I don’t really consider the battlebots to be “robotics”) where things like “Receiver” and “Motor Controller” were considered atomic components as much as screws – they could not, and should not, be decomposed further. I’ve gotten a bit better at that, what with making entire motor controllers and all, but embedded programming is still one of my sour spots.

This is part of the reason why I like Arduino so much – it’s easy, reasonably well featured, and I don’t have to think about diddling registers and setting bits – 6.115 taught me to never do that again if I could avoid it – just to toggle an output pin. It makes the software experience just a little more like high level application programming, the kind I did before getting into hardware and actually all through high school (Did you know that I was CS before I was EE or ME?). Convenience is of the utmost importance, absolute code efficiency and running speed less so. Probably because I just haven’t done a complicated enough motor controller yet, or a flying thing with enough axes. Granted, I’ve also gotten slightly better at that, since there are just some things which are easier to do, like changing the PWM frequency of analogWrite(), by breezing through the manual and just doing the annoying bit shift thing, or enabling a regular interrupt so some part of my code runs with a fixed delta-time for control calculations. In summary, I favor trying and modifying existing solutions first in order to solve the high level problem of make thing work. Which is another great thing about Arduino and the general OSHW community – someone has probably done it already. Including build a smaller quadrotor, but that’s besides the point.

But I think I’ve reached the end of reasonable high level probing, because Chibicopter is not wanting to program wirelessly at all.

Here’s the rundown. I’m using the Adafruit Solution for wireless code uploading to the ATmega328-turned-arduino. There are some differences between my exact circuit and the “community solution” in this case – I’m running 3.0v logic power and my reset line is coming out of D6 instead of D3. The Little Purple Wire hacks are documented here. Otherwise, the level shifter/buffer circuit (which I feel isn’t really necessary) is the same, and for the first few attempts, the settings for my XBee Series 1 radios were also exactly the same as directed.

So here’s what’s been going on:

The Symptom: The remote reset always worked, but the program transmission itself has a success rate of maybe 5 to 10% at most. The most common symptom is hanging – the RSSI LED on the transmitting Xbee goes out, and the ‘Uploading” stage of the Arduino IDE never completes until it times out with an Out of Sync error. A few times, I’ve had programs make it all the way through and complete, but only once or twice, and then it becomes completely up to chance again. The successful attempts seemed to require uncorrelated “adjustments” such as exact location in room (possible radio bad spots or WiFi interference) and orientation of radio, which at such close range I find implausible to be the problem.

The fixes:

1. Complete hardware swap. I ordered more XBee Adapters because my one remaining unit was clearly showing reliability problems – I had to seat the XBee in the headers in a specific half-out fashion to get the power and associate LEDs to turn on, so to rule out the possibility of bad contacts or intermittent power, I made some new boards up. This did not result in any appreciable change in the operation – the vast majority of uploads still failed.

2. More radio power and XBee swap To test the interference theory, I borrowed Shane’s XBee Pro units which transmit at something like 150mW, which tends to outpower every 2.4ghz device around it. This did not affect the success rate of upload, but in this process one of my transmitting XBees was found out to be damaged. It was replaced with another of my radios (the one which had been handling LandBearShark’s load cell reading telemetry), to no appreciable change. I then borrowed two brand new radios, also to no appreciable difference.

3. Reduction to Tx/Rx only with stock XBee settings I removed the reset circuit’s digital I/O pin function so the pin did not toggle. The programming was then done just by hitting the reset button while uploading with only Tx and Rx active. This got me 2 or 3 consistent uploads (variations of Blink.ino), but after that, it once again become unreliable. I completely refreshed the settings a few times, changing only the baud rate to 57600 8-N-1.

4. Possible undervoltage operation problems The XBee is rated to operate between 2.8 and 3.5 volts. I’m running 3.0v, technically not really “3.3v”, so it could be that the XBee is being underpowered. Testing on real 3.3 volts provided by a bench power supply, using variations of Blink.ino only resulted in the discovery of the “uncorrelated adjustments” like Shane standing 5 feet to my left vs. next to my right, or using the back half of MITERS vs. the front, and turning my wireless LAN/Bluetooth off on my laptop vs. on. I do not believe any of those environmental factors are truly the cause of the problem.

5. Power Supply instability. Xbees, being high powered digital devices, draw current in bursts. I have very little 3.0v capacitance, so maybe little dips on the power supply was causing problems such as when the receiving end sent back start/stop flags. I piled a ridiculous amount of caps on the XBee pins directly during the above power supply runs, to no appreciable gain.

6. Trying a known working board. The 2.007 Nano carrier can wirelessly program using the “community solution” or using bone-stock settings on the XBees and manually pressing the reset button. This was demonstrated several times by Shane, but I could not get any of my hardware to reliably work with it either! This was eye opening, and pointed me to the fact that the problem may not lie with Chibicopter’s board. The full battery of tests – my Xbee adapter with both my radios and his radios, the XBee Pro, his own XBee USB dongle… none of them worked reliably if my computer was involved!

7. Messing with virtual COM port settings I tried the established solution (SET RTS ON CLOSE) with no other changes, changing the baud rate explicitly to 57600bps, and even installing a fresh, new FTDI cable to talk to the XBee adapter (thus installing an entirely new virtual COM with no possible previous changes). While the latter change appeared to result in success (4 reliable uploads), it stopped being reliable again thereafter. So promising ;-;

8. Literally trying wires. Hooking up transmitting TX to receiving RX, and vice versa, with GND bridged. This was literally plugging wires in and out of XBee sockets, and it worked without issue every time. This means the issue lies strictly between how the XBees interact with my computer and with eachother – once I literally bridged the connection, there were no communication problems.

Possible explanations we gathered:

1. Some hardware level difference between computers. While this seems to be a stretch, Shane’s Dell notebook can program Chibicopter with much higher reliability such that the random interference, voltage dip, and noise explanations begin to be plausible, and the Nano carrier essentially flawlessly. My HP DV7 can do neither. I’m not up to date on integrated computer peripheral hardware, but I do want to try the exact same parts on a Macbook – if it works on a Mac, then that would explain why there are so few complaints about it, given the Arduino and OSHW community demographic…

2. I am actually missing something very fundamental and stupid. Given that the uploads are so reliably unreliable, this seems almost like the most plausible explanation. Did I really forget to ground something? Are my traces actually soldered? They must be, because I can definitely program the damn thing over 3 wire serial! Are my XBees just cancerous? They’re both  Series 1 whip antenna types with the latest 10ED firmware now.

I’m willing to rerun some of the tests and provide more verbose error message logs, as well as COM port settings and XBee settings. But what the ass?

 

 

 

 

 

 

Chibicopter: It’s Reached “That Stage”

…you know, the stage of all my projects where they become stuck in software hell.

For Chibicopter, oddly enough, it’s not been the actual operation code which has stumped me, but the process of getting it there. As previously described, Chibicopter’s only means of code uploading after the ATMega328 has been turned into an Arduino is through wireless bootloading. This has been done successfully many times. In the Chibicopter board schematic, I included components intended to use the Adafruit Method, and a similar arrangement is used on the Gravitech XBee shield for the Arduino nano and on the 2.007 Nano carrier. So it’s gotta be pretty bulletproof, right?

Well, kind of. Here’s how shit went down.

First off, I had to make one last wire jump for everything to stand a chance of working. The reason is because I connected the RTS pin of the FTDI cable (through the wonderful Adafruit XBee adapter) to DIO8 on the XBees:

(Don’t mind where it says “DIO12” – that’s because Sparkfun’s XBee footprint is weird, or something – it’s actually DIO8 according to the manual)

I chose DIO8 instead of DIO3, the usual choice, because it was much closer to the appropriate pins of the ATMega based on component placement. It would have been less of a topological acid trip to route the trace there. The only problem with choosing DIO8? It’s not a thing. As in, DIO8 turned out to be only DI8 when I tried to configure it in X-CTU.

Hmm. Well that’s disappointing. Wire jump time:

I performed a Little Purple Wire jump, after cutting the DI8 trace, to DIO6 across the other side. Conveniently DIO6 was also the XBee’s default RTS pin. However, in the interest of following instructions for now, I configured the pin as standard digital input (on the transmtiter side) and a default-high digital output (on the receiver side). Now, I’m assuming there’s pretty much no difference at this point between setting it as instructed or setting both sides to “RTS FLOW CONTROL” for this pin, but I could be wrong.

The fix was promising at first – I could upload blink programs of various durations with no problems through Arduino, getting to the “Done Uploading” stage every time. But as soon as I tried uploading a bigger program, it would quit – usually after only a few seconds (short enough to transmit a blink program, but nothing much else). The activity LED would turn off, whereas if it were transmitting, it would be on pretty solidly.

Scoping the TX/RX pins and the DIO pin associated showed that the reset pulse was making it through (as my hack D13 LED did flash) and at least something program-like was being transmitted. However, it would randomly shut off, and the process would abort with avrdude-in-Arduino complaining that the programmer was out of sync.

I thought it might have been a mild baud rate mismatch problem (and still suspect it to some degree), so I hardwired Tx and Rx straight to eachother on the XBee adapter board:

Of course this arrangement worked. The blame now lay square with the XBee, and at Shane’s behest, I reset both XBees to factory default, wiping every setting I might have changed, and then changed things back exactly as instructed. (The transmitting one came out of the defunct RazErblades glove controller and the receiving side came out of…. hell if I know where)

It worked.

But only sporadically. I’m in a position now where some uploads will complete, some will totally fail within the first few seconds, and others will seemingly fail and cause Arduino to wait forever in the “Uploading…” stage until finally terminating, usually a full minute later, with an out of sync error.

Weeeeird. Well, at least I can upload some code:

I’ve since balanced the propellers much better (the whole thing doesn’t really resonate any more, though it’s still not in perfect balance) and have cut and paste enough code from Pololu’s MinIMU9 library to read all the sensors and process them. I’m not sure how you’re supposed to use their library, by the way, so I just copied and pasted the important I2C register-setting code from it and never looked back. Are you supposed to… instantiate a new instance of each sensor or something? It didn’t compile in Arduino 1.0, and the provided AHRS code was of little help since it had such lovely high level functions such as “Read_Gyro();” without explanation of where they came from, and which I couldn’t located in all the linked .h files anyway.

Anyways, Chibicopter is some more code and tuning away from flying, which is to say it will probably sit in a box for the next few weeks. If anyone from the Arduino hacker community has any idea why my code uploads are spotty, I am open to suggestions. My number one suspicion is still the 57.6Kbps baud rate mismatch now that other inconsistencies have been eliminated.

The next step is to revive XBYPASS and glue it back to my transmitter since for some reason I decided on making this thing talk over wireless serial. That step, however, has been done before. Wow, finally a legitimate use for XBYPASS that is not trolling the anti-Arduino crowd?!

Also,