Showing posts with label Bootloader. Show all posts
Showing posts with label Bootloader. Show all posts

Sunday, September 27, 2009

Bootloading the Arduino over XBee ZB, Part II

Right, so I got the Arduino to load over XBee with the default bootloader. But I am still stuck with having to manually hit the reset-button on the Arduino.

So here is my plan. (I've seen various variations on this on the 'net, but not exactly what I want. Someone has probably done it, before, though. I don't care.) I wonder if that whole CTS hardwired to Reset can work for us his time. What I want is for the DTR, when received over the USB-connection by the XBee Coordinator, to magically reset the Arduino. This should in theory be very simple with the XBee shield.
  • On the XBee EndDevice, set DIO7 to mode 4, which is "Digital Out, Low". (ATD7=4, if you're doing it by hand)
  • Then, on the XBee Coordinator, set DIO7=Input (ATD7=3), and IC=80 (IC is a bitmap of which inputs to monitor, 40h is a bitmap with only the 8th bit set, counting from IO0)
  • Finally, solder a jumper on your XBee explorer, tying DTR and CTS together. (Actually, this should probably be a resistor.. I'm guessing CTS is an input on the FTDI. And Maybe it should be possible to revert this somehow, I think X-CTU depends on CTS and DTR for firmware-loading. Minor details!)
  • Done!
Looks good, no? This should work because the XBee's are quite intelligent little things. Because we set DIO7 on the Coordinator to Input, the XBee should automagically send this information to whichever XBee is addressed in the Coordinators DH/DL-registers (you did program those, didn't you?). And since we hardwired DIO7 to DTR, whenever AVRdude asserts DTR, the remote XBee will assert DIO7. And, as we know from bitter experience, DIO7 is hardwired to Reset on the XBee shield.

Sounds simple, doesn't it. Perhaps too simple.. I've struggled with this for a few hours, but no matter what I do, no matter what config, no matter what firmware, I can not get the target XBee to change its outputs.

I've concluded that this functionality ("transporting" Digital IO-lines) only works on Series 1 XBee's. Something that is not clear in the documentation. (As a sidebar, I would like to note that the XBee documentation in general is not all that great..)

Anyway, I've opened a case with Digi on this, hopefully they will come back with a clear answer. I'll update if they do!

Update! I've heard back from a very pleasant support-person at Digi, and he confirmed my suspicion. This is not supported on the XBee ZB, and it probably never will be. They also confirmed that this does work on their series 1 radios, the XBee 802.15.4.

So, what would the workaround be?? Well, I've verified that asserting DIO7 will reset the arduino. So I guess I'll write a small wrapper for AVRdude, which sends a package to the remote XBee instructing it to set DIO7 high, then low, and then fires up AVRdude. Might work. The bad news is that it will require the API firmware, at least on the Coordinator. Don't yet know if API Coordinator with AT EndDevice will have the desired effect. I do not yet know if I can make this work, if the EndDevice needs to have the API firmware in order to support remote commands, I don't think it will send the data straight out on the serial, but rather in a frame-structure. Meaning I'd need a custom bootloader in order to decode the data.. Hm.

So I suppose there will be a "Bootloading the Arduino over XBee, Part III". Sometime.

Bootloading the Arduino over XBee ZB

I was playing with the XBee and Arduino again, and reading a lot of posts about how to bootload the Arduino wirelessly over the XBee. It was a fairly intricate process, involving among other things a custom bootloader. Now, it should be said that most of these posts were fairly dated, so there may be something that's changed. Because when I tried it, it worked on first try, with the default bootloader.. Mysteriously.

Setup: XBee Coordinator on XBee USB Explorer on COM5, XBee EndDevice on Arduino Mega.

(BTW, if you read my previous post, this will not work with the rerouted Serial. Put both jumpers to 'XBEE' on the XBee Shield)

Anyway, here's how I did it.

  • Set up both XBee's to use 57600 baud.
  • Upload .hex-file using AVRdude. Here is my cmdline:
 avrdude -Uflash:w:ledXBee.cpp.hex:i -cstk500v1 -P \\.\com5 -pm1280 -b 57600 -D
  • At the precise moment you hit Enter, also press the reset-button on the Arduino. You may have to try a couple of times. Basically, methinks its because DTR isn't transmitted to the Arduino wirelessly, so you have to perform that duty yourself. I have an idea on how to fix it, but it requires some soldering..
  • Done.

A screenshot may be in order:

Ok, so that works like a charm. I must explain that the XBee's are 4 inches apart, and the binary is less than 3K. I don't know if it'll scale in size or distance.

So, over to that last pesky bit, having to hit reset manually.. But that will have to wait to another day.