This is the circuit that will handel the programming of the Arduino Duemilanove. Funny enough, its based on an Arduino microcontroller itself. I attached a picture of the schematic in case you cannot open the eagle file.
A background on the circuit:
The most unique thing about this circuit is probably the fact that it uses an interrupt on digital pin 2 that is connected to the RX pin of the destination Arduino (the Arduino that is destined to be programmed). This is to detect the first low bit of serial data, which will be the IDE trying to reset the arduino for a sketch upload. However, the IDE cannot reset the destination Arduino directly, but that is why I included the intermediary Arduino (The Arduino that will reset the destination Arduino). Once a interrupt is triggered a timer, really a delay function, will start that triggers a low to high pulse on D8. In turn, D8 is connected to the destination Arduino's reset line and will cause it to reset.
I found a good time to delay was almost 500ms, or 499500us to be exact. I arrived at this by monitioring the serial communcation and reset line of an Arduino that was connected VIA USB to my laptop while I uploaded a program to it, and trial and error. I posted a picture of the results into this step, it's the one with the Matlab program operating as an oscilloscope. This may be one point of improvement, because according to the picture I can shorten the delay to 100ms or 250ms from the first serial reset command. I stuck with 499500us because it worked and a half a second shorter upload was not worth another hour of debugging to me. You can see that 499500us is not a very genral number to arrive to. I had to try 490ms, 495ms, 499ms, 500ms, 501ms, 505ms, ... before I arrived to 499500us.
In order to keep the interrupt from reseting the destination Arduino on every recieved serial tranmission while uploading I included a timeout of 60s. Which seems to be how long it would take to upload even a ~30kb program; the maximum size possible. However the time to upload a 1,100 byte program is about 5s so I included another interrupt that will stop the timeout if a high voltage is detected on the A0 pin of the destination Arduino. Therefore, if you include a few lines of code that pulse a high level on the A0 pin in the setup() routine of your destination Arduino you will significantly shorten the time between uploads for your small sketches. I programmed a blue LED to light on when the timeout is active. Indicating that you are uploading, and nothing else can be transmitted at the time.
One last note for this step. I highly recommend putting this circuit on a shield, and using the female headers to mount the XBee. This will not only make your circuit much sturdier, a work of art, not permanently comission an XBee, but also speed up your prototyping as well; which is probably what your doing when your uploading code often enough to benift from doing it wirelessly. If you're not ready not solder, though, or dont belive me lol, you can always breadboard the ciruit and use it like that. Which is what I did when I was prototyping this circuit.
For some reason I cannot attach my code here, do you know why? I've tried Chrome and Explorer. So I pasted it below.
This sketch is meant to be mounted on a Arduino(I used a UNO 5v) that is going to be used
to reset a Arduino Duemilanove that is meant to wirelessly programmed. It has one
interrupt on pin 2(tied to RX on destination Arduino to know when a upload
is attempted and therefore reset the destination Arduino at the approriate time.
Another interrupt exists on pin 3(tied to A0 on destination Arduino) that is used
as a signaling pin by the programmed Arduino to tell this Arduino that the
programming process has concluded. An example of such a signaling routine is shown
below. For best practice, include it as the first line in your setup() routine of your
However this is not necessary, because this program includes a 60s timeout after
which you can again program this chip. The afore mentioned code simply stops the
timeout, allowing you to upload code immeadelty after your previous upload. In any
case you cannot upload until the blue LED on D4 turns off.
volatile boolean startup=false;
volatile boolean done=false;
static byte resetpin=8;
static byte blueledpin=4;
attachInterrupt(0, resetter, LOW); //this pin is attached to the RX line of the other Arduino
attachInterrupt(1, stopignore, HIGH); //this pin is attached to A0 of the other Arduino
detachInterrupt(1); //However this interrupt is only necessary when the first one has triggered
detachInterrupt(0); //so we do not reset again in the middle of the upload
delayMicroseconds(499500); //499500us worked well
digitalWrite(resetpin,HIGH); //bring high to stop reseting the Arduino
//maybe insert a small delay here
attachInterrupt(1, stopignore, HIGH);
for(unsigned int i=0; i<60000; i=i+50) //delay a total of 60s unless "done" is true
if(done) //then stop timeout because upload has finished
//reset for the next code upload
attachInterrupt(0, resetter, LOW);
void resetter() //triggered only at the start of an upload. E.G. first low byte of an upload