Issues with PWN when running python file

I am running a python program to control the speed of a dc motor on the jetson nano and trying to use PWN however, I am receiving an error when I run the code saying “Attribute Error: ‘module’ object has no attribute ‘PWN’”. I have the import statement “import RPi.GPIO as GPIO” in my program. I am not sure what the issue. Does anyone know a solution for this error or know another way to control the speed of dc motors?

Have you tried PWM as is Mary

Thank you. That spelling mistake was the error. However, even though my there are no errors, when I run my program, nothing happens to the motor.

import RPi.GPIO as GPIO
import time

for 1st Motor on ENA

ENA = 33
IN1 = 35
IN2 = 37

set pin numbers to the board’s

GPIO.setmode(GPIO.BOARD)

initialize EnA, In1 and In2

GPIO.setup(ENA, GPIO.OUT)
GPIO.setup(IN1, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(IN2, GPIO.OUT, initial=GPIO.LOW)

pwm= GPIO.PWM(ENA,100)
pwm.start(0)

Forward

GPIO.output(IN1, GPIO.HIGH)
GPIO.output(IN2, GPIO.LOW)
pwm.ChangeDutyCycle(100)
time.sleep(1)

Backward

GPIO.output(IN1, GPIO.LOW)
GPIO.output(IN2, GPIO.HIGH)
pwm.ChangeDutyCycle(50)
time.sleep(1)

Stop

GPIO.output(IN1, GPIO.LOW)
GPIO.output(IN2, GPIO.LOW)
time.sleep(1)

pwm.stop()
GPIO.cleanup()

Could someone help me find out why?

Have you configured the pinmux for PWM?

$ cd /opt/nvidia/jetson-io
$ sudo jetson-io.py

Configure 40-pin expansion header, Select pwm2 (33), Save and exit, reboot.

and see:
jetson-gpio/simple_pwm.py at master · NVIDIA/jetson-gpio (github.com)

Yes I already selected pwm2(33) in the pin configuration when I was running my program.

I have a feeling you haven’t tried the jetson-io tool. Configuring the pins in python isn’t enough. CHeck the documentation again.

  1. PWM

See samples/simple_pwm.py for details on how to use PWM channels.

The Jetson.GPIO library supports PWM only on pins with attached hardware PWM controllers. Unlike the RPi.GPIO library, the Jetson.GPIO library does not implement Software emulated PWM. Jetson Nano supports 2 PWM channels, and Jetson AGX Xavier supports 3 PWM channels. Jetson TX1 and TX2 do not support any PWM channels.

The Jetson.GPIO library does not dynamically modify the pinmux configuration to achieve this. Read the L4T documentation for details on how to configure the pinmux.

This is the only way I was able to get it to work. Also if you are connected via SSH, “Save and exit without rebooting” then reboot. I tried “Save and reboot” before and it wouldn’t boot again.

$ cd /opt/nvidia/jetson-io
$ sudo jetson-io.py

I have already configure the pwm pins with jetson-io. This is what is currently says after save and reboot. Do I need to do anything else?

That’s all. Test the code I linked earlier.

I tried running the code you sent for 2 dc motors but the motors aren’t doing anything. I was little confused on how the motors are wired to the input pins. Are the pwm pins being connected to enable on a motor driver or are they connected to the to the motors directly? If possible, could you explain the schematic to run that code?

I think the 2 motor example is using this 10Amp 6V-24V DC Motor Driver HAT for RPI (2 Channels) (cytron.io)

Your use case might be different.

Yes I am using a PChero L298N Motor Drive Controller Board Module, Dual H Bridge DC Stepper for Arduino. Do you know if theres an issue with the code I sent earlier?

I’m not familiar with that motor driver. Can you scope the PWM pin(s) to make sure they’re working?

Does this help?
Building a Custom JetBot with Jetson Nano - Hackster.io

I check the pin with a scope and found that the pin didn’t generate a pulse.

hello akashsivapalanspam,

may I know what’s the results by checking debug node. $ cat /sys/kernel/debug/pwm

platform/70110000.pwm, 1 PWM device
pwm-0 (pwm-regulator ): requested enabled period: 2500 ns duty: 0 ns po larity: 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 polarit y: normal
pwm-2 ((null) ): period: 0 ns duty: 0 ns polarity: normal
pwm-3 (pwm-fan ): requested enabled period: 45334 ns duty: 0 ns p olarity: normal