Getting Started with Raspberry Pi: A Beginner’s Guide

Getting Started with Raspberry Pi: A Beginner's Guide

What is Raspberry Pi? How to learn CODESYS programming? Suddenly, many industrial control friends are interested in learning. Indeed, our masters are sharing on the forum, and it has been updated to the ninth article. (Click below [Read Original] to see all)

Today, I selected the fourth, fifth, and sixth sections shared by user FreeTigerMan in the PLC forum to show everyone. I suggest beginners interested in this topic go to the forum and start reading from the beginning. Of course, I encourage everyone to share more for the benefit of peers, learning from each other and progressing together!

During the pandemic, feeling bored at home, I bought a Raspberry Pi to tinker with and pass the time. Unexpectedly, there have been many high-quality technical posts on the forum discussing Raspberry Pi and its applications in automation. I also want to join in the fun and share my experiences in purchasing, using, and tinkering with it for everyone’s reference to avoid detours.

After installing the Codesys runtime, you can start programming. If you encounter connection or running issues, and if you are familiar with Linux commands, you can connect to the Raspberry Pi via ssh to check the service status. The normal result should be: sudo systemctl status codesyscontrol.service

Getting Started with Raspberry Pi: A Beginner's Guide

In this state, create a new project in Codesys, select Raspberry Pi MC or SL (multi-core and single-core versions), and when connecting to the network, scan the network to find the device:

Getting Started with Raspberry Pi: A Beginner's Guide

Sometimes you can’t find it by scanning, so you can directly fill in the IP address to connect:

Getting Started with Raspberry Pi: A Beginner's Guide

Then you can happily start programming!

You can compare the original version of Codesys and the SoMachine software from Schneider, which adds FDT/DTM and various device support, and believe you will have a better understanding of PLC programming.

Next time, we will discuss the IO interfaces and buses supported by Raspberry Pi and its connectivity with Schneider devices.

Continuing from the previous post, after installing the Codesys runtime on Raspberry Pi and connecting normally, the Raspberry Pi becomes a controller with certain functionalities. We can see that Codesys supports various interfaces of Raspberry Pi:

Getting Started with Raspberry Pi: A Beginner's Guide

Many interfaces that come with Raspberry Pi are not commonly used in the industrial control field. Here’s a brief introduction: Raspberry Pi has a camera interface that many use for machine vision applications. CodeSys also displays this Camera device. I don’t have a camera, so I can’t test if it can easily achieve some image recognition tasks that our PLCs cannot do. Students with conditions can continue to explore. Raspberry Pi also has a display interface that can connect to a touchscreen, conveniently transformed into a retro gaming machine. This is also for interested students to study, and you are welcome to post and showcase your results. The most useful for control is probably the GPIO interface, shown in the diagram below, which also marks the serial port (UART) pins:

Getting Started with Raspberry Pi: A Beginner's Guide

