owlaf2173
Hi,  I'm new to using a Pi with a PLC CPU, but not new to PLCs.  I have a Pi 5, went through the installation steps on the openplc website.  I also install wiringpi from github.  I wired up the pi using the simple example on the openplc site to see a basic working version.  I have the program uploaded, the pi hardware selected, and the program running.  
 
Everything seems to install fine, but the output doesn't come on.  The inputs don't change.  I feel like I am missing a simple beginners step.
Reply 0 0
owlaf2173
The dashboard logs
 
OpenPLC Runtime starting...
Interactive Server: Listening on port 43628
Skipping configuration of Slave Devices (mbconfig.cfg file not found)
Warning: Persistent Storage file not found
Issued start_modbus() command to start on port: 502
Server: Listening on port 502
Server: waiting for new client...
Issued start_dnp3() command to start on port: 20000
DNP3 ID manager: Starting thread (0)
DNP3 ID DNP3_Server: Listening on: 0.0.0.0:20000
Issued start_enip() command to start on port: 44818
Server: Listening on port 44818
Server: waiting for new client...
Issued stop_pstorage() command
Server: Client accepted! Creating thread for the new client ID: 9...
Server: waiting for new client...
Server: Thread created for client ID: 9
Modbus Server: client ID: 9 has closed the connection
Terminating Modbus connections thread
Server: Client accepted! Creating thread for the new client ID: 9...
Server: waiting for new client...
Server: Thread created for client ID: 9
Server: Client accepted! Creating thread for the new client ID: 11...
Server: waiting for new client...
Server: Thread created for client ID: 11
 
Reply 0 0
thiagoralves
The easiest way to check is by uploading the Blink example and then check on the Monitoring page in the webserver if the output is being triggered. Then connect an LED to the pin and check if it blinks as well
Reply 1 0
owlaf2173
The easiest way to check is by uploading the Blink example and then check on the Monitoring page in the webserver if the output is being triggered. Then connect an LED to the pin and check if it blinks as well
The monitor page shows no change
Reply 0 0
thiagoralves
Then most likely the PLC is not running or your program was not compiled correctly. Can you send a screenshot of your monitoring page?
Reply 0 0
owlaf2173
Something was wrong with the first blink.  Started from new and now it works as in the monitor page shows the output changing.  I got to go home for the night here in the Hoosier state.  I will try adding an LED tomorrow.  Could it have been that the previous programs were a continuous changing project, that I kept creating new st files?  I get open source can be on the bleeding edge
 
Thanks for help
Reply 0 0
thiagoralves
Hard to say without seeing your actual project. Most likely there was some error on your project and it did not get compiled. When that happens, OpenPLC reverts to the previously working project. You must pay attention to the compilation logs to ensure that the project got compiled. 
Reply 0 0
owlaf2173
Hard to say without seeing your actual project. Most likely there was some error on your project and it did not get compiled. When that happens, OpenPLC reverts to the previously working project. You must pay attention to the compilation logs to ensure that the project got compiled. 
I have not done a side by side comparison to verify if I made a mistake, but I have success installing on a pi 4.  I don't know if I made a mistake on a pi 5.  Been busy, will compare later and make sure.  I do appreciate the help
Reply 0 0
richw
Wiringpi does not work on the pi5 because of new hardware changes. Doing a search for "rpi5 and gpio" will explain why and give you other libraries to use.
Reply 0 0
owlaf2173
Wiringpi does not work on the pi5 because of new hardware changes. Doing a search for "rpi5 and gpio" will explain why and give you other libraries to use.
Thanks
Reply 0 0
Gustavo Ortiz
Hello everyone,
 
I have the same problem with my Raspberry Pi 5: I installed the OpenPLC_v3 on the RPi 5 and the OpenPLC Editor on my Mac. I was able to configure the "Blink1" example changing the pin 16 (%QX0.2) and it looks like its working on simulation and on the RPi 5 runtime web page, but the physical output is not being activated. Any suggestion to fix this issue? attached the log file and the screenshot of the program in the OpenPLC Editor.
 
Regards,
Reply 0 0
DJKalian
Hello everyone,
 
