• Home
  • Raspberry Pi
  • Codesys eCockpit
  • Python
  • Docker
  • Embedded Programming
Brighter Side Tech
  • Home
  • Raspberry Pi
  • Codesys eCockpit
  • Python
  • Docker
  • Embedded Programming
No Result
View All Result
  • Home
  • Raspberry Pi
  • Codesys eCockpit
  • Python
  • Docker
  • Embedded Programming
No Result
View All Result
Brighter Side Tech
No Result
View All Result
Home Automation

Configure Raspberry Pi Serial ports as COM ports for Codesys Runtime

Mwesigwa Peter by Mwesigwa Peter
October 7, 2024
in Automation, Raspberry Pi
0
Configure Raspberry Pi Serial ports as COM ports for Codesys Runtime

Configure Raspberry Pi Serial ports as COM ports for Codesys Runtime

0
SHARES
122
VIEWS
Share on FacebookShare on Twitter

Introduction

Codesys Runtime for Linux ARM SL allows you to program your Raspberry Pi according t the IEC 61131-6 standard and use it as an Industrial Controller. The Runtime installation can be downloaded form the Codesys Store website and can be used with a trial license to test it out, so there is no need of buying a license right away

After installing Codesys Runtime for Linux Arm, you are now free to program your raspberry pi as a PLC in from the Codesys environment and even implement your desired industrial communication protocols. One of the most common industrial protocols is the Modbus RTU. This is a Serial based protocol and uses the serial interface of your device to exchange information with a remote device via a serial communication channel

For standard Industrial Controllers that come already installed with Codesys runtime, you don’t need any extra configuration to access your serial interfaces, since the particular vendor will have implemented all the necessary for this functionality. All you you to do is to connect the remote device to a physical serial port and then communication can be established via the corresponding COM port number.

However, for a generic Codesys Runtime installation such as Codesys Control Win v3 (Windows) and Codesys Control for Linux for ARM (Linux) you need to do some extra configurations to expose your Serial interfaces to Codesys. See, codesys runtime identifies serial interfaces as based on their COM port number. For windows, its a lot easier, because when you connect a device to a serial port (USB, RS232, etc) in windows, windows will assign a COM port number to that interface and using this number, you can establish serial communication to the remote device that is connected to this interface. For Linux However, its a bit different

Linux does not automatically assign a COM port numbers to its serial interfaces. therefore the user has to manually map the desired serial ports. The goal of this guide therefore is to show how to map desired serial interfaces to different COM ports, and establish Modbus RTU communication with a report device. The guide particular addresses serial communication via the GPIO serial pins

This guide uses a Raspberry PI 3B+ but the same can be applied for other models. Raspberry Pi 2/3 have two UARTs (uart1 and uart0) that are accessible via GPIO pin 14 and Tx and pin 15 as RX. By default, UART0 is reserved for the On-board Bluetooth module and the UART1 (Mini UART) reserved for Linux Console.

Hardware Configuration

The serial interface is enabled over the GPIO pin 14 and Tx and pin 15 as RX however, you cannot connect the RS232 or the RS485 connections directly to these pins because of the voltage level differences between these serial two architectures and what the raspberry pi can support. Instead, a conversation must be done to convert the voltage level of the RS232 or the RS 485 to a level the raspberry pi can handle (3.3 to 5v). To do this , a RS 232/RS485 to TTL Converter can be used. For RS232 a MAX3232 can be used for this purpose

Software Configuration

Step 1: Enable the Serial Port

The first step is to enable the serial port on your raspberry pi which will permit serial communication via either the UART0 or UART1. To do this, we run the following command in the terminal

pi@raspberrypi:~ $ sudo raspi-config

When the configuration tool opens, select option 3: Interface Options

Then select Interface option 3: Serial Port

Select No wen prompted to allow a login shell to be accessible over serial

Select Yes when prompted to enable serial port hardware

Select Finish after this configuration

Step 2: Disable Bluetooth Module connection to UART interface

As mentioned before, by default one of the UART serial interfaces is connected to the login shell by default and the other is connected to the Bluetooth Module. So it is important to disconnected the Bluetooth module form the URAT interface and free it so that it can be connected to the Hardware serial interface (Serial Ports 14 and 15). To do this, you should edit the config.txt file located in the boot folder and add the following line

pi@raspberrypi:~ $ sudo nano /boot/config.txt
dtoverlay=diasble-bt

Step 3: Identify which UART interface is connected to the Hardware serial interface

Now you need to identify with UART interface is connected to the serial Hardware Interface. The hardware serial interface is usually identified with a symbolic link Serial0 and the Bluetooth module connection interface as Serial1, if it exists. Use the following commands

pi@raspberrypi:~ $ ls /dev

pi@raspberrypi:~ $ ls -l /dev

From the above image, you can clearly see which UART interface is connected to Serial0 and Serial 1

Step 4: Map COM Port numbers to Serial Interfaces

