With all this hardware, we're going to need some software to bring it all together. Rather than start with WinAVR or Atmel Studio, I decided to use the Arduino framework, since it gives a good boost to a project with its libraries of base functions, so we can start coding our project, not a basic framework for IO. This will also help to keep the children engaged as we get things working more quickly.

The problem that we're going to have to overcome is that the Arduino framework expects a USB connection from the PC directly to the target microcontroller. This is going to be a problem, since whilst we can theoretically develop directly on the Raspberry Pi in the same box as the Arduino. However, it's not a particularly fast way to develop given he low power nature of the Pi's processor and running in a graphical mode would be slow and take more of the already precious RAM.  

Conversely running a USB cable across the house and garden is a non starter too. What we need is the IDE to be on my PC, yet for the programming to be on the Raspberry Pi. I can connect to the Pi over the wireless network from my PC via ssh. 

Unfortunately, the Arduino framework does not offer this as an option, so I need to go digging. After a while, I find how the Arduino framework works. This is all configured via the boards.txt, programmers.txt and platform.txt files in the c:\program files (x86\Arduino\Hardware\Arduino\avr Directory. Note that these files are overwritten by an Arduino upgrade, so be careful if you edit them. Better still see my final solution under the how-to's section.

The config files result in a call to AVRDUDE with some flags. AVRDUDE is the AVR download and upload utility, which can program AVR microcontrollers using many interface types. 

After a few false starts editing the files and what looks like bugs in the Arduino framework, I reach out to the Arduno developers on their Google Groups forum and on Github and get the info I need from Matthijs Kooijman (Thanks Matthijs)

So, I added some new options to the config files that allowed me to run an upload script, this script copies the resulting .hex file via WinSCP to the Arduino, it logs in using a certificate, so no credentials are in the script   Once that is done, it uses plink (which is part of Putty) to log in via a terminal session and run a script on the Pi, this script does some sanity checks and calls AVRDUDE, which actually programs the Arduino. The really great thing about this is that the progress of all of this appears in the Arduino IDE, which is really good. The whole setup process is detailed here and available from GitGub as the farduino project for Far away Arduino's.

In terms of physical connectivity between the Pi and he Arduino, my options are SPI and serial, SPI would be faster and I would prefer to keep the serial link for debugging. Serial download uses the built in Arduino bootloader that is accessible just after the microcontroller is reset. 

Unfortunately the standard version of AVRDUDE didn't support the hardware SPI interface on the raspberry Pi, however I found that a fork of the utility had been created by Kevin Cuzner and was available on GitHub. This uses the Linux SPI devices  in /dev

I found that although I could program an Arduino out of the circuit, I could not do this when it was in circuit. The reason is that it drives the reset pin at all times and I could not get it to invert the reset pin to accommodate the open collector transistor that pulls the reset pin low. This functionality was detailed in the manual and just required the ~ directive on the pin in the config file, however processing this hadn't been implemented in the code, so I modified the code to support that and it then worked as expected, so we now have hardware driven SPI programming from a Raspberry Pi. The change was duly submitted and incorporated into Kevin's fork. 

I was also able to use the USB port on the Pi to connect to the USB port on the Arduino and perform serial programming, just at a slower rate. This is the Arduino' s built-in USB to serial interface. 

So, now we can develop and debug from the comfort of the office and whilst on a proper computer and yet still program the device whilst it's in the chicken coop. I can also ssh into the Pi and run minicom to get a serial connection, which will help a lot with debugging.