I have the same problem with my Raspberry Pi 5: I installed the OpenPLC_v3 on the RPi 5 and the OpenPLC Editor on my Mac. I was able to configure the "Blink1" example changing the pin 16 (%QX0.2) and it looks like its working on simulation and on the RPi 5 runtime web page, but the physical output is not being activated. Any suggestion to fix this issue? attached the log file and the screenshot of the program in the OpenPLC Editor.
 
Regards,
Raspberry Pi 5 uses a different GPIO interface setup than Pi 4 and previous. WiringPi no longer works on Pi 5. I was able to get things working, by uninstalling WiringPi and using the gpiozero library, which comes preinstalled on Raspberry Pi OS Bookworm. Then, I enabled PSM on Linux and wrote the IO using the gpiozero library. Works great. I have a Pi5, Pi3 and a PiZero2 all talking to each other successfully over ModBus TCP with IO on the master triggering IO on each of the slaves and vice  versa, and my modified files, the exact same code on all 3 devices. When I set up a new device now I just copy over these main.py and raspberrypi.cpp files and everything works.
 
Possibly in the future Thiago may update the OpenPLC driver for this but at the moment I think it would break backwards compatibility for older Pi's. Personally having to adapt the PSM to use the new gpiozero library is a good exercise for writing custom drivers and I have already learned so much from having to do this. 
 
Thanks again Thiago for an amazing product.
 
Kris
Reply 1 0
thiagoralves
Hey @DJKalian could you post your PSM solution here so others can benefit? Indeed the Pi5 has a different GPIO structure. I couldn’t find any C library that works with it
Reply 1 0
Gustavo Ortiz
Raspberry Pi 5 uses a different GPIO interface setup than Pi 4 and previous. WiringPi no longer works on Pi 5. I was able to get things working, by uninstalling WiringPi and using the gpiozero library, which comes preinstalled on Raspberry Pi OS Bookworm. Then, I enabled PSM on Linux and wrote the IO using the gpiozero library. Works great. I have a Pi5, Pi3 and a PiZero2 all talking to each other successfully over ModBus TCP with IO on the master triggering IO on each of the slaves and vice  versa, and my modified files, the exact same code on all 3 devices. When I set up a new device now I just copy over these main.py and raspberrypi.cpp files and everything works.
 
Possibly in the future Thiago may update the OpenPLC driver for this but at the moment I think it would break backwards compatibility for older Pi's. Personally having to adapt the PSM to use the new gpiozero library is a good exercise for writing custom drivers and I have already learned so much from having to do this. 
 
Thanks again Thiago for an amazing product.
 
Kris
Thank you for your answer Kris,
 
as Thiago wrote, would be posible to get more detail instructions and code on how to make these changes in my RPI5 in order to get OpenPLC working?
 
I apologize if this seems like too much to ask but I would really like to work with OpenPLC in my RPI5.
 
Regards,
Reply 0 0
DJKalian
Hey @DJKalian could you post your PSM solution here so others can benefit? Indeed the Pi5 has a different GPIO structure. I couldn’t find any C library that works with it
No problem, I am just very inexperienced with forums posting, code and such. I will try to post my modified file.
 
Below is my PSM code. I use gpiozero to read and write to GPIO pins, and I used the psm.get_var and psm.set_var to update the IO variables.  I think that any other working GPIO library can also be used in this way, I only used what came with Bookworm for simplicity.
 
It should be noted that I have modified my raspberrypi.cpp file to exclude some of the GPIO pins from being used as IO pins in OpenPLC. The reason for this is because eventually I would still like to use the I2C, SPI and UART interfaces to communicate with different external sensors that I am working on. For testing, I am only using 8 input and 8 output pins as physical IO. Some companies sell small 8 channel GPIO expander boards that can be used with I2C and SPI so I would like to make this a modular expansion system. That is why you see in my PSM code that I only use a limited number of GPIO.
 
I am only learning Python at the moment, so my code is very simple. I have not yet come to the point where I can write clean loops for updating the IO, such as what is in your original hardware drivers. I look forward to any improvements that can be suggested. This is an entirely self learning project for me.
 
Also, this is the file I copy to all of my different Pi architectures and so far they all run. I am working on adding and testing more architectures as well.
 
