Pages

Friday 13 April 2018

Arduino OTA - Ethernet

                               

1.    Overview

The goal of this project is to provide over-the-air (OTA) upload of Arduino sketches to a remote Arduino. This is accomplished by programming the remote Arduino using Ethernet enabled arduino.
Ariadne Bootloader implements a TFTP server on the Arduino board to allow uploading sketches to boards with a W5100 Ethernet controller attached using any TFTP client. This bootloader also supports the standard serial upload method.

2.    Requirements

2.1.        Hardware:

§  Arduino Uno
§  Ethernet Shield
§  Ethernet Cable

2.2.        Software:

§  Arduino IDE.
§  SinProg for uploading bootloader.
§  Ariadne Bootloader(or arduino-tftpboot bootloader).

3.    Procedure Summary

1.       Install the arduino-tftpboot bootloader platform package and libraries.

2.       Burn the TFTP-compatible bootloader to your Arduino.
3.       Setup the configuration for your network.
4.       Verify the network configuration.
5.       Upload your sketch.
6.       Modify your sketch to be remote-reset compatible (optional).
 

4.    Install the arduino-tftpboot bootloader platform package.

First up you need to install the "platform package" that contains the bootloader you will burn to your Arduino to make it TFTP-compatible. This also contains a library with some tools and helpful examples you can use later on.
1.      Exit the Arduino application if it is running. If you don't do this the IDE won't recognise the new board package.
2.      Download the arduino-tftpboot package from https://github.com/freetronics/arduino-tftpboot/downloads.

Unzip the package file. You should see the following files and folders

1.      Copy the boards.txt data of arduino-tftpboot found at arduino-tftpboot-beta-003\package\ hardware\arduino-tftpbootand paste the same at the end of the boards.txt file found at C:\Program Files\Arduino\hardware\arduino\avr.
2.      Start the Arduino IDE application.
3. Verify you have the platform package correctly installed by looking for a new board named TFTP Bootloader ATmega328 (No Upload) available under the Tools > Board menu:

If you see the new board listed then you're ready to move on to the next step.
Now you have the platform package installed you can burn the arduino-tftpbootbootloader onto your Arduino board. Learn how to do this in next section.

1.     Burn the bootloader

Once you have installed the TFTP-capable bootloader platform package in previous section you can burn the bootloader onto your Arduino board:
Method One:
  1. Open boards.txt file and move to end i.e to tftp bootloader.
  2. Note down values assigned for low_fuses, high_fuses, extended_fuses, lock_bits and unlock_bits.
 

3     3 Connect your UNO to Programmer.
4.      Open SinProg.exe application for uploading bootloader file.
5.      Select the board ATmega328 and click on search.
6.      Enter fuse values which you noted down previously and click write.
7.      If fuse writes OK, then browse for bootloader hex file and click verify. It takes lot of time so be patient.
8.      Once verifies OK, click write. It takes lot of time so be patient.
Method two:
  1. Select the appropriate option from the Tools > Board menu:
    • For an EtherTen, Arduino Ethernet, Arduino Uno with Ethernet shield or other ATmega328 based board, choose: TFTP Bootloader ATmega328 (No Upload).
  2. Connect your ISP programmer from your computer to the ISCP header pins on your Arduino or Arduino-compatible board.
  3. In the Tools > Programmer menu select the name of your programmer. e.g. USBtinyISP or Arduino as ISP.
Select the Tools > Burn Bootloader menu option. This will burn the arduino-tftpboot bootloader to your board. It can take around a minute for this to complete:

  • You can confirm the bootloader has been burned successfully by connecting an LED and resistor between ground and pin 9 on your Arduino.
  • Immediately after the bootloader has been burned it will blink the LED at a rate of about once per second until you upload a sketch via TFTP. Once a sketch has been uploaded the LED will only blink for about three seconds after a reset/power-on (indicating the bootloader is waiting for a TFTP connection) before it stops and the uploaded sketch is executed

6.    Configure your network

The default configuration

By default the arduino-tftpboot bootloader uses the following network configuration:
·         IP address: 192.168.1.1
·         Net mask: 255.255.255.0
·         MAC address: 12:34:45:78:9A:BC
·         Gateway address: 192.168.1.254

Storing your network settings

