0

I believe this code is correct. I am working connected to the Pi through SSH and tried running it through the Mu shell. Motor controller is hooked up to a 12V power supply. If it helps, I noticed the signal power indicator is not on, but the power indicator is on solid.

# Imported Libraries
import RPi.GPIO as GPIO
from time import sleep

# SetMode
GPIO.setmode(GPIO.BOARD)

# Motor 1 Setup
PWR1, ENA1, IN1, IN2, GND = 2, 33, 31, 29, 39
GPIO.setup(ENA1, GPIO.OUT)
GPIO.setup(IN1, GPIO.OUT)
GPIO.setup(IN2, GPIO.OUT)
PWMA = GPIO.PWM(ENA1, 50)
PWMA.start(0)

# Motor 2 Setup
PWR2, ENA2, IN3, IN4, GND = 4, 32, 18, 16, 34
GPIO.setup(ENA2, GPIO.OUT)
GPIO.setup(IN3, GPIO.OUT)
GPIO.setup(IN4, GPIO.OUT)
PWMB = GPIO.PWM(ENA2, 50)
PWMB.start(0)


GPIO.output(IN1, GPIO.HIGH)
GPIO.output(IN2, GPIO.LOW)
PWMA.ChangeDutyCycle(60)
# Cleanup
GPIO.cleanup()
5
  • you have not described the problem that you are facing
    – jsotola
    Dec 22, 2020 at 5:46
  • this is the way it was done in this code: github.com/jumejume1/pi-l298n-dc-motor/blob/master/… Dec 22, 2020 at 5:49
  • i looked at your previous code .... it looks like you corrected problems with the old code, but you left out some other parts that you probably need
    – jsotola
    Dec 22, 2020 at 7:59
  • This is a general programming question. Have you noticed the program exits as soon as you have set up the motors? Do you realise that will undo everything you have done?
    – joan
    Dec 22, 2020 at 8:52
  • I should get rid of gpio cleanup, right? it still doesnt work Dec 22, 2020 at 15:12

0

Browse other questions tagged or ask your own question.