JorgeG30
Posts: 3
Joined: Tue Jul 10, 2018 3:59 pm

GPIO callback function does not update quick enough

Tue Jul 10, 2018 4:29 pm

Hello,

I am currently working on a python script that sends pulses from one pin to a stepper motor driver using pigpio. Sending the pulses is fine since the motor moves whenever the pulses are sent. The problem is that within my callback function I am incrementing or decrementing a variable based on the direction of the stepper motor driver. Here is the callback function

Code: Select all

def xPulseCount(gpio, level, tick):
	global xPulses
	global xdir
	if xdir == 0:
		xPulses = xPulses - 1
	elif xdir == 1:
		xPulses = xPulses + 1
My problem is that even though the function is being called, the xPulses variable isn't being updated fast enough it seems. In my output I would get an updated value every 2 pulses or so. So it would go from 1 to 3 to 5 etc. I am running 3 other callbacks along side this one. There are 2 different pins, each with 2 callbacks. Could this be an issue. Could the delay between writing high and low to the pins be an issue as well since the delay between writing high and low to a pin is .0001 seconds. Thank you for any help or advice

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

Re: GPIO callback function does not update quick enough

Tue Jul 10, 2018 6:00 pm

pigpio Python may not be suitable. Callbacks will have perhaps 0.5 milliseconds latency. You would be better off using another Python GPIO library if you want an immediate response to an interrupt.

JorgeG30
Posts: 3
Joined: Tue Jul 10, 2018 3:59 pm

Re: GPIO callback function does not update quick enough

Wed Jul 11, 2018 12:16 am

Thanks for the advice. Any other GPIO library that you can recommend?

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

Re: GPIO callback function does not update quick enough

Wed Jul 11, 2018 6:43 am

RPi.GPIO is the obvious choice. It will be as fast as any of the others for callback responsiveness. If that is not good enough you will probably have to use C.

JorgeG30
Posts: 3
Joined: Tue Jul 10, 2018 3:59 pm

Re: GPIO callback function does not update quick enough

Wed Jul 11, 2018 2:22 pm

Alright I’ll give it a shot. Thanks for the advice

Return to “Python”

Who is online

Users browsing this forum: oumaymahd and 23 guests