The GPIO is powerful and supports many functions beyond general IO: I2C interface is a simple, bidirectional two-wire synchronous serial bus developed by Philips. It only requires two wires to transmit information between devices connected to the bus. Raspberry Pi can control multiple sensors and components via the I2C interface. Their communication is completed through SDA (data pin) and SCL (clock speed pin). Each slave device has a unique address, allowing for rapid communication among many devices. The ID_EEPROM pin is also part of the I2C protocol, used for communication with HATs. The SPI interface is used to control components with a master-slave relationship, operating in a master-in-slave-out and master-out-slave-in manner. The Raspberry Pi’s SPI consists of SCLK, MOSI, and MISO interfaces, where SCLK controls data speed, MOSI sends data from Raspberry Pi to connected devices, and MISO does the opposite. The UART interface (the RXD, TXD, GND in the diagram, which is RS232) is well-known among Arduino users. UART or Serial is a universal asynchronous receiver/transmitter interface used to connect Arduino to the computer it is programmed on and for communication between other devices and the RX and TX pins. If the Raspberry Pi has the serial terminal enabled in raspi-config, these pins can be used to control the Raspberry Pi via a computer, and can also be directly used to control Arduino. PWM interfaces can achieve software PWM on all Raspberry Pi pins, while GPIO12, GPIO13, GPIO18, and GPIO19 can achieve hardware pulse-width modulation. GPIO (General Purpose I/O Ports) means general input/output ports. In simple terms, they are pins that can output high or low levels or read the status of the pins—high or low. GPIO is a relatively important concept, allowing users to interact with hardware (such as UART), control hardware operations (like LEDs, buzzers, etc.), and read hardware working status signals (like interrupt signals). The use of GPIO pins is very widespread. Mastering GPIO is almost equivalent to mastering the ability to operate hardware. Raspberry Pi has 26 GPIO pins, some of which are multiplexed interfaces. 1. Pins 3 and 5 are I2C multiplexed interfaces. 2. Pin 7 is a (GCLK) global clock pin multiplexed interface. 3. Pins 19, 21, and 23 are SPI multiplexed interfaces. 4. Pins 8 and 10 are serial multiplexed interfaces, TX for sending, RX for receiving. 5. Pins 12, 32, 33, and 35 are PWM multiplexed interfaces. By configuration, these 26 IOs can be used as both DI and DO. Codesys has utilized the multiplexed pins according to their functional interfaces in the drivers, so in GPIOs_A_B, it supports GPIO0~31 in software, leaving only the remaining non-multiplexed pins for IO points based on needs.

Getting Started with Raspberry Pi: A Beginner's Guide

To truly use these IOs to control devices, level conversion and increased load capacity are generally required, unless it’s something small like an LED that can be driven directly. Those interested in understanding this can create their own PLC, which requires knowledge of digital and analog electronic circuits. Students who have not yet returned these to the teacher are welcome to join. Of course, there are ready-made relay boards available on Taobao, which can be connected with Dupont wires to immediately drive small motors.

Having introduced the various interfaces supported by Raspberry Pi, let’s continue discussing its applications in industrial control. According to official materials, Raspberry Pi supports the following interfaces (some repetition with the previous post, but here it is more accurate):

1. CODESYS OPC UA Server, as a full version for data exchange. OPC UA will surely be widely used in the future, breaking the limitations of win DCOM. 2. CANopen via EL6751 Gateway/CanOpen, which requires a gateway. 3. Raspberry Pi Camera/supports camera functions, taking photos, capturing images, and displaying pictures are all fine; image recognition may need to be developed independently. 4. I2C interface, with SenseHat, SRF02, Adafruit PWM, MPU6050 Gyro, MPU9150 Gyro, AK8975 Compass/IIC master station, can connect to those foreign devices, which seem to be available on Taobao as well. 5. SPI interface, with MCP3008, MCP23S17, PiFace Digital, PiFace Control Display/SPI interface supports the listed devices. 6. One-wire interface, with DS20B18/1-wire, supports some devices. 7. GPIO/As mentioned earlier, supports direct configuration of IO input and output.

Supported Fieldbus by software

1. CODESYS CANopen Manager / Device requires gateway support. 2. CODESYS EtherCAT Master/directly supports using the integrated network port, and also supports USB expansion network cards, only supports master station. 3. CODESYS EtherNet/IP Scanner / Adapter / directly supports using the integrated network port, see the post by W. 4. CODESYS J1939 / not used, welcome to advise. 5. CODESYS Modbus TCP Master / Slave / Schneider’s basic protocol, can be directly implemented with the integrated network port, very convenient, supports master and slave. 6. CODESYS Modbus Serial Master / Slave / Schneider’s basic protocol, supports USB serial ports. Whether GPIO’s UART is supported hasn’t found detailed steps yet; theoretically, it can be because Codesys says the serial port driver is provided by the operating system, meaning as long as Raspbian can recognize it, it can work; practically, buying a USB serial (like PL2303) is easier than converting GPIO’s UART. However, from the perspective of resource utilization, using GPIO is better. 7. CODESYS PROFINET Controller / Device / Siemens’ Ethernet protocol, only supports master station. 8. CODESYS SoftMotion, CNC / supports motion control. 9. Network protocol BACnet/supports BACnet, commonly used in building control buses.

