Hello everyone,
I am having issues with PWM on pins 32 and 33, which I urgently need to resolve. I enabled the PWM on pins 32 and 33 via:
sudo /opt/nvidia/jetson-io/jetson-io.py
But when setting PWM for controlling motors via my L298N bridge from a Python script on my Jetson NANO, they go full speed, no matter the PWM I set.
This is the output of $ sudo cat /sys/kernel/debug/pwm:
platform/70110000.pwm, 1 PWM device
pwm-0 (pwm-regulator ): requested enabled period: 2500 ns duty: 0 ns polarity: normal
platform/7000a000.pwm, 4 PWM devices
pwm-0 ((null) ): period: 0 ns duty: 0 ns polarity: normal
pwm-1 (pwm-regulator ): requested period: 8000 ns duty: 1440 ns polarity: normal
pwm-2 ((null) ): period: 0 ns duty: 0 ns polarity: normal
pwm-3 (pwm-fan ): requested enabled period: 45334 ns duty: 0 ns polarity: normal
I’m new to embedded developing, so any help would be appreciated! The other topics on the issue couldn’t seem to resolve it tho…
This is my Python script controlling the motors:
import Jetson.GPIO as GPIO
import time
# Set the mode of numbering the pins.
GPIO.setmode(GPIO.BOARD)
# Motor A
ENA = 32 # Speed control for motor A (PWM)
IN1 = 35 # Direction
IN2 = 37 # Direction
# Motor B
ENB = 33 # Speed control for motor B (PWM)
IN3 = 38 # Direction
IN4 = 40 # Direction
# Set up the pins
GPIO.setup(ENA, GPIO.OUT)
GPIO.setup(IN1, GPIO.OUT)
GPIO.setup(IN2, GPIO.OUT)
GPIO.setup(ENB, GPIO.OUT)
GPIO.setup(IN3, GPIO.OUT)
GPIO.setup(IN4, GPIO.OUT)
# Set PWM frequency
pwm_A = GPIO.PWM(ENA, 1000) # Frequency in Hz
pwm_B = GPIO.PWM(ENB, 1000) # Frequency in Hz
# Start PWM
pwm_A.start(0)
pwm_B.start(0)
def motorControl(motor, speed, direction):
if motor == 'A':
pwm = pwm_A
in1 = IN1
in2 = IN2
else:
pwm = pwm_B
in1 = IN3
in2 = IN4
pwm.ChangeDutyCycle(speed)
if direction == 'r':
GPIO.output(in1, GPIO.HIGH)
GPIO.output(in2, GPIO.LOW)
elif direction == 'f':
GPIO.output(in1, GPIO.LOW)
GPIO.output(in2, GPIO.HIGH)
else:
GPIO.output(in1, GPIO.LOW)
GPIO.output(in2, GPIO.LOW)
try:
while True:
pwm_1, pwm_2, dir_1, dir_2, stime = input("PWM1, PWM2, DIR1, DIR2, TIME: ").replace(" ", "").split(",")
motorControl("A", int(pwm_1), dir_1)
motorControl("B", int(pwm_2), dir_2)
time.sleep(float(stime))
motorControl("A", 0, "x")
motorControl("B", 0, "x")
finally:
pwm_A.stop()
pwm_B.stop()
GPIO.cleanup()
Any help would be appreciated, thanks in advance!