uploading new sketch to arduino via imp

edited July 2013 in IDE & Tools
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 :)
  • yummy :)
  • 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.
  • edited July 2013
    hey generjones, great news

    regarding the wiring needed for this
    i understand its a uart pair (rx/tx) and a reset pin.
    anything more?

  • @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.

  • Can you show us your code?
  • Not really, it's for a commercial application :(
  • 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?

  • 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.


  • Awesome Aron, thank you!!
  • edited February 2014
    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?
  • edited May 2014
    I don't know if he answered you @aron, but I'm trying to use the same code and getting the same error. As a absolute newbie, I think I picked a project with a pretty steep learning curve and I don't know which direction to look.
  • Same for me here :(
  • Hi @Johnygab / @Hugo - you could try my Imp based programmer that uses in-system programming (rather than requiring a bootloader) and will work with Arduino boards like the UNO, i.e. the ATmega328, or pretty much any other popular AVR MCU.

    I posted about this a few days ago but doesn't seem to have elicited too much notice :( Hope it's of some use to you and others looking to program AVRs / Arduinos via the Imp.


    I produced a huge writeup about it here:


    Have fun and tell me how it goes :)

  • Hey guys, I just created a pull request on this amazing work that programs the Arduino. I have added Dropbox support using the dropins API so that you can utilize Dropbox for getting your Hex file. It is pretty slick as I added support to "remember" the last links using HTML5 storage and you can keep clicking "Upload" after the Dropbox sync has pulled your hex files over from your PC. Pretty slick!

    If Sparkfun accepts the pull request, then you can have it too:

    Here is my pull request:

    1700 x 2200 - 195K
    1700 x 2200 - 131K
  • Got it working!

    this work very well : https://learn.sparkfun.com/tutorials/wireless-arduino-programming-with-electric-imp

    BUT !!! your Atmega328p must have the Uno boot loader, otherwise its now waiting long enough in the Bl section and the imp is not able to get a reply.

Sign In or Register to comment.