0

xbee for arduino wireless programming
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

xbee for arduino wireless programming

by mieczotronix on Mon Dec 22, 2008 6:14 am

I tried the solution described on this page:
http://www.ladyada.net/make/xbee/arduino.html
but I am having some problems.
I established the 19200 kbps connection between two modems, they see and talk to each other (checked with two serial consoles) but I've been having problems with arduino wireless programming.
Although reset works and programming starts and seems to proceed ok, it always ends with an error from avrdude. The errors I've been getting look like these:
Code: Select all | TOGGLE FULL SIZE
avrdude: stk500_paged_write(): (a) protocol error, expect=0x14, resp=0x64
avrdude: failed to write flash memory, rc=-4
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51


Sometimes, even if the programming ends with an error, the arduino gets programmed. The shorter the uploaded program is, the more likely it does.

I checked the transmission and it is ok, no interference. Checked it by tansmitting keyboard strokes from hyperterminal to x-ctu terminal over the two xbees, I didn't notice any errors. Exactly what I typed appeared on the other side.

The modems (regular Xbees with blue SMT antennas on adafruit's xbee adapters, one on ftdi 3.3v cable, the other connected to arduino) are some 50 cm apart and set to 4-HIGHEST power level.

The resp values (here: 0x64 0x51) seem to be the data the program that's already in arduino is meant to send over the air. It looks like avr dude having finished programming waits for some kind of confirmation from arduino, but never receives it since reset seems to occur too early and instead of bootloader acknowledgement avrdude gets response from the programmed app.


I tried with reset cap of 100n and 1100n, which seems to make a little difference, if any.
Any ideas?
mieczotronix
 
Posts: 9
Joined: Wed Dec 17, 2008 9:34 pm

Re: xbee for arduino wireless programming

by adafruit on Mon Dec 22, 2008 1:12 pm

which IDE are you using, which arduinos?

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: xbee for arduino wireless programming

by mieczotronix on Mon Dec 22, 2008 5:56 pm

0012 Alpha, Windows, freeduino (diecimila compatible) - one with USB. Ext power supply 7.4 V lipo battery

I've been just watching rx,tx and reset on scope. And the reset pulses are there at the beginning and at the start. But in 50% of cases the bootloader doesn't sync with the avrdude and avrdude doesn't event start to send data, the bootloader exits and arduino goes into app. Then avrdude keeps waiting for almost a minute, when it finishes its wait, it resets the arduino again (some times arduino gets programmed on that last reset) and terminates displaying errors. So I guess the reset cap is ok, but I guess my problems must be related to xbees' limitations (i.e. they can not send while they receive data while there's something in the buffer - and maybe that's why they doesn't catch up).

My xbees modules are from your shop (bought them this month), they are programmed as: XBEE XB24, Function set XBEE 802.15.4 and updated to 10CD firmware

EDIT: I've just reset both xbees to default and programmed them step-by-step according to your instructions. Now the red LED in Receiver stays always on while in the transmitter it only turns red while data is transmitted. Now I am getting more success with uploading small apps (<2k) while a large one (5k) never completes ok.
Last edited by mieczotronix on Mon Dec 22, 2008 9:17 pm, edited 1 time in total.
mieczotronix
 
Posts: 9
Joined: Wed Dec 17, 2008 9:34 pm

Re: xbee for arduino wireless programming

by adafruit on Mon Dec 22, 2008 8:19 pm

to be honest i didnt try large .hex's just blink type stuff. but it sounds like you're getting closer!

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: xbee for arduino wireless programming

by mieczotronix on Mon Dec 22, 2008 9:17 pm

Aha! Could you then try to program something larger with your setup? I'm just curious if that's something I've been doing wrong, or the whole idea is somehow flawed.
I've spent 4 hours today on this but got only blink type things getting programmed.

For the last hour I've been trying with higher data rates to avoid buffer full and stuff but this did not help either.
mieczotronix
 
Posts: 9
Joined: Wed Dec 17, 2008 9:34 pm

Re: xbee for arduino wireless programming

by adafruit on Tue Dec 23, 2008 1:24 pm

sadly my setup has been cannibalized for a new project. perhaps someone else watching can step in and verify?

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: xbee for arduino wireless programming

by bdaniels on Tue Dec 23, 2008 3:51 pm

Sounds like the same problems I've been having with my BlueSMiRF implementation. I was hoping this would not be the case with Xbee's.

bdaniels
 
Posts: 45
Joined: Thu Dec 18, 2008 12:29 am
Location: Mission Viejo, CA

Re: xbee for arduino wireless programming

by bdaniels on Tue Dec 23, 2008 3:53 pm

I've seen a guy able to do wireless programming with 900MHz modems that are un-encrypted, full-duplex, true bi-directional. But it was a $300 device, and the target modem came with a wall-wart :(

bdaniels
 
Posts: 45
Joined: Thu Dec 18, 2008 12:29 am
Location: Mission Viejo, CA

Re: xbee for arduino wireless programming

by mieczotronix on Tue Dec 23, 2008 5:52 pm

Not good....
So presumably all this is caused by the fact those modems are not working in duplex and the timing is not right.
It may also be the case that xbee waits until it collects some data in its out buffer then sends it. That may also introduce some timing errors. I'll have to read the documentation to see if there's any workaround.

Anyway the cheapest solution would be to tweak the bootloader or to write a new one - add some delays so that data is not getting lost and all stays in sync. But I'm not going to do that. I'll rather see on avrfreaks what bootloaders are there. I used to code in AvrStudio gcc anyway
mieczotronix
 
Posts: 9
Joined: Wed Dec 17, 2008 9:34 pm

Re: xbee for arduino wireless programming

by mieczotronix on Tue Dec 23, 2008 9:56 pm

Found this in the documentation
Code: Select all | TOGGLE FULL SIZE
Data is buffered in the DI buffer until one of the following causes the data to be packetized and
transmitted:
1. No serial characters are received for the amount of time determined by the RO (Packetization
Timeout) parameter. If RO = 0, packetization begins when a character is received.

I've set RO to zero but this has not improved things a bit...
mieczotronix
 
Posts: 9
Joined: Wed Dec 17, 2008 9:34 pm

Re: xbee for arduino wireless programming

by blalor on Wed Jan 07, 2009 9:30 am

I'm having the same problems as mieczotronix. I think I'm going to give Rob Faludi's method a go. Adding a transistor and tweaking the sketch a bit to help the bootloader do the upload isn't ideal, but if it works... Ladyada, any thoughts on going this route? Reading his description in more detail, I'm not sure it's going to help; the problem is less to do with the reset timing than it is with getting the data written reliably...

blalor
 
Posts: 30
Joined: Tue Jan 06, 2009 11:37 pm

Re: xbee for arduino wireless programming

by mieczotronix on Wed Jan 07, 2009 10:52 am

As you noticed manually triggering reset will not probably help you.
Also I think that data writting unreliability is not the cause
I guess the problem here lies with the way xbeess handle serial communication.
If you send data over a serial cable it appears on the other end instantenously.
When you send it over xbee - it may be first collected in a xbee's buffer until some minimum amount is connected / timeout expires. After data is is transmitted, xbee may (possibly) wait for an acknowledgement to see whether data got through, and (possibly) resend it, etc.
So it looks to me that xbee is introducing some unspecified delays to data being transmitted the bootloader protocol is not expecting to encounter. It may happen that everything works fine with small programs, but with larger ones delays accumulate or exceed bootloader thresholds. I haven't been touching the issue since Christmass, so I don't now much more than I knew back then.
mieczotronix
 
Posts: 9
Joined: Wed Dec 17, 2008 9:34 pm

Re: xbee for arduino wireless programming

by boulderbill on Thu Jan 08, 2009 12:39 pm

Hi all,

Wanted to jump in to the conversation here. Have been working on some pretty fun stuff with 120 diecimila arduinos, all with an Xbee shield attached. Have had a lot of success ( well, 30% accuracy, I'd say ) wirelessly uploading programs to remote arduinos using a few different techniques, including a version of Rob Faludi's "*reset" string, as well as using a physical button and line passing on the xbee to perform a hard reset on the remote arduino. These techniques seem OK, but now we are trying to automate the process ( to reprogram all 120 boards! ) and are running into a bunch of problems. Using a macro program we have been able to upload only a handful of times. I agree with mieczotronix that it could definitely be a problem with the xbee's buffer; we are also trying to load very large ( almost maximum ) programs, and are much more consistently getting 50% or greater into the upload process when 'something' goes awry.

Anyway, we are now using AVRdude directly ( only Arduino IDE to compile ), and we just don't know enough about how it works to know where to go from here. mieczotronix, were you saying that it's avrdude that attempts to reset the arduino? How does it do that? It's not as simple as a pin change, but the arduino does not have software reset capabilities, right? I think we must just be doing a hard reset at the exact time at which avrdude is attempting it's reset.

Like I said, I just wanted to jump into the conversation. I have had a lot of experience with the xbee, so please feel free to ask me any questions about what we've gotten to work. I don't have the most technical background, so my knowledge is piecemeal. Please bear with me.

Thanks much.

Cheers.

boulderbill
 
Posts: 14
Joined: Thu Jan 08, 2009 12:25 pm

Re: xbee for arduino wireless programming

by boulderbill on Thu Jan 08, 2009 12:55 pm

Just one other thing to add to this that makes us question whether there's more going on than just the buffer problem is that when we run the avrdude directly from a command prompt and send our hard reset ( send an 'r' character out a separate COM port that resets the remote arduino by line passing on our programming xbee via a transistor ) we've found that the timing between those two tasks, when changed down to the microsecond, dramatically changes the percentage of the program that makes it to upload. The nice thing about using avrdude on the command line is that you can see these percentages directly and see how much of a difference your timing makes.

So, yea, this is basically where our knowledge falls apart. We don't really understand how, when not in a wireless mode, that the avrdude does it's reset. We are trying to find a way to replicate that timing with our own reset technique to at least eliminate this question before attacking the buffer issue.

Any advice?

On another note, when we have some time we'll post some detailed info on how we've successfully wirelessly programmed using the line passing technique. It is much easier to deal with than integrating Rob Faludi's method into your program, and it works enough of the time to make it useful for programming a few boards manually, even with very large programs. In the meantime, please feel free to ask any questions.

If anyone wants to take a look at what we're up to, check out: http://www.blueink.com/ThePool/2008/ThePool2008.htm


Cheers.

boulderbill
 
Posts: 14
Joined: Thu Jan 08, 2009 12:25 pm

Re: xbee for arduino wireless programming

by mieczotronix on Thu Jan 08, 2009 2:16 pm

I've been doing it the way ladyada did
according to the description here:

http://www.ladyada.net/make/xbee/arduino.html

is it the way you did it?
mieczotronix
 
Posts: 9
Joined: Wed Dec 17, 2008 9:34 pm

Please be positive and constructive with your questions and comments.