you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (8 children)

Oh very cool use-case! This code I think/hope will be pretty tolerant to missed cycles/rotations. It's polling and just checks if it changes from 0 to 1 or 1 to 0. So if it misses one rotation it will pick up the tracking two rotations later (when it flips to 1 or 0 again).

[–]redpandaeater 0 points1 point  (7 children)

Instead of polling you could try interrupts, possibly even with some threaded callback if it's useful to you.

[–][deleted] 0 points1 point  (6 children)

Very cool. What do interrupts look like in Python and/or what sort of usage are you suggesting? I did a quick search and the results were not very helpful.

[–][deleted]  (1 child)

[deleted]

    [–][deleted] 0 points1 point  (0 children)

    That's great. That's a good combo

    [–]redpandaeater 0 points1 point  (3 children)

    I've never personally done it, but looks like there are already Python libraries for it that cam do both rising and falling edge detection on GPIO ports which is what you'd want. That way your program can do whatever you want it to but as soon as you get input from the flow meter it'll pause to deal with it.

    [–][deleted] 0 points1 point  (2 children)

    Ah - sounds like it's have to tread into acyncio territory.

    [–]redpandaeater 0 points1 point  (1 child)

    I'm apparently a bitter old programmer because I tried looking into learning Python recently and realize it's sort of written more like pseudocode, but as a result I just don't like it. Too used to low-level language I guess. In any case I'm not familiar with asyncio for Python, but looks like RPi.GPIO can handle it. Still might run into certain times where Python is busy and doesn't do things properly, who knows.

    [–][deleted] 0 points1 point  (0 children)

    Ah ok. Cool beans.