Project Overview

Monarco (1)
Project Members:

Monarco Hat v1.0.0.0 Package &
Monarco Hat Realtime Clock SRAM Support Package

Download Monarco Package v1.0.0.0

Download Buffered SRAM Package

The Monarco HAT

The Monarco HAT is a robust industrial graded HAT, perfectly suited for IOT projects, small home-automation or industrial projects and much more ...
It also protects your Raspberry Pi from overvoltage or short-circuiting and simultaneously provides you with enough IO channels and channel configuration versatility.
It features analog and digital inputs and outputs, RS-485, 1-Wire bus and a Real Time Clock.

The Monarco Hat driver is v1.0.0.0 implemented as an FB device-driver. You can program your code in any language you desire, either visual or textual.

  • 100% Open source,
  • 100% Pure IEC 61131-3 code (ST)


v1.0.0.0 Released
FB based driver including demo project
Retain data support via RTC (separate Buffered SRAM Package)

  <Id>FFFF 0005</Id>

Hardware prerequisitories

  1. A Raspberry Pi, see
  2. A Monarco HAT, see
  3. At least an 8 GB SD Card ...

Hardware installation and setup

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

cd monarco-hat-firmware-bin
./ update

Software prerequisitories

  1. CODESYS V3 IDE available at,
  2. CODESYS Raspberry Pi .package available at,
  3. 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)
  4. Contents of SVN directory : SVN

Codesys Runtime installation

Installing CODESYS runtime component on pi (Demo or licensed), just follow CODESYS online help steps, it's easy!;product=CODESYS_Control_for_Raspberry_Pi_SL;version=

Or check this youtube video:
[[embed url=]]

Package installation

Monarco Hat v1.0.0.0 Package &
Monarco Hat Realtime Clock SRAM Support Package

Download Monarco Package v1.0.0.0

Download Support Package

Monarco UART configuration

Enable CODESYS to use the RS485 UART on the Monarco Hat.

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.

Now, do a forced NTP sync

sudo timedatectl

This will force to sync time with some time server and returns something like, depending on date/time and your time-zone;

 Local time: zo 2018-09-23 14:46:17 CEST
 Universal time: zo 2018-09-23 12:46:17 UTC
 RTC time: zo 2018-09-23 12:46:18
 Time zone: Europe/Amsterdam (CEST, +0200)
 Network time on: yes
 NTP synchronized: yes
 RTC in local TZ: no

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

Running the 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 and enjoy!

Limitations / Bugs

All functionality of the HAT is implemented into the core of the driver. However I have no illusion that this driver will still contain bugs.
Due to limited time resources, I am not able to solve every bug anymore, sorry...
As this opensource software you are cordially invited to fix the bug and share your solution via a ticket.

v2.0.0.x Experimental and under construction, NOT RECOMMENDED unless you like to tinker
IO based driver
devdescr.xml: vendor id set to 0004, device id set to 0005, see for details.

      <Id>0004 0005</Id>
  • Ctrl Byte,
  • HWConfig,
  • UserLeds,
  • UserLedMask
  • Retain data support via RTC (separate Buffered SRAM Package)

For the package and the source of v2, see the SVN repo under tags


v1 Realised in 2017.
Special thanks goes out to Ingo Hornberger for helping out with difficulties and for his patience.

Monarco Hat Package &
Monarco Hat Realtime Clock SRAM Support Package

Download Monarco Package v1.0.0.0

Download Buffered SRAM Package