Hello,
I have an issue where I want to detect the rising edges from a YF-S201. Since RPI5 different GPIO pin out, I needed to use gpiozero and it's DigitalInputDevice.when_activated within the PSM. Yet the interrupt for increasing the frequency is never being called. I have tested a non-PSM python script and was able to read and interrupt correctly, while using the same gpiozero.
Similarly, I wonder if I need to modify any firmware or anything to achieve saving the value. Or just simply have the interrupt work..
Sorry, I very new to OpenPLC and trying to learn Python.
Thanks!!!
#import all your libraries here
import psm
import time
from gpiozero import DigitalInputDevice
#GPIO pin connected to flow sensor (YF-S201) and use pull-down resister
GPIO_flow_sensor = DigitalInputDevice(4, pull_up= False)
#Freqeuncy of pulse from flow sensor
frequency = 0
total_time = 0
#Handle when flow sensor detects rising edge
def handle_flow_interrupt(channel):
print("rising")
global frequency
frequency += 1
GPIO_flow_sensor.when_activated = handle_flow_interrupt
def update_flow():
#Divide frequency by 7.5 is roughly flow rate
flow = frequency/7.5
print(f"Flow Rate: {flow} L/Min")
psm.set_var("ID0", flow)
def hardware_init():
#Insert your hardware initialization code in here
psm.start()
def update_inputs():
#place here your code to update inputs
update_flow()
def update_outputs():
#place here your code to work on outputs
pass
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()