#                  - OpenPLC Python SubModule (PSM) -
# 
# PSM is the bridge connecting OpenPLC core to Python programs. PSM allows
# you to directly interface OpenPLC IO using Python and even write drivers 
# for expansion boards using just regular Python.
#
# PSM API is quite simple and just has a few functions. When writing your
# own programs, avoid touching on the "__main__" function as this regulates
# how PSM works on the PLC cycle. You can write your own hardware initialization
# code on hardware_init(), and your IO handling code on update_inputs() and
# update_outputs()
#
# To manipulate IOs, just use PSM calls psm.get_var([location name]) to read
# an OpenPLC location and psm.set_var([location name], [value]) to write to
# an OpenPLC location. For example:
#     psm.get_var("QX0.0")
# will read the value of %QX0.0. Also:
#     psm.set_var("IX0.0", True)
# will set %IX0.0 to true.
#
# Below you will find a simple example that uses PSM to switch OpenPLC's
# first digital input (%IX0.0) every second. Also, if the first digital
# output (%QX0.0) is true, PSM will display "QX0.0 is true" on OpenPLC's
# dashboard. Feel free to reuse this skeleton to write whatever you want.

#import all your libraries here
import psm
import time
from gpiozero import LED, Button

#global variables
input_IX0_0 = Button("GPIO17",pull_up=False)
input_IX0_1 = Button("GPIO27",pull_up=False)
input_IX0_2 = Button("GPIO22",pull_up=False)
input_IX0_3 = Button("GPIO5",pull_up=False)
input_IX0_4 = Button("GPIO6",pull_up=False)
input_IX0_5 = Button("GPIO13",pull_up=False)
input_IX0_6 = Button("GPIO19",pull_up=False)
input_IX0_7 = Button("GPIO26",pull_up=False)

output_QX0_0 = LED("GPIO23")
output_QX0_1 = LED("GPIO24")
output_QX0_2 = LED("GPIO25")
output_QX0_3 = LED("GPIO12")
output_QX0_4 = LED("GPIO16")
output_QX0_5 = LED("GPIO20")
output_QX0_6 = LED("GPIO21")

def hardware_init():
    #Insert your hardware initialization code in here
    psm.start()

def update_inputs():
    #place here your code to update inputs
    if input_IX0_0.is_pressed:
        psm.set_var("IX0.0", True)
    else:
        psm.set_var("IX0.0", False)
    
    if input_IX0_1.is_pressed:
        psm.set_var("IX0.1", True)
    else:
        psm.set_var("IX0.1", False)

    if input_IX0_2.is_pressed:
        psm.set_var("IX0.2", True)
    else:
        psm.set_var("IX0.2", False)

    if input_IX0_3.is_pressed:
        psm.set_var("IX0.3", True)
    else:
        psm.set_var("IX0.3", False)
    
    if input_IX0_4.is_pressed:
        psm.set_var("IX0.4", True)
    else:
        psm.set_var("IX0.4", False)

    if input_IX0_5.is_pressed:
        psm.set_var("IX0.5", True)
    else:
        psm.set_var("IX0.5", False)

    if input_IX0_6.is_pressed:
        psm.set_var("IX0.6", True)
    else:
        psm.set_var("IX0.6", False)
    
    if input_IX0_7.is_pressed:
        psm.set_var("IX0.7", True)
    else:
        psm.set_var("IX0.7", False)

def update_outputs():
    #place here your code to work on outputs
    a = psm.get_var("QX0.0")
    if a == True:
        output_QX0_0.on()
    else:
        output_QX0_0.off()

    a = psm.get_var("QX0.1")
    if a == True:
        output_QX0_1.on()
    else:
        output_QX0_1.off()

    a = psm.get_var("QX0.2")
    if a == True:
        output_QX0_2.on()
    else:
        output_QX0_2.off()

    a = psm.get_var("QX0.3")
    if a == True:
        output_QX0_3.on()
    else:
        output_QX0_3.off()

    a = psm.get_var("QX0.4")
    if a == True:
        output_QX0_4.on()
    else:
        output_QX0_4.off()

    a = psm.get_var("QX0.5")
    if a == True:
        output_QX0_5.on()
    else:
        output_QX0_5.off()

    a = psm.get_var("QX0.6")
    if a == True:
        output_QX0_6.on()
    else:
        output_QX0_6.off()

if __name__ == "__main__":
    hardware_init()
    while (not psm.should_quit()):
        update_inputs()
        update_outputs()
        time.sleep(0.1) #You can adjust the psm cycle time here
    psm.stop()
 
Reply 0 0
Reply