Uploading new sketch to arduino via imp

first off, as i’m sure someone thought of this, and as i couldn’t find a discussion going, please fwd me there.
anyway, title says it all. is it possible? and if so… how?

It’s totally possible, I know a customer doing this… but can’t share any code I’m afraid. You can totally reset the arduino and talk to its bootloader though :slight_smile:

yummy :slight_smile:

some more info:
http://forums.electricimp.com/discussion/comment/4996#Comment_4996

Yeah, I was working on this, and I thought got it almost working, then had some other issues in life pop up.

I’m going to open up the code I had, hopefully someone can complete it.

hey generjones, great news

regarding the wiring needed for this
i understand its a uart pair (rx/tx) and a reset pin.
anything more?
http://ame2.asu.edu/staff/kidane/ArdWilessBtProg.pdf

@yair, yes, that’s right.

Of course, most Arduino’s are 5V, so a logic level converter is also needed.

Half-way, yes. You need to clamp the arduino output at 3.3v (resistor & zener diode) but the imp’s 3.3v output is above the Vih(min) of the ATMEGA, which is 3.0v, so you don’t need conversion on the TX (from imp) path.

What would the imp code for doing this look like?

Probably it would:

  • Reset the arduino, and interrupt the boot process to enter the bootloader
  • Send bootloader commands to erase the target areas
  • Fetch chunks of data from the agent, and program them by sending them over serial to the arduino a chunk at a time
  • Reset the arduino when done so it runs the code

I’ve not looked for the arduino bootloader protocol, but I think it’s pretty simple.

You can either use the FTDI header and twiddle the reset line then squirt the firmware into the AVR using the serial port, or pull reset low for the duration and use the SPI port. SPI is quite a bit quicker and has the advantage of not needing the Arduino bootloader present on the AVR (meaning you gain some flash space and can therefore have a bigger sketch). I’ve implemented both methods using the Imp, and both work fine. SPI is a little more fiddly to get going because it’s harder to reverse engineer what the AVR ISP programmer is doing as the verbose output in the Arduino IDE is the communication between the IDE and the USB programmer (rather than the SPI wire level transmission). However, there are some useful documents http://www.atmel.com/images/doc0943.pdf and http://pdf1.alldatasheet.com/datasheet-pdf/view/313208/ATMEL/ATmega644PA.html that detail the programming protocol.

Toby

Can you show us your code?

Not really, it’s for a commercial application :frowning:

My half-arsed, still in progress, code is at https://github.com/genejones/avr-rascal

It doesn’t quite work yet, but might offer an idea of how to go about it…

I based my work heavily off Kevin Oshburn’s documenation of the Arduino Bootloader process, as well as the AVRDude source files.

I want to reiterate what TheBarrelShifter said about SPI/Serial options for programming.

SPI has the main advantage of being platform agnostic - any AVR can be programmed with it. It’s documented in some AVR tech specs.

I chose not to use SPI, and rather program over serial with the Arduino bootloader. It’s an easier hardware setup, and easier to code for as well. The speed issue is mostly inconsequential - the Uno bootloader runs at 115200 baud, with a maximum flash space of 32Kb (1Kb of which is bootloader) and some overhead, programming should take less than 3 seconds in most cases. This is, in my view, fast enough.

If you have the Sparkfun Electric Imp Shield, one needs merely solder the serial jumpers, then convert a single pin’s output to 5V for the reset control.

generjones, that`s really neat!

any updates on this?

did you got it working?

thanks

Hi guys,

Just thought I would chime in here quickly. If it is useful I can go into more detail.
We build an Imp-Arduino board here with hardware.uart57 connected to the serial pins (digital 0 and 1) and hardware.pin1 connected to the reset pin (all via a logic level converter from 3V3 to 5V). We are using an Arduino with a basic boot loader preloaded.

I then worked out the basic structure of the Intel HEX files and the bootloader’s protocol and wrote some Squirrel to load the HEX file onto the Arduino via a HTML form in the agent.

It isn’t designed to be robust rather just a proof of concept that works for me. You guys are welcome to extend it and make it work for you.

Let me know if this helps.
https://github.com/electricimp/reference/tree/master/hardware/impeeduino

 A.

Awesome Aron, thank you!!

aron first thanks a lot for sharing your work.

Im trying to implement impeeduino code in mine, but I have the imp connected to the avr through UART_1289. So i tryed to configure for that.
Also I deleted some Led parts as they use pins that are in use by above Uart.

help is much aprecciated.

here is the server.log:

[Status] Device booting; 13.88% program storage used 2014-02-10 18:45:13 UTC+2: [Device] Read cycle took 1856 us 2014-02-10 18:45:13 UTC+2: [Device] Device started, impee_id xxxx and mac = xxxx 2014-02-10 18:45:13 UTC+2: [Device] Bouncing the Arduino reset pin 2014-02-10 18:45:14 UTC+2: [Device] ERROR: assertion failed 2014-02-10 18:45:14 UTC+2: [Device] ERROR: at execute:247 2014-02-10 18:45:14 UTC+2: [Device] ERROR: from check_duino:265 2014-02-10 18:45:14 UTC+2: [Device] ERROR: from unknown:307 2014-02-10 18:45:19 UTC+2: [Status] Device disconnected; 213 bytes sent, 0 received, 213 total

Here is Agent, Device and Arduino Code.



thanks for the space and help

Hi luizhavoc, I just noticed this hasn’t been answered. Are you still stuck?