I’ve tried searching for a solution to my problem but was unable to find one.
I am currently working with Zerynth and a DOIT ESP32 DevKit V1. I have included my code below. I am trying to activate only one motor at a time using PWM, setting the duty to 0 when a motor should not be activated. The problem is I took this straight from a working project, and now this section of the PWM-related code isn’t working.
For example, when I activate Motor 1, I can confirm via print statements that only the duty for one motor is being set at a time, and all others are 0. When I set the duty for Motor 1, this is the case. However, if I then set the duty for Motor 2, Motor 1 continues working AND Motor 2 is activated, even though the duty for Motor 1 should be set to 0. When I set all motors to 0, they turn off in unison as expected. However, when I try to activate Motor 2 again, Motor 2 and Motor 1 turn on together again. It seems they are somehow tied together even though I can confirm that this portion of the code works perfectly when tested in a different environment. I’m wondering if there’s some issue with the PWM module that I’m not aware of? Any help would be much appreciated.
import pwm ... forward_pin = D18.PWM left_pin = D19.PWM back_pin = D22.PWM right_pin = D23.PWM pinMode(forward_pin, OUTPUT) pinMode(left_pin, OUTPUT) pinMode(back_pin, OUTPUT) pinMode(right_pin, OUTPUT) forward = 0 left = 0 back = 0 right = 0 # MICROS so every sec is 1000000 of micros frequency = 100 period = 1000000//frequency ... def set_PWM(direction, range): # Range comes in 0, 1, 2, or 3 if range == 0: # Set duty to 0 duty = 0 else: # Set duty to period/3, period/2, or 1 duty = period//range if direction == 1: # Motor 1 forward = duty left = 0 back = 0 right = 0 elif direction == 2: # Motor 2 forward = 0 left = duty back = 0 right = 0 elif direction == 3: # Motor 3 forward = 0 left = 0 back = duty right = 0 elif direction == 4: # Motor 4 forward = 0 left = 0 back = 0 right = duty else: # Set all to 0 forward = 0 left = 0 back = 0 right = 0 print('\nForward ') print(forward) print('Left') print(left) print('Back') print(back) print('Right') print(right) pwm.write(forward_pin, period, forward, MICROS) pwm.write(left_pin, period, left, MICROS) pwm.write(back_pin, period, back, MICROS) pwm.write(right_pin, period, right, MICROS)