0

Starting Day 2 troubleshooting this error. Code used to work on a previous rasp pi 4B but doesn't on a new one so I'm assuming I'm missing some breaking change.

Problem:

Using import RPi.GPIO as GPIO I run some basic setup:

GPIO.setmode(GPIO.BCM) GPIO.setup(pin_motor_1_a, GPIO.OUT) GPIO.setup(pin_motor_1_b, GPIO.OUT) motor_1_f = GPIO 

which runs. When I get to any code that uses the GPIO object it says i'm missing that attribute so:

motor_1_f.start(0) 

Errors:

AttributeError: module 'RPi.GPIO' has no attribute 'start'

If I remove the start call I get further down my code and just have the same error on other things like:

motor_1_f.ChangeDutyCycle(0)

Gives:

AttributeError: module 'RPi.GPIO' has no attribute 'ChangeDutyCycle'

I've wiped my SD card several with Raspberry Pi OS Lite times and went through the python3 / pip3 setup and can't get past this error. This is my entire setup on first boot:

 sudo apt update sudo apt upgrade sudo apt update -y sudo apt dist-upgrade -y sudo apt install git -y sudo apt install python3-pip -y sudo apt install python3-venv -y sudo apt install python3-dev -y sudo apt-get install libgpiod2 -y sudo apt-get install wiringpi -y sudo apt-get install -y python-smbus -y sudo apt-get install -y i2c-tools -y sudo apt-get install raspi-config -y sudo apt-get install rpi.gpio -y sudo apt-get install python-setuptools -y pip3 install --upgrade setuptools pip3 install adafruit-circuitpython-rplidar pip3 install pygame pip3 install --upgrade setuptools pip3 install --upgrade adafruit-python-shell pip3 install --upgrade adafruit-circuitpython-dotstar adafruit-circuitpython-motor adafruit-circuitpython-bmp280 pip3 install adafruit-circuitpython-hcsr04 pip3 install adafruit-blinka 

What am I missing? - thanks!

1 Answer 1

2

Those functions are part of GPIO.PWM.

Instead of motor_1_f = GPIO try motor_1_f = GPIO.PWM(channel, frequency)

1
  • The reason this code worked before is because that's how it was before - I don't know why I changed it :facepalm: Commented May 11, 2022 at 13:41

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.