CP Code for Liquid Flow Meter

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Gregg28
 
Posts: 28
Joined: Fri May 15, 2020 3:39 pm

CP Code for Liquid Flow Meter

Post by Gregg28 »

I am new to this. I am doing my project on a Feather Express using Circuitpython. I am trying to connect three different sensors, analog, digital and pulse (Hall Effect). I have the analog and digital working, but I can not find any example code for the pulse. It is an Adafruit Liquid Flow Sensor, plastic (https://www.adafruit.com/product/828). Is there any example code written in Circuitpython to get me started? Sorry for my ignorance, as I said, I am new to this.
Thanks.

User avatar
dastels
 
Posts: 15667
Joined: Tue Oct 20, 2015 3:22 pm

Re: CP Code for Liquid Flow Meter

Post by dastels »

You'll probably want to be using the pulseio module, specifically the PulseIn class: https://circuitpython.readthedocs.io/en ... lseIn.html

Dave

User avatar
Gregg28
 
Posts: 28
Joined: Fri May 15, 2020 3:39 pm

Re: CP Code for Liquid Flow Meter

Post by Gregg28 »

Thanks.
That does give me a pulse length, but I need to get the frequency. Is there a function in there that counts pulses during a time window?

User avatar
dastels
 
Posts: 15667
Joined: Tue Oct 20, 2015 3:22 pm

Re: CP Code for Liquid Flow Meter

Post by dastels »

You could use combined adjacent high and low durations to get a frequency.

Dave

User avatar
Gregg28
 
Posts: 28
Joined: Fri May 15, 2020 3:39 pm

Re: CP Code for Liquid Flow Meter

Post by Gregg28 »

I will try that tomorrow. Thanks.

User avatar
Gregg28
 
Posts: 28
Joined: Fri May 15, 2020 3:39 pm

Re: CP Code for Liquid Flow Meter

Post by Gregg28 »

OK, so here is my code. It seemed to work until the rpm of the wheel dropped to 0 and then crashed. Something turned it off. So moved the Wait for an active pulse inside the while loop and that fixed it. I need to put an if statement in to output 0 while it is waiting.

Code: Select all

import pulseio
import board
import time

pulses = pulseio.PulseIn(board.A0)


while True:
    # Pause while we do something with the pulses
    pulses.pause()

    # Print the pulses. pulses[0] is an active pulse unless the length
    # reached max length and idle pulses are recorded.
    print("pulses: {} Hz".format(pulses[0]))
    # Clear the rest
    pulses.clear()
    # Resume with an 80 microsecond active pulse
    pulses.resume()
    time.sleep(.5)

User avatar
Gregg28
 
Posts: 28
Joined: Fri May 15, 2020 3:39 pm

Re: CP Code for Liquid Flow Meter

Post by Gregg28 »

I am trying to use this as a peripheral device to send data to my phone. Nothing complicated, just a simple ble broadcast would do. Is there an example of just a simple project in circuitpython that just broadcasts data from a sensor?

Thanks

User avatar
dastels
 
Posts: 15667
Joined: Tue Oct 20, 2015 3:22 pm

Re: CP Code for Liquid Flow Meter

Post by dastels »

It looks like ther are a few projects that might be of interest: https://learn.adafruit.com/search?q=ble.

Dave

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”