Objective: controlling the LEDs of a RevPi base module using CODESYS. The base modules have two to five freely programmable LEDs (A1 … AX) featuring up to seven colors. The application makes these LEDs light up cyclically every second in the possible colors.
This tutorial can be applied to the base modules
An already programmed sample project is available in a GitLab repository for each basic module. If you start with the ready-to-use sample project, you can jump to Running Application.
Prerequisites #
✓ RevPi is connected to the power supply.
✓ RevPi is connected to the network.
✓ CODESYS Development System (CODESYS) is installed on your PC.
✓ CODESYS runtime is installed in the CODESYS Development System.
✓ RevPi I/O driver is installed in the CODESYS Development System.
✓ CODESYS is connected to the RevPi.
✓ CODESYS runtime is installed on the RevPi.
See documentation for Setting up the System.
1. Creating a Project in CODESYS #
▷ Open CODESYS on your PC.
▷ Create a new standard project with CODESYS Control for Linux ARM/ARM64 and the required programming language.
The sample projects use structured text.
❯ A device tree is created in the Devices window.
▷ Open the context menu on the root device in the device tree.
▷ Select Add device.
❯ A list of all RevPi devices is displayed under Miscellaneous using the manufacturer filter KUNBUS GmbH.
▷ Select the appropriate RevPi device.
▷ Select Add device.
❯ The RevPi device is added to the device tree.
See also documentation for Creating a Project Including RevPi Devices.
2. Assigning Output #
On the RevPi, the output for controlling the LEDs is labeled RevPiLED . The assignment between LED, bit and color is described in the documentation for the base modules in section RevPiLED (OUT) . See also How do you use the LEDs of the RevPi base modules?
▷ Open the RevPi device in the device tree.
▷ Enter a user-defined variable name on the Mapping tab in the Channel RevPiLED.
Example for RevPi Connect 5:
❯ A variable is assigned to the output for the LEDs, which can be called up in the program to access the output.
3. Writing the Program #
▷ Write a program in the required programming language and use the assigned variable.
In the sample project for the RevPi Connect 5, the program in Structured Text is:
TON_0(IN:= TRUE AND NOT (TON_0.Q), PT:= T#1S);
IF(TON_0.Q)THEN
uiModuloRemainder:= uiCounterTON MOD 7;
CASE uiModuloRemainder OF
0:
wRevPiLED:=4681;// Turn A1-A5 LEDs red. Binary value 001001001001001
1:
wRevPiLED:=9362;// Turn A1-A5 LEDs green. Binary value 010010010010010
2:
wRevPiLED:=18724;// Turn A1-A5 LEDs blue. Binary value 100100100100100
3:
wRevPiLED:=14043;// Turn A1-A5 LEDs orange. Binary value 011011011011011
4:
wRevPiLED:=28086;// Turn A1-A5 LEDs cyan. Binary value 110110110110110
5:
wRevPiLED:=23405;// Turn A1-A5 LEDs magenta. Binary value 101101101101101
6:
wRevPiLED:=32767;// Turn A1-A5 LEDs white. Binary value 111111111111111
ELSE
wRevPiLED:=0;
END_CASE;
uiCounterTON:= uiCounterTON+ 1;
END_IF
4. Running Application #
▷ Select Generate Code (F11) in the menu bar to translate the project.
▷ Open the root device.
▷ Select Scan Network in the Communication Settings , select the RevPi and establish the connection to the device using OK.
▷ Select Login (AltF8) in the menu bar to log in to the RevPi.
▷ When you log in for the first time, create a user by following the wizard and entering your login details.
▷ In the Device User Logon window, log in to the RevPi.
▷ The first time, confirm the download of the application to the RevPi by Yes .
▷ Select ⯈ (F5) in the menu bar to start the application.
❯ The LEDs of the RevPi light up in a different color every second.