UPLOADING A SKETCH TO A PLC USING ETHERNET. STEP 2. BINARY FILE

UPLOADING A SKETCH TO A PLC USING ETHERNET. STEP 2. BINARY FILE

In this post we will see how to take the binary file from an sketch.ino

First of all we need to know the differences between uploading a code via USB  and uploading via Ethernet. When a code is uploaded into an Arduino board using the USB, Arduino IDE software automatically does its magic and transforms the code sketch.ino into a file.hex which is the one that gets uploaded automatically. If we want to upload a code via Ethernet we need to do it manually. To start with, we do not upload a .hex file as in the USB, now it is a .bin file so the first part is getting this binary file.

It is a different process to get the binary file using Windows than using Linux, so this post will be separated into this 2 parts.

1. Common Part. Modification of a Preference in Arduino IDE software.

On Arduino IDE software go to File -> Preferences. tick in the Show verbose output during: Compilation *optional: Upload (not necessary).

 

2. Verify your sketch on the Arduino IDE software.

 

*Take in consideration by the time you want to upload a code using Ethernet it has to be done a Reset to the PLC, if the PLC hasn’t been configured to automatically resets, it will have to be manually (pressing phisically the button of reset). Here it is let the post which explains the code you need to add in order to remote reset

HOW TO RESET A PLC USING THE ETHERNET SHIELD

3. Windows 

In order to create the binary file we need to know where is located the .hex file. This file is created in a temporary folder. By the time a code is verified having this Compilation tick (in Preferences) we will be able to see the path.

We need to situate into the last lines. After “Linking everything together… ” the next line shows this path. It is not showed in the first photo as it is too large for represented in one photo. In this following photo I have just moved to the right the black windows finding the path of the temporary file. (TIP: search for /Temp/)

          By default it should be saved in the temporary folder of the Windows system of your user.

          If you go to that directory you will find something like this in the temporary folder:

          As you can see I have found my .hex file created after verifying my sketch. 

3.1 Open CMD

This is a terminal to insert commands that the Windows understands, we will use this terminal to send a command that will execute an Arduino IDE tool that will convert the .hex into the .bin. 

          If you know how CMD works you need to go to the directory of the .ino.hex file which is the one we have seen from before. This is made using the command cd “$path” as it is shown in the photo.
Once we get into the correct directory we need to use this command to use the Arduino IDE Tool that transforms the .hex into .bin. The path on the first path can be slightly different depending on the language and the architecture of your computer (32bits computers have \Program Files (x86)\)
 
C:\Program Files\Arduino\hardware\tools\avr\bin\avr-objcopy.exe" -I ihex [sketchname].ino.hex -O binary [sketchname].ino.bin
 
Here is the result:
 
Now it appears the .bin file
 
 
Linux
 
In order to create the binary file we need to know where is located the .hex file. This file is created in a temporary folder. By the time a code is verified having this Compilation tick we will be able to see the path.

We need to situate into the last lines. After “Linking everything together… ” the next line shows this path.  (TIP: search for /Tmp/)

 

          By default it should be saved in the temporary folder of the Linux System.

          If you go to that directory you will find something like this in the temporary folder:

          As you can see I have found my .hex file created after verifying my sketch. 

Once we have reached this part we need to convert the .hex file into a .bin file using the tool of Arduino IDE avr-objcopy. To implement this part we need to open a terminal and go to the directory where it is the .hex file using the command cd “path”. Once we have arrived to there we will need to use the following command to implement the binary compilation of the .hex file.

avr-objcopy -I ihex [sketch].hex -O binary [sketch].bin

Here is the result:

 Now it appears the .bin file
 
Now it is been created the .bin file. This file will be directly uploaded to the PLC using the Ethernet. To send this file it is needed to use a server that can communicate to the Arduino. In this case it will be used the tftp Client. This will be shown in the 3rd part of this posts.
 
 
Comments are closed.