Now that we have identified which UART interface we are interested in, we can map this Interface to a COM Port Number. To do this, we must edit the CODESYSControl_User.cfg file found in the /etc directory. Add the following code to the file

sudo nano /etc/CODESYSControl_User.cfg
[SysCom]
Linux.Devicefile.1=/dev/ttyAMA0
Linux.Devicefile.2=.dev/ttyUSB0

With the above code, we have mapped /dev/ttyAMA0 to COM Port 1 as seen on line 1. If you have multiple serial interfaces, use the same procedure, making sure that you map each Interface on a different unique COM Port number. We can also map USB serial interfaces to COM port numbers as can be seen on line 2 above

After the editing process above, your CODESYSControl_User.cfg should look like this. You can now proceed and implement Modbus RTU communication in Codesys.

Tags: Codessys Control for Linux ARM
Previous Post

ARM error: no member named ‘IP’ in ‘NVIC_Type’ Solved

Next Post

Parsing JSON Data in Codesys

Mwesigwa Peter

Mwesigwa Peter

Related Posts

Parsing JSON Data in Codesys
Automation

Parsing JSON Data in Codesys

Parsing JSON Data in Codesys is quite an important operation especially when exchanging data over the REST API. The data...

by Mwesigwa Peter
January 25, 2025
Modbus TCP Master Simulator
Automation

Modbus TCP Master Simulator Tool – Free Download

The Modbus TCP Master Simulator Tool has been implemented in using QT for python and can be used to Simulate...

by Mwesigwa Peter
October 14, 2023
Next Post
Parsing JSON Data in Codesys

Parsing JSON Data in Codesys

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Parsing JSON Data in Codesys
Automation

Parsing JSON Data in Codesys

by Mwesigwa Peter
January 25, 2025
0

Parsing JSON Data in Codesys is quite an important operation especially when exchanging data over the REST API. The data...

Read moreDetails
Configure Raspberry Pi Serial ports as COM ports for Codesys Runtime

Configure Raspberry Pi Serial ports as COM ports for Codesys Runtime

October 7, 2024
ARM error: no member named ‘IP’ in ‘NVIC_Type’ Solved

ARM error: no member named ‘IP’ in ‘NVIC_Type’ Solved

July 18, 2024
TCP Socket Client Implementation in Codesys

TCP Socket Client Implementation in Codesys

January 11, 2024
Modbus TCP Master Simulator

Modbus TCP Master Simulator Tool – Free Download

October 14, 2023
Parsing JSON Data in Codesys

Parsing JSON Data in Codesys

by Mwesigwa Peter
January 25, 2025
0

Parsing JSON Data in Codesys is quite an important operation especially when exchanging data over the REST API. The data...

Configure Raspberry Pi Serial ports as COM ports for Codesys Runtime

Configure Raspberry Pi Serial ports as COM ports for Codesys Runtime

by Mwesigwa Peter
October 7, 2024
0

Introduction Codesys Runtime for Linux ARM SL allows you to program your Raspberry Pi according t the IEC 61131-6 standard...

ARM error: no member named ‘IP’ in ‘NVIC_Type’ Solved

ARM error: no member named ‘IP’ in ‘NVIC_Type’ Solved

by Mwesigwa Peter
July 18, 2024
0

This is how to solve the error: no member named 'IP' in 'NVIC_Type' Open the misc.c file : AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\StdPeriph_Driver\src\misc.c, if you are...

TCP Socket Client Implementation in Codesys

TCP Socket Client Implementation in Codesys

by Mwesigwa Peter
January 11, 2024
0

This is a TCP socket client implementation in codesys to run on your PLC and connect to any TCP Socket...

About Brighterside Tech

Brighter Side Tech

As a hobbyist Engineer and Programmer , i love to share my learnings and solutions to technical challenges that i face during work and studying. My website gives me the ability to express my ideas and such solutions to the wider audience

Contact: admin@brightersidetech.com

Browse by Category

  • Automation
  • Codesys eCockpit
  • Docker
  • Embedded Programming
  • Python
  • Raspberry Pi
https://youtu.be/Lkrma5f60rs

Recent News

Parsing JSON Data in Codesys

Parsing JSON Data in Codesys

January 25, 2025
Configure Raspberry Pi Serial ports as COM ports for Codesys Runtime

Configure Raspberry Pi Serial ports as COM ports for Codesys Runtime

October 7, 2024
ARM error: no member named ‘IP’ in ‘NVIC_Type’ Solved

ARM error: no member named ‘IP’ in ‘NVIC_Type’ Solved

July 18, 2024
  • Home
  • Raspberry Pi
  • Codesys eCockpit
  • Python
  • Docker
  • Embedded Programming

© 2024 Brighterside Tech.

No Result
View All Result
  • Home
  • Raspberry Pi
  • Codesys eCockpit
  • Python
  • Docker
  • Embedded Programming

© 2024 Brighterside Tech.