Following these instructions, you can turn your Arduino Due into a complete IEC-61131 PLC.
Arduino Due firmware types
Please visit the "Download" page on our website:
then expand the Run-times section, here you can choose between two variants of the Arduino PLC runtime:
- Binary version: pre-compiled firmware binary, ready to download and use, but can not be customized in any way
- SDK version: version for developers, can be customized by adding functions and variables written in C language
- choose Runtime for Arduino Due (Binary version) and download it
- unpack the contents of the archive, named ArduinoDue_PLC_binary_x.y.z.zip
- connect your Arduino Due with the Programming port and verify the COM port number assigned by Windows
- execute download.bat; it will ask your COM port and will proceed with the firmware download
- reboot your Arduino Due, connecting it to the Native port and verify the COM port number assigned by Windows
- please go to "Installation and first use of LogicLab" chapter in this page, to install LogicLab and register a valid license
First of all you need Arduino Due compiler on your computer: Go to Arduino website, at the following link, and download the latest version of Arduino IDE (1.8.4 at the moment of this writing). "Windows installer" is recommended.
- Install Arduino IDE and launch it
- Go to Tools → Board: “current board name” → Boards Manager...
- Type “arduino due” in the "Filter your seach..."
- Select below "Arduino SAM Boards (32-bits ARM Cortex-M3)"
- Select compiler version 1.6.11. You can also choose a more recent version if available, in this case you will have to manually adjust the Makefile!
Now download the SDK version from Axel website:
- choose Runtime for Arduino Due (SDK version) and download it
- unpack the contents of the archive, named ArduinoDue_PLC_SDK_x.y.z.zip. You will now have a "AlPlc_ArduinoDue_Custom" folder.
- choose Runtime for Arduino Due (SDK library) and download it
- unpack the contents of the archive, named ArduinoDue_PLC_SDKLibrary_x.y.z.zip, inside the "AlPlc_ArduinoDue_Custom" folder cited above. You will now have a "AlPlc_ArduinoDue_Custom\lib" folder.
The "SDK library" contains the base LogicLab PLC Runtime (static library and headers), so everytime there’s an update you can just download the latest version of the "Runtime for Arduino Due (SDK library)" and replace the content of “lib” folder.
You can now edit the provided sources with any text editor or IDE you want, and then compile them with a simple make command in the command prompt (and use make clean to clean the previous build).
Alternatively, you can use Codelite (a free C++ IDE), for which a project is already provided; you can download it from:
Once installed, run Codelite and select “Workspace → Open workspace → AlPlc_ArduinoDue_Custom.workspace”.
Customize the firmware
By customizing the firmware you can add new datablocks and embedded functions for LogicLab and modify the firmware behavior.
This firmware version already includes TinkerKit files. TinkerKit I/O has been used as datablocks and embedded functions examples.
- To add a new datablock
A datablock is a special memory area of the PLC runtime used to "publish" a C variable to the PLC environment, using a fixed "logical address".
You can create the variable you want to publish wherever you want but we suggest you to put it in the Datablocks.cpp file, where all the datablocks are stored. You will find an array named const PLCIEC_DBREC plcDataBlocks in the UserDefinition.cpp file, to make your variable visible to LogicLab you have to add an element to that array; follow the instructions you will find there.
Then, you will need to edit your TGT file for LogicLab accordingly.
- To add a new embedded function
An embedded function is a C function that is "published" to the PLC environment.
You can create the function you want to publish wherever you want but we suggest you to put it in IEC_Embedded.cpp file, where all the IEC functions are stored. You will find an array named const PLCIEC_FCNREC plcEmbeddedFunctions in the UserDefinition.cpp file, to make your function visible to LogicLab you have to add an element to that array; follow the instructions you will find there.
Then, you will need to edit your TGT file for LogicLab accordingly.
- To modify firmware behavior
In the UserDefinition.cpp file you will find four functions named BeforePlcTaskFast(), AfterPlcTaskFast(), BeforePlcTaskBackground(), AfterPlcTaskBackground(). These functions are called before and after tasks execution; you can add your code here (see the example of ReadInputs() and WriteOutputs() which are called before and after the task fast).
In the main.cpp file you will find the “main” function, which you may use as entry point for your code. “Main” already calls two functions: AlPlcArduinoStartup() makes the basic initialization for Arduino device and it’s required by the Runtime library; you should leave this function call as the first thing done by “main” function. AlPlcMain() start the tasks execution. Do never delete those functions, or you’ll get unexpected behavior (most of all the LogicLab Runtime won’t run). You can add your code between those two functions, in order to do something before the tasks start running, and you can add your code after the AlPlcMain() in order to do something else other than the PLC programs made with LogicLab.
To download the firmware on your Arduino Due board you must use command prompt:
- Open command prompt and go to your AlPlc_ArduinoDue_Custom folder
- Connect your Arduino Due with the programming port and verify the COM port number assigned by Windows
- Edit the Makefile and put the correct COM port number
- Execute make download command, once finished reboot your Arduino Due
- Connect the board to the Native port and verify the COM port number assigned by Windows.
Now LogicLab can connect to your Arduino Due board, but you won’t be able to execute a PLC program until you register a valid license. To learn more about LogicLab and license read chapter “Installation and first use of LogicLab”
Installation and first use of LogicLab
Downloads of LogicLab Automation Suite
Go to our website www.axelsw.it, In the Downloads section expand the list Software -> LogicLab Automation Suite Download the file LogicLab Automation Suite
Install the setup
- Press New Project, select target Arduino Due 1.0, give the project a name and press the OK button.
- From the menu On-line select Setup communication.
- Select the protocol GDB, then press the Properties button.
- Change the COM port number (verify the COM port number assigned by Windows to your Arduino Due board)
- Choose Connect from the menu Online
If everything went correctly, you should see the green word Connected on the status bar in the lower right corner of LogicLab.
However if the license key has not been written yet, will be able to connect but not to download and run any PLC code
Get the free license
- Press the Read HW Key button : this will display your hardware key in the text box
- Send a mail to email@example.com with the hardware key; Axel will send you the license key back. Our policy provides a first license for free, if you need numerous license, we may request a payment.
- Enter the license key you received in the Write License text box and press the button
- Reboot your Arduino Due and connect with LogicLab again
For more information you can consult LogicLab online manual, or follow our tutorials available in the news section of the website or on YouTube by following the link below:
We ask you to contact our support team only to get the license; due to the fact that this is a free software distribution we won't provide assistance through our support system.