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.
CP Code for Liquid Flow Meter
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- dastels
- Posts: 15667
- Joined: Tue Oct 20, 2015 3:22 pm
Re: CP Code for Liquid Flow Meter
You'll probably want to be using the pulseio module, specifically the PulseIn class: https://circuitpython.readthedocs.io/en ... lseIn.html
Dave
Dave
- Gregg28
- Posts: 28
- Joined: Fri May 15, 2020 3:39 pm
Re: CP Code for Liquid Flow Meter
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?
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?
- dastels
- Posts: 15667
- Joined: Tue Oct 20, 2015 3:22 pm
Re: CP Code for Liquid Flow Meter
You could use combined adjacent high and low durations to get a frequency.
Dave
Dave
- Gregg28
- Posts: 28
- Joined: Fri May 15, 2020 3:39 pm
Re: CP Code for Liquid Flow Meter
I will try that tomorrow. Thanks.
- Gregg28
- Posts: 28
- Joined: Fri May 15, 2020 3:39 pm
Re: CP Code for Liquid Flow Meter
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)
- Gregg28
- Posts: 28
- Joined: Fri May 15, 2020 3:39 pm
Re: CP Code for Liquid Flow Meter
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
Thanks
- dastels
- Posts: 15667
- Joined: Tue Oct 20, 2015 3:22 pm
Re: CP Code for Liquid Flow Meter
It looks like ther are a few projects that might be of interest: https://learn.adafruit.com/search?q=ble.
Dave
Dave
Please be positive and constructive with your questions and comments.