Using Pigpio to drive a couple of stepper motors on a CNC-like system, I'd like to "initialize" by setting up a repeating wave to continually step until a limit switch has been reached, at which point I'd issue a wave_tx_stop() to halt the stepper. I'm curious if there's any way of seeing how many pulses have been issued at the point the wave was stopped, so that I could deduce how many steps "wide" the area is between limit switches.

That is, is there any way to see how many total pulses have been executed by the currently-running wave chain? Am I just way off base here and need to try something different?


You will have to find an alternative mechanism. There is no way to tell how many pulses have been transmitted by an interrupted wave chain (unless the pulses are quite slow and you have an alert set up on the pulse GPIO).

If you run a wave chain with a loop count to completion it will have executed the number of pulses in the loop count.

  • Ah, that's a bummer, but it makes sense. Out of curiosity, do you have an idea as to what constitutes "quite slow" in this context? 100 us? 1ms? More? Anyway, thank you for the quick response. – Jordan Day Oct 26 '17 at 13:43
  • @JordanDay Speed would depend on the language (e.g. C is likely to be better than Python) and principally the interface, e.g. the socket interface (used by Python) will be slower than a directly linked C application. As a ball park something like 40k per second on a Pi3 using Python. – joan Oct 26 '17 at 15:40

For all those still searching: Actually there is - contradictory to the current answer - a pretty good solution also provided by pigpio (at least for me there was)!

You can use either piscope (a way too much overhead) or if the frequency is not too high you can use pigpio.callback() too keep accurate track of the total pulses sent.

cb = pi.callback(GPIO)
# to create a simple "callback counter" on the pin where the PWM pulses are sent
print(cb.tally()) # to display number of pulses made
cb.reset_tally() # to reset the counter

See also following Stackexchange Post

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.