Since I have some experience in programming PLC-s,the idea came to me to use XIAO as Programmable Logic Controller.
To setup this project, there are several software packages you need to install in order to make firmware for XIAO:
- Beremiz4Pico Manager (https://github.com/bbouchez/Beremiz4Pico)
- Beremiz PLCopen editor (https://beremiz.org/get)
- Arduino IDE (https://www.arduino.cc/en/software)
Beremiz4Pico is a fork of PLCopen editor, an Open Source IEC61131-3 Programmable Logic Controller software that supports programming in Ladder Diagram, Function Block Diagram, Structured Text, Instruction List and Sequential Function Block.
Although Beremiz4PicoManager is made for the Raspberry Pi Pico, XIAO RP2040 from SeedStudio uses the same architecture/CPU as the XIAO RP2040, means they are compatible and the code generating procedure is the same.
First install and setup Arduino IDE for XIAO RP2040, as explained in tutorial below: https://wiki.seeedstudio.com/XIAO-RP2040-with-Arduino/
Step 1. Launch the Arduino application.
Step 2. Add Seeed Studio XIAO RP2040 to your Arduino IDE
Navigate to File > Preference, and fill "Additional Boards Manager URLs" with the url below:
https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
Navigate to Tools-> Board-> Boards Manager..., type the keyword "XIAO" in the searching blank. Select the lastest version of "Seeed XIAO RP2040" and install it.
That's it, the Arduino IDE has been installed and configured for Seed XIAO RP2040.
Next, go to github url:: https://github.com/bbouchez/Beremiz4Pico , go to releases, download Beremiz4PicoManager and source file. Extract those to your folder (Name it Beremiz4Pico), so that the folder structure looks like this:
After that, run Beremiz4PicoManager.exe.
At first run, you will get a message:
That means you must set tools path. From the file menu, go to Set tools path, and navigate and select Beremiz4Pico folder, where Beremiz4PicoManager.exe is and its belonging files.
Our first example program will be LED blinking program.
1. Create a new project from the file menu.
2. Under the Pin section, scroll down to GP25 (LED), double click to Not used under Function column. Select the Digital Output.
3. Note that now under PLC name there is name for the pin %Q0.25, which is automatically named and it is IEC61131-3 naming format.
We selected the pin GP25, because the LED on XIAO 2040 is connected to that pin. You can verify that from schematic documentation available on SeedStudio website.
The settings above are show in the image below:
Now everything is ready to program our XIAO using Ladder diagram. Prom Project menu, go to Open Beremiz for Pico Editor:
Click the big plus sign under Project tab, and select program.
Create a new POU window opens up, select LD for Language and click OK:
To create a new variable for LED click on the + symbol below:
New variable with LocalVar0 name will be added, change Name to LED, Type to BOOL, and Location to our earlier configured GP25 PLC name %Q0.25.
Now we can create our Ladder program which will look like this:
We have added two times: TON0 and TOF0, which are ON and OFF timers for turning the LED ON and OFF with intervals of one second (one second LED is ON, one second if OFF, which is defined by variable T#1s).
Double click on Resource1 and click on + symbol inside instance windows and configire settings like below:
Now all is good and ready to save project. After saving click on Build icon:
If everything is okay, you will see a message C code generated successfully:
Now, last step: go to Beremiz for Pico manager and select Generate target files. This generates all files ready for Arduino IDE to build program and upload it to your XIAO. The filed are under your project folder you created for Beremiz4Pico, and the folder name is Project_arduino.
Open Project_arduino.ino file with Arduino IDE and compile and upload sketch program to your XIAO with selected SEED XIAO RP2040 board:
Congragulations, XIAO onboard LED will start flashing.
This example is simple, you can do a lot of other cool projects as you would with ordinary PLC:
- Line following robot,
- PLCbased automatic bottle filling system
- PLC Based Automatic garage Door Opening System
- Temperature control in industrial environment
- PLC Based Automatic Coffee Vending Machine
The posibillities for projects are endless...
Comments