0
votes

I am trying to run balance() function on one thread and use Timer on a separate one. Both methods when run separately work fine, but when I try to use them both at once the issr() function which is called by a Timer just stops working after few calls. There is no error on REPL from Raspberry. The motor.do_step() method just changes the Pin values from 0 to 1 when called. Any ideas what is the problem?

def issr(timer):
    global motor1, motor2, i
    motor1.do_step()
    motor2.do_step()


def balance():
    while True:
        global motor1, motor2
        motor1.set_speed(1000)
        motor2.set_speed(1000)


_thread.start_new_thread(balance, ())

tim = Timer()
tim.init(freq=3000, mode=Timer.PERIODIC, callback=issr)
you should move your global statement away from while loop, and have some sleep in balance functionLixas