ESP8266 > AVR ISP sketch upload over WiFi

Yes, this is an interesting project. I have an “old” EmonTx board in the basement and doing firmware updates proved to be an hassle… unscrewing, screwing, etc…:slight_smile:

I decided to buy a few Wemos mini boards. These are quite compact and include the programmer. You need a special driver for Windows. Then, I made a quick project consisting of monitoring my gas consumption. I upload the data on emoncms.org through my second router located nearby. So far, so good.

In this thread, Glyn mentionned ESP8266AVRISP sketch. I had a look. In short, I did not manage to upload any sketch via Wifi to my “end destination” !
Did you manage to?

What I have done:
Upgrade Arduino IDE to 1.6.10. Avrdude doesn’t work with 1.6.9 in Windows for this specific task.

My schema: Wemos board is connected to an Arduino UNO via the SPI pins. There is a level translator (14050) on MISO pin because Wemos is 3.3 V.
Once wemos is loaded with the Arduino_Wifi_AVRISP sketch, it is ready to accept data:
I am getting this:

Arduino AVR-ISP over TCP
IP address: 192.168.0.19
Use your avrdude:
avrdude -c arduino -p <device> -P net:192.168.0.19:328 -t # or -U ...

My avrdude command: (I put avrdude.conf and the hex file in the same folder)

avrdude -v -C avrdude.conf -c arduino -p atmega328 -P net:192.168.0.19:328 -U flash:w:Blink.cpp.hex:i

By the way, it’s the first time I use avrdude on the CLI. I am getting all kind of information but nothing is really positive…

avrdude: Version 6.3, compiled on Jun 22 2016 at 16:05:21
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "avrdude.conf"

         Using Port                    : net:192.168.0.19:328
         Using Programmer              : arduino
avrdude: ser_drain(): read error: ParamÞtre incorrect.

avrdude: ser_drain(): read error: ParamÞtre incorrect.

avrdude: ser_drain(): read error: ParamÞtre incorrect.

         AVR Part                      : ATmega328
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino

avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x14

avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x10
         Hardware Version: 4728160
         Firmware Version: 0.2
         Topcard         : STK502
         Vtarget         : 1.8 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: stk500_initialize(): (b) protocol error, expect=0x10, resp=0x01
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x10

avrdude done.  Thank you.

Am I missing something?

Thanks for your help.

Walter

1 Like

Haven’t tested this yet, but it should work since its an official Arduino library. This library is for avr upload via ISP rather than serial. Do you have esp connected to avr ISP header?

Right, it should work.
Yep, I have connected as follow:
ESP is the master (ESP on the left here below)

MISO (GPIO12) ← MISO (through a level converter)
CLK (GPIO14) → CLK (direct connection)
MOSI (GPIO13) → MOSI (direct connection)
RST (GPIO5) → RST (throught an NPN open collector)
5V → 5V
GND → GND

These are the 6 connections.

Small update:

I need to check if SS has to be connected …

Walter

Walt,

If the Vcc connections are both active, they should not be connected.
Ref: avr - Programming ATMega16L over ISP interface - Electrical Engineering Stack Exchange

I am keen to integrate ESP8266AVRISP uploading into EmonESP. Please let me know if you manage to get it to work, if you are still having issues you should open an issue on the Arduino ESP Github. Thanks a lot for you help, much appreciated.

Hi Bill

Thanks for the info.
I did not make that mistake! However, it’s good you mentioned it here in case someone else wants to try that.

Edit: And I guess, SS is not needed. It’s not even available on this 6 pin socket.

Walt :slight_smile:

Hello Glyn

No prob!

I own an emonTx V3.4: I would like to try with a module running at 3.3 V so that I can get rid of the level translator.
There is an ISP connector on that board.
Can I use the SPI interface on the emonTX?

Thanks

Walter

Why is a level translator needed? Both the emonTx and esp both run at 3.3v.

What are you connecting to spi on the emonTx? The rfm69cw module on the emontx is currently connected to spi, it is possible to have more then one device on the same spi but might require some tweaking of cs /ss signals.

I am currently testing with a Wemos board (3.3V) and an Arduino Uno. That’s why I need a level translator.

In the next step, I would like to connect the Wemos to the emonTx.
What do you mean by tweaking?

Ah right ok. Did you mean ISP rather then spi? You should just be able to connect stright to the emonTx ISP header to upload.

I have opened an issue at WIFI + AVRISP + avrdude: can't upload hex file · Issue #2406 · esp8266/Arduino · GitHub

Walter

1 Like

The ISP is SPI. You just need to make sure all devices on the bus are inactive (their /CS externally pulled high) while you’re trying to program the AVR via the ICSP header. That’s true regardless of what you’re using as a programmer. Remember this thread: RFM69CW ISP Upload Problem - Reset timming | Archived Forum

It probably also means you want to make sure all those esp8266 output pins used during the programming, are changed to pulled-up inputs after the programming is completed, otherwise they’ll interfere with the AVR’s ability to talk to SPI peripherals once running.

Very true, I am aware of that. Sorry for the confusion I thought @daturach was asking about connecting another peripheral to the SPI

I hope you don’t mind, I have split the discussion on ESP > AVR upload into this seperate topic to allow general ESP firmware dev discussion to continue on the other thread:

Hello Glyn

Just fine. Great move

Arduino team just reverted back their avrdude.exe to an older version. There are a few regressions issues.
https://www.arduino.cc/en/Main/ReleaseNotes

This old version doesn’t work on Windows 7 (does not support parameter like net:192.168.0.19:328 )

Walter

1 Like

Ah OK, so windows is to blame! So if you used avrdude on Linux the ESP avr ISP upload should work? Have you got a spare raspberrypi you could use to run avrdude on? Or run a Linux VM.

Another option could be to use the avrdude bundled as part of platformio.