Arduino Due: Difference between revisions

From Axel Public Wiki
Jump to navigation Jump to search
Line 54: Line 54:
* '''To add a new datablock'''
* '''To add a new datablock'''
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.
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.


* '''To add a new embedded function'''
* '''To add a new embedded function'''
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.
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.


* '''To modify firmware behavior'''
* '''To modify firmware behavior'''

Revision as of 10:54, 22 September 2017

Following these instructions, you can turn your Arduino Due into a complete IEC-61131 PLC.

Download and flash firmware (binary version)

  • Download the firmware with our PLC runtime from our site at (section Run-times):
http://www.axelsw.it/index.php?option=com_content&view=article&id=143&Itemid=1806
  • unpack the contents of the archive
  • 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

Customizable firmware version

Downloads

First of all you need ArduinoDue compiler on your computer:

  • Go to Arduino website, at the following link, and download the latest version of Arduino IDE
https://www.arduino.cc
  • Install Arduino IDE and launch it
  • Go to Tools → Board: “Current board name” → Click on Boards Manager
  • Chose Type “Arduino” from the drop down menù
  • Select Arduino SAM Boards (32-bits ARM Cortex-M3)
  • Version 1.6.11
  • Install


Now download the customizable firmware version from Axel website:

  • Go to the following link
???? LINK NOT AVAILABLE ????
  • Download the custom archive (???) and unzip it; you will find a folder named “lib”
  • From the same link above download the library archive (???) and unzip it in the “lib” folder

The library archive (???) contains the LogicLab Runtime, so everytime there’s an update you can just download the latest version of the library archive (???) and replace the content of “lib” folder.


A Codelite project as already been created in order to edit and compile these files, if you want to use it you need to download Codelite software at the following link

 https://codelite.org/

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

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.

  • To add a new embedded function

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.

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

Flash firmware

As said in the previous chapter, the custom version provide a Codelite project ( AlPlc_ArduinoDue_Custom.workspace), you can use this project to build your code; else you can open your command prompt, drive to the custom folder (where the makefile is) and invoke make clean command and then make command.

To download the firmware on your Arduino Due board you must use command prompt:

  • Open command prompt and drive to the custom folder (where the makefile is).
  • Connect your Arduino Due with the programming port and verify the COM port number assigned by Windows (should be COM 13, if not modify it)
  • 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 (it should be COM 11, if not modify it).

Now LogicLab can connect to your Arduino Due board, but you won’t be able to download a 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

Launch LogicLab

  • 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)
  • 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 support@axelsw.it with the hardware key; Axel will send you the license key back
  • 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

More informations

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:

https://www.youtube.com/user/Axelsrl