V2.0.0.1 library info
Implemented as CODESYS 3 IO device-driver;
100% Open source,
100% Pure IEC 61131-3 code (ST),
No function block calls in your software necessary, just write code, attach variable to an I/O channel, ready!
Breaks compatibility with earlier FB version but improves highly on ease of use,
4 Di,
4 Do,
2 Ai,
2 Ao,
Hardware Watchdog,
Control Byte (experimental).
Stable, but work in progress ...
Missing in action
At this moment all functionality is implemented into the core of the driver (as FB), but not yet routed to the user as parameters;
Not yet routed to parameters are;
RS485 configuration,
DO channels PWM configuration,
DI channels Counter configuration,
1-Wire bus.
Previous versions info
https://github.com/Aliazzzz/Monarco-HAT-library-for-CODESYS-V3/blob/master/VERSIONS.md
The main software components
.package file (CODESYS package installer) which installs the necessary files in a user friendly manner;
Hardware device description file,
Software library file,
Example project file,
A copy of the "unlicense" agreement...
Hardware prerequisitories
A Raspberry Pi, see https://www.raspberrypi.org/
A Monarco HAT, see https://www.monarco.io/
8 GB SD Card ...
Software prerequisitories
CODESYS V3 IDE available at https://store.codesys.com/codesys.html,
CODESYS Raspberry Pi .package available at https://store.codesys.com/codesys-control-for-raspberry-pi-sl.html,
Codesys Raspberry Pi SL Demo or License (The Demo is unrestricted in technical capabilities but will only run for two hours straight, after which it stops and you have to set it in run again yourself by logging in)
Latest Monarco IO Hat library for CODESYS package avilable at https://github.com/Aliazzzz/Monarco-HAT-library-for-CODESYS-V3/tree/master/Monarco/2.0.0.1/package
Hardware installation
Attach Monarco HAT to Raspberry Pi and power it up;
sudo cat /proc/device-tree/hat/vendor
should return "REX Controls".
sudo cat /proc/device-tree/hat/product
should return "Monarco HAT".
Disable system console on UART
sudo sed 's/ console=serial0,[0-9]+//' -i /boot/cmdline.txt
sudo reboot
Install essential tools
sudo apt update
sudo apt install git
Flash Monarco HAT EEPROM (to avoid manual installation of overlay)
sudo git clone https://github.com/monarco/monarco-hat-firmware-bin
cd monarco-hat-firmware-bin
./monarco-eeprom.sh update
Install CODESYS runtime component on pi (Demo or licensed)
Follow Codesys online help steps, its easy!
https://help.codesys.com/webapp/_rbp_install_runtime;product=CODESYS_Control_for_Raspberry_Pi_SL;version=3.5.12.0
Monarco codesys package installation
Either install the Monarco codesys package via; Double-click the package or via CODESYS IDE Package Manager or Install the loose components via the Library / Device Repository, found under Tools menu option in CODESYS IDE.
Attach CODESYS to the RS485 UART
Switch to etc direcory and edit the CODESYSControl.cfg;
cd etc/
sudo nano CODESYSControl.cfg
Add the following lines;
[SysCom] Linux.Devicefile=/dev/ttyAMA
Now save and Quit nano.
Enable NTP sync
Now manually configure and enable NTP service;
sudo nano etc/ntp.config
Add server pool.ntp.org (other server entries can be commented out)
Uncomment line restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap (you may need to change IP to your network base)
Now save and Quit nano again. Now you can enable NTP service;
sudo systemctl enable ntpd.service
And then start it;
sudo systemctl start ntpd.service
And check configuration;
sudo ntpq -p
Now you can use the HAT, RS-485 and the Real-Time Clock from within a CODESYS IEC application. Access the RS485 UART via a comlib of you own flavour in CODESYS (like CAA SerialCOM library).
Run CODESYS Project
Open the provided example project file.
Check/Set SPI master parameters:
Mode 0,
SPI bits 8,
Speed(Hz) 1000000 (=1MHz) => can be set up to 4 MHz, slower speeds avoid chance on crc errors
Compile, download and run => enjoy!