tomsimmons
Posts: 107
Joined: Sun Jan 19, 2014 5:54 pm

PIGPIO Callback

Sun Dec 09, 2018 10:22 am

I'm using Python 3 and Pigpio to monitor and control some hardware, the problem I'm having is with callback on a connection to a flow meter.

The flow meter is little more than an impellor in a tube that generates a pulse every revolution. I can't recall the max flow rate, but the sensor generates 750 pulses per litre of water - according to the spec.

I have my main python program, that create an instance of a class solely for dealing with the flow meter. This class sets up the flow meter...

Code: Select all

self.__pi.set_mode(FLOW_SENSOR, pigpio.INPUT) # flow sensor
self.__pi.set_pull_up_down(FLOW_SENSOR, pigpio.PUD_UP)
cb = self.__pi.callback(FLOW_SENSOR, pigpio.FALLING_EDGE, self.intrptFlow)
and the interrupt function is...

Code: Select all

def intrptFlow(self, gpio, level, tick):
        self.__pulseCount += 1
When I ask for the contents of the pulseCount variable I'm getting very small values, 1 - 8 when I expect thousands.

Have I don this correctly, it seemed to work when on test bed and I had another python program generating the pulses - didn't fancy a hose pipe coming into the office to run the flow meter!

Does this need to be threaded? My understanding was it acts like an interrupt so would take care of itself.


Tom

User avatar
bensimmo
Posts: 3975
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: PIGPIO Callback

Sun Dec 09, 2018 10:57 am

Just a quick one as others are better at this than me.
Have you checked the pulses you are actually getting? (Oscilloscope or similar?)

Have you checked the pulses the Pi is seeing at the pin? With piscope http://abyz.me.uk/rpi/pigpio/piscope.html

tomsimmons
Posts: 107
Joined: Sun Jan 19, 2014 5:54 pm

Re: PIGPIO Callback

Sun Dec 09, 2018 11:04 am

Bensimmo

Thanks for your reply.

Sadly I haven't been I a position to, it all looked like it was working on the workbench, since then it hasn't been somewhere that I can easily get a scope to.

I guess I'm going to have to, but was hoping someone could confirm my approach was correct.

Tom

User avatar
bensimmo
Posts: 3975
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: PIGPIO Callback

Sun Dec 09, 2018 11:08 am

Usually Joan answers these questions at some point. (The author of pigpio).

But plenty of other can answer them.
But if it works from simulated square pulses, then it probably works.
To me that would then be the hardware, how square are the pulses... Are they all meeting the threshold voltage for a pulse (>~2V )
Is there a link to the flow meter document incase anyone can spot a problem with it.

tomsimmons
Posts: 107
Joined: Sun Jan 19, 2014 5:54 pm

Re: PIGPIO Callback

Sun Dec 09, 2018 11:17 am

It's really annoying, this project has been on the go for over a year, I was sent the spec, or at least a link, ages ago, since then they have changed the sub model of the flow sensor they are using, but I can't find the link.

The sensor is meant to provide a perfect square wave on it's own.

Tom

tomsimmons
Posts: 107
Joined: Sun Jan 19, 2014 5:54 pm

Re: PIGPIO Callback

Sun Dec 09, 2018 11:41 am

I've just remoted onto the Pi, installed PiScope, I'll see if that help.

User avatar
joan
Posts: 13930
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: PIGPIO Callback

Sun Dec 09, 2018 12:02 pm

750 pulses per litre sounds very high. 750 per cubic metre would also seem high.

tomsimmons
Posts: 107
Joined: Sun Jan 19, 2014 5:54 pm

Re: PIGPIO Callback

Sun Dec 09, 2018 3:11 pm

Joan

When you say high, do you mean high for a flow meter, or high for Pigpio to handle?

I'm pretty sure my code is correct as I'm sure it worked previously and other interrupts seem to be working fine.


Tom

User avatar
joan
Posts: 13930
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: PIGPIO Callback

Sun Dec 09, 2018 3:19 pm

High for a flow meter. pigpio should handle thousands per second. In the UK water is usually sold in cubic metres, a 100 pulses per cubic metre would probably be enough.

tomsimmons
Posts: 107
Joined: Sun Jan 19, 2014 5:54 pm

Re: PIGPIO Callback

Sun Dec 09, 2018 3:34 pm

Joan

It's not a domestic flow meter I'm using, but it could well be I've been told a load of ...

I was originally told it would be 1120 a litre with a max flow rate of litres per min.

As a quick aside, PiScope, if I run that on the same Pi as my code, which is using most of the IO pins, does it have any affect on their configuration or code operation or is entirely passive?


Tom

User avatar
joan
Posts: 13930
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: PIGPIO Callback

Sun Dec 09, 2018 5:54 pm

pigpio is completely passive when monitoring. piscope does not alter the state of any GPIO. A simpler command line alternative is http://abyz.me.uk/rpi/pigpio/examples.h ... monitor_py

Both require the pigpio daemon to be running.

(sudo pigpiod)

Return to “Python”