The arduino-tftpboot bootloader has the ability to read network settings from EEPROM and use those settings rather than its defaults. First, though, you need a sketch to store the network settings in EEPROM. But once you have installed the bootloader you can't upload a sketch to it unless it has the correct settings! It ends up being a bit of a chicken-egg situation.
There is an additional complication due to the fact the default Arduino bootloader configures the Arduino so the EEPROM is erased when a bootloader or sketch is uploaded via an ISP programmer. This means the settings in EEPROM will not be preserved if we write network settings to EEPROM from a sketch before we install the new bootloader.
The solution (if you can't use the default bootloader network settings) is to:
1.Burn the arduino-tftpboot bootloader (as you did in Step Two).
2.      Write the network settings to EEPROM with the WriteNetworkSettings sketch (which you're about to do).
3.      Burn the arduino-tftpboot bootloader (again).
The way this works is that the first time you burn the bootloader it also configures your Arduino to preserve the contents of the EEPROM whenever you next burn a bootloader or sketch. But when you upload the network settings sketch via the programmer it also overwrites the bootloader. So, then you have to burn the bootloader again but this time it will preserve and use the settings in EEPROM. (Yes, it's frustrating repetition but it seems there is no easier way.)
Here's how to write the network settings:
1.      Open the File > Examples > ArduinoFTP > WriteNetworkSettings sketch.
2.      Modify the gateway/netmask/IP/MAC details in the NetworkSettings section of the file, as required, using the values you chose in the "Choosing a static IP address" section of this step. (The comments at the head of the file provide two other settings variations you can use via copy & paste.)
3.      Upload the sketch via your ISP programmer.
4.      Let the sketch run once. When the sketch has finished an LED attached to Pin 9 will blink rapidly.
5.      (Optional) If you have a serial connection to your Arduino board you can check that the EEPROM has the correct values by uploading the eeprom_read sketch via your ISP programmer (File > Examples > EEPROM > eeprom_read) and verifying the values it prints to the serial monitor. The output should look something like this:
    0   85
    1   170
    2   255
    3   10
    4   1
    5   1
    6   1
    7   255
    8   0
    9   0
    10  0
    11  18
    12  52
    13  69
    14  120
    15  154
    16  188
    17  10
    18  1
    19  1
    20  20
Now that you have the network settings stored you need to go back and repeat Step Two to burn the arduino-tftpboot bootloader back onto your Arduino.
Do that now.
Once the arduino-tftpboot bootloader is installed on your Arduino again you will need to verify your Arduino's network settings and then you can upload a sketch over the network. You'll learn how to do this in steps four and five, which are coming up right about....now.

1.    Verify the network connection

1.  Open cmd in your PC and type ping 192.168.1.1
(If you have used the WriteNetworkSettings to change the IP address of the Arduino you should use that address instead.)
You should see a response like:
    PING 192.168.1.1 (192.168.1.1): 56 data bytes
    64 bytes from 192.168.1.1: icmp_seq=0 ttl=128 time=0.180 ms
    64 bytes from 192.168.1.1: icmp_seq=1 ttl=128 time=0.126 ms
    64 bytes from 192.168.1.1: icmp_seq=2 ttl=128 time=0.191 ms

Now move onto to the next step and finally upload a sketch over the network!

2.    Upload your sketch

Convert your elf file to bin file.

Enable verbose compilation output

While the Arduino IDE will compile our sketch for us as normal, we need to know where the IDE puts the compiled file. To do this we need to enable "verbose compilation output":
1.      Open the Arduino Preferences dialog. (Arduino 1.0 or later.)
2.      Ensure the compilation option is selected for Show verbose output during:


3.      Click OK.
You only need to set this once.

Compile a sketch

1.      Ensure the correct board is selected (as you did previously in Step Two):
    • For an EtherTen, Arduino Ethernet, Arduino Uno with Ethernet shield or other ATmega328 based board, choose: TFTP Bootloader ATmega328 (No Upload).
2.      If you have connected an LED an resistor to pin 9 you can open the File > Examples > ArduinoTFTP > BlinkUploadTest sketch. (Otherwise you'll need to choose a different sketch with which to test.)
3.      Click the Verify button, choose the Sketch > Verify / Compile menu option or use the associated keyboard shortcut.
Wait until the compile completes with a message like this:

5.      Note the text on the third to last line (highlighted in the screenshot above) of the output that ends with BlinkUploadTest.cpp.elf. Copy this line of text (you can select it in the output and copy as normal) to a temporary location. This line of text is the file path of the compiled version of your sketch.
(Ensure you don't copy the line that ends with .hex. Also, depending on the width of your editor window the file path may not be on a line on its own--yeah, helpful I know. You'll find it.)

 

Convert sketch for bootloader

Due to the way the bootloader works we need to convert from the compiled file format the Arduino IDE produces to a format the bootloader can understand.
The conversion uses the avr-objcopy tool from the avr-gcc package--this is distributed with the Arduino IDE on Windows & Mac OS X but needs to be installed separately on Linux distributions. avr-gcc may also be installed separately on Windows or Mac OS X but in most cases it's best to use the version that ships with the IDE.
1.      Goto C:\Program Files\Arduino\hardware\tools\avr\bin file and start a cmd Terminal from there.
2.      Type avr-objcopy -j .text -j .data -O binary C:\Users\Admin\AppData\Local\Temp\arduino_build_718552\BlinkUploadTest.cpp.elf C:\Users\Admin\AppData\Local\Temp\arduino_build_718552\BlinkUploadTest.bin

Upload the sketch

tftp program is installed by default on Windows XP. Later versions may require you to enable the tool first.
  1. Open a console command line window from bin file path.
  2. Perform the upload by typing:
3.      tftp -i <Arduino IP address> put <filename>.bin
e.g. if your Arduino has the default 192.168.1.1 address, use:
    tftp -i 192.168.1.1 put BlinkUploadTest.bin
The -i switch indicates you want to send the file in binary form.
.

Test a sketch that uses the network

1.      Open the File > Examples > ArduinoTFTP > WebServerWithSettings sketch.
2.      Compile & upload the sketch--ensure the MAC address in the sketch is the same as used by the bootloader.
3.      In a web browser visit the IP address of your Arduino. The standard demonstration page should appear.

No comments:

Post a Comment