Page 1 of 1

PIGPIO Callback

Posted: Sun Dec 09, 2018 10:22 am
by tomsimmons
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

Re: PIGPIO Callback

Posted: Sun Dec 09, 2018 10:57 am
by bensimmo
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

Re: PIGPIO Callback

Posted: Sun Dec 09, 2018 11:04 am
by tomsimmons
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

Re: PIGPIO Callback

Posted: Sun Dec 09, 2018 11:08 am
by bensimmo
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.

Re: PIGPIO Callback

Posted: Sun Dec 09, 2018 11:17 am
by tomsimmons
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

Re: PIGPIO Callback

Posted: Sun Dec 09, 2018 11:41 am
by tomsimmons
I've just remoted onto the Pi, installed PiScope, I'll see if that help.

Re: PIGPIO Callback

Posted: Sun Dec 09, 2018 12:02 pm
by joan
750 pulses per litre sounds very high. 750 per cubic metre would also seem high.

Re: PIGPIO Callback

Posted: Sun Dec 09, 2018 3:11 pm
by tomsimmons
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

Re: PIGPIO Callback

Posted: Sun Dec 09, 2018 3:19 pm
by joan
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.

Re: PIGPIO Callback

Posted: Sun Dec 09, 2018 3:34 pm
by tomsimmons
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

Re: PIGPIO Callback

Posted: Sun Dec 09, 2018 5:54 pm
by joan
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)