View: 2285|Reply: 6

Using Flow Sensor with WiringOP

[Copy link]

1

threads

1

posts

5

credits

Novice

Rank: 1

credits
5
Published in 2023-5-31 19:51:47 | Show all floors |Read mode
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?
Published in 4 daybefore | Show all floors
An impressive share, I merely given this onto a colleague who was doing a little analysis for this. Anf the husband in truth bought me breakfast simply because I found it for him.. smile. So i want to reword that: Thnx for your treat! But yeah Thnkx for spending plenty of time to talk about this, I feel strongly regarding this and really like reading regarding this topic. If it is possible, as you grow expertise, can you mind updating your blog site with a lot more details? It’s highly useful for me. Huge thumb up with this writing!        Bioma Probiotics
Published in byday 15:23 | Show all floors
I’m interested in using some of your material for my website. Please let me know if that’s OK and I will link back to this page.        bokep indonesia
Published in byday 19:42 | Show all floors
Perhaps this is a bit off topic but in any case, I have been surfing about your blog and it looks really neat. impassioned about your writing. I am creating a new site and hard-pressed to make it appear great, and supply excellent articles. I have discovered a lot on your site and I watch forward to additional updates and will be back.        บาคาร่า88
Published in byday 21:42 | Show all floors
It’s best to take part in a contest for top-of-the-line blogs on the web. I will advocate this site!        sbobet777 login
Published in yesterday 19:16 | Show all floors
thank you for a really fascinating read, i hope you would do a follow up article considering i can never go through enough on this topic        https://new88838.com
Published in yesterday 19:53 | Show all floors
Rapidly this particular amazing web site ought to irrefutably turned out to be acknowledged inside all the website many people, because of the diligent content articles or even evaluations or even suggestions.        kingthai999
You need to log in before you can reply login | Register

Points Rule

Quick reply Top Return list