Upload an sketch to a PLC using Ethernet - Step 2 - Binary File

December 24, 2018 by
Upload an sketch to a PLC using Ethernet - Step 2 - Binary File
Alejandro Jabalquinto

Introduction

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


Requirements

Ethernet or 20 I/Os PLC:      Ethernet PLC             20 I/Os PLC     

Industrial Shields boards:   Industrial Shields Boards


Description

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

 Modification of a Preference in Arduino IDE software

2. Verify your sketch on the Arduino IDE software.

 Verify the sketch on the Arduino IDE software

*Take into 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.

Where is located the .hex file

We need to situate into the last lines. After “Linking everything together… ” the next line shows this path. It is not shown 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/)

Black windows finding the path of the temporary file.

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:

Temporary folder

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

3.1 Open CMD

CMD - Upload an sketch to a PLC using Ethernet

This is a terminal to insert commands that 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. 

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 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:
 .bin file - Upload an sketch to a PLC using Ethernet
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:

 temporary folder - Upload an sketch to a PLC using Ethernet

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 there we will need to use the following command to implement the binary compilation of the .hex file.

command to implement the binary compilation of the .hex file.

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


And here is the result:

Result - Upload an sketch to a PLC using Ethernet

 Now it appears the .bin file.
 
Then .bin file is created. This file will be directly uploaded to the PLC using 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 post, don't miss it!

 
 

​Search in our Blog

Upload an sketch to a PLC using Ethernet - Step 2 - Binary File
Alejandro Jabalquinto December 24, 2018
Share this post

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>>