Hi everyone,
I've set a system with a raspberry zero hosting openplc and a program.
I used PSM coding to get the value of a temperature sensor (DS18B20) and to get my input and outputs GPIO.
It is working at first but after a while (average of 2 hours) i'm facing the following issue :
1) Temperature is still read by PSM.
2) GPIO inputs and outputs are not working anymore.
3) Modbus communication is working fine.
To get it work again for a few hours, i have to stop the program and run it.
When I start the program I get a message that PSM connection failed at first, and when i start it a second time connection is ok but doesn't last.
Here is my hardware code.
Maybe is something wrong in it but I don't know.
#import all your libraries here
import psm
import time
from w1thermsensor import W1ThermSensor
import RPi.GPIO as GPIO
#global variables
sensor = None
i_Pin=[2,3,4,17,27,22,10,9]
q_Pin=[14,15,23,24,25,8,7,12]
def hardware_init():
#Insert your hardware initialization code in here
global sensor
psm.start()
sensor = W1ThermSensor()
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
# Pin Configuration
for i in range(0,7):
GPIO.setup(i_Pin[i], GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(q_Pin[i], GPIO.OUT)
def update_inputs():
#place here your code to update inputs
global sensor
temperature = sensor.get_temperature()
temp_int = int(temperature)
psm.set_var("IW10", temp_int)
#Read inputs
for i in range(0,7):
i_Str = 'IX0.'+str(i)
i_State = int(GPIO.input(i_Pin[i]))
print (i_Str,i_State)
psm.set_var(i_Str, i_State)
def update_outputs():
#place here your code to work on outputs
for i in range(0,7):
q_Str = 'QX0.'+str(i)
a = psm.get_var(q_Str)
print(q_Str,a)
if a == True:
GPIO.output(q_Pin[i], GPIO.HIGH)
else:
GPIO.output(q_Pin[i], GPIO.LOW)
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()
Is there a way the see the logs of PSM part?
Thanks for your help