These bus supports, along with the built-in web visualization to create simple browser-based human-machine interfaces (HMI), can meet many industrial control requirements. Moreover, due to the open nature of Codesys, it also supports self-developed drivers. However, Raspberry Pi and Codesys Raspberry Pi Runtime are primarily aimed at education and testing. The real-time performance of Codesys Runtime still relies on the Raspberry Pi operating system. Although Raspbian supports real-time control mechanisms, to truly use it in industrial sites, a lot of work and testing is still required. As a learning tool, it is quite good. We can connect Raspberry Pi to any devices we can find for IO and create an operational interface using web visualization, which can be accessed via a computer or mobile browser.

Getting Started with Raspberry Pi: A Beginner's Guide

If you create an internal network penetration on the router, it can easily achieve “cloud control”, which is excellent… Try selecting some typical configurations from the supported devices above, and it compiles easily. Although hardware needs to be debugged one by one, through these settings, you can gain a better understanding of the configurations and working principles of these devices.

Getting Started with Raspberry Pi: A Beginner's Guide

Access from the browser or mobile:

http://192.168.1.44:8080/webvisu.htm for convenient operation:

Getting Started with Raspberry Pi: A Beginner's Guide

Having discussed the panoramic view of Raspberry Pi Codesys functionality, some detailed configurations of protocols were not elaborated. Interested students can also go to the forum for communication.

Source/China Industrial Control Network, please contact for reprints

Recommended Articles

[Original Share] Industrial Control People Talk About Home Intelligent Control, Not Using PLC and It’s Very Simple?
Edge Computing and Artificial Intelligence, Siemens Strengthens Future Layout in Factory Automation Business
[Original Share] Practical Dual Motor Drive Master-Slave Control with Inverter

[Original Share] A Tough Experience in Debugging Packaging Equipment

Increased Compensation Capacitors, Why Did Power Consumption Increase?
Make Good Use of EXCEL, Efficient PLC Programming, What Do You Think?
[Original Share] Equipment Transformation Case: Communication between S7-200 PLC and Yokogawa DCS System
[Original Share] Connection and Simulation of M200 PLC and Kunlun Tongtai Touch Screen
[Original Share] Using PLC to Eliminate Safety Production Hazards of Gas Pressure Turbine Power Generation Device
[Original Share] Mitsubishi Q Series and FX2N Series Communication via CC-Link (Communication between Master Station and Intelligent Device Station)
[Original Share] Efficient Design of Siemens PLC Circuit 2 – Quickly Perform PLC Address Encoding and Schematic Establishment
[Original Share] Efficient Design of Siemens PLC Circuit – Based on EPLAN and TIA Selection
[Original Share] Mitsubishi FX5U Series PLC and Siemens MM420 Series Inverter Achieving USS Protocol Serial Communication
[Original Share] Discussing the Difficult Development Path of Domestic Pressure Sensors
Electric Motors, Magnetic Fields, AC and DC Circuits, Electrical Calculation Formulas, Essential for Electricians!
[Original Collection] Growth Path of Industrial Control Technology Experts, All Have Had These Moments!
How Much Do You Know About Electrical Grounding?
[Original Share] Interpreting the Classic PID Controller from a New Perspective
[Share] Schneider LMC 058 Motion Control Electronic Cam
After 15 Years in Inverters, Explaining the Output Short Circuit Protection Function of Inverters
[Original Share] Is PLC Ladder Diagram Programming Low? Then You Must Check Out the Origin of PLC Ladder Diagrams
[Original Share] How to Establish OPC Communication between WINCC7.3 and 1200?

I know you are “watching”~

Leave a Comment

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