| 
 | 
 
 This post was finally edited by OARB at 2023-5-31 20:03  
 
Hi, I am new to Linux based systems and Orange Pi 5. For a project, I need to use a flow sensor and display the flow rate.  
 
 
I am using a flow sensor with sends pulses. The Orange Pi creates an interrupt to read the pulses and increase a counter, and the flow rate is caluclated based on that. I am facing an error while running the file that: "wiringPiISR: unable to open /sys/class/gpio/gpio138/value: No such file or directory 
 
 
The code that I am using: 
 
 
import time 
import ctypes 
 
# Load the WiringPi library 
wiringpi = ctypes.CDLL('libwiringPi.so') 
 
# Constants 
FLOW_SENSOR_PIN = 5 
 
# Set up WiringPi 
wiringpi.wiringPiSetup() 
 
# Set pin mode to INPUT 
wiringpi.pinMode(FLOW_SENSOR_PIN, 0) 
 
# Variables 
pulse_count = 0 
flow_rate = 0.0 
 
# Function to handle interrupt 
def handle_interrupt(): 
    global pulse_count 
    pulse_count += 1 
 
# Configure interrupt handler 
INT_EDGE_FALLING = 1 
INT_EDGE_SETUP = 0 
wiringpi.wiringPiISR(FLOW_SENSOR_PIN, INT_EDGE_FALLING, ctypes.CFUNCTYPE(None)(handle_interrupt)) 
 
# Start the program 
print("Flow Sensor Reading Started") 
 
try: 
    # Main loop 
    while True: 
        # Reset pulse count 
        pulse_count = 0 
 
        # Delay for 1 second 
        time.sleep(1) 
 
        # Calculate flow rate 
        calibration_factor = 4.5  # Calibration factor for the flow sensor 
        flow_rate = (pulse_count / 7.5) * calibration_factor  # Calculate flow rate in liters per minute 
 
        # Print flow rate 
        print("Flow rate: {:.2f} L/min".format(flow_rate)) 
 
except KeyboardInterrupt: 
    # Cleanup GPIO pins 
    wiringpi.pinMode(FLOW_SENSOR_PIN, 0) 
 
    print("\nFlow Sensor Reading Stopped") 
 
 
What am I doing wrong or missing out? 
 |   
 
 
 
 |