1

I use this simple circuit to control a DC motor with an L293D, and a 9g servo motor with a Raspberry PI Zero W:

enter image description here

I use the simple following code to test the circuit:

from time import sleep
import RPi.GPIO as GPIO   

ServoPin = 32

MotorPin1 = 3
MotorPin2 = 5
MotorEnable = 33

GPIO.setmode(GPIO.BOARD)

GPIO.setup(ServoPin, GPIO.OUT)

GPIO.setup(MotorPin1, GPIO.OUT)
GPIO.setup(MotorPin2, GPIO.OUT)
GPIO.setup(MotorEnable, GPIO.OUT)

servoPWM = GPIO.PWM(servoPIN, 50)   # 50 Hz
servoPWM.start(2.5)                 # Duty cycle (0.0 <= dc <= 100.0)

motorPWM = GPIO.PWM(MotorEnable, 100)
motorPWM.start(0)

GPIO.output(MotorPin1, GPIO.LOW)
GPIO.output(MotorPin2, GPIO.HIGH)

sleep(0.5)

servoPWM.ChangeDutyCycle(5)
motorPWM.ChangeDutyCycle(25)

sleep(0.5)

servoPWM.ChangeDutyCycle(10)
motorPWM.ChangeDutyCycle(50)

sleep(0.5)

GPIO.output(MotorPin1, GPIO.HIGH)
GPIO.output(MotorPin2, GPIO.LOW)

servoPWM.ChangeDutyCycle(2.5)
motorPWM.ChangeDutyCycle(80)

sleep(0.5)

The raspberry crashes (reboot) often, mostly when controlling both the motor and the servo at the same time. Any idea why?

I followed those instructions for the DC motor wiring.

  • I can not correlate the circuit diagram with the code you are using. Could you add a photo or photos which clearly show the connections you are using. The script is also wrong. You are using BOARD numbering and pin 4 as a GPIO. Pin 4 is not connected to a GPIO, it is connected to the 5V power rail. It's fairly pointless to speculate on the crashes without seeing the actual connections. – joan Aug 18 '18 at 14:49
  • Sorry, I used random pin numbers in this script since I don't have my raspberry pi with me :/ But you can consider the pins to be correct (I edited them). – arthur.sw Aug 18 '18 at 15:17
  • The only thing is that I connected the 3.3V of the L293D on a 5V pin, but I assumed it is not a big deal... – arthur.sw Aug 18 '18 at 15:22
  • "The only thing is that I connected the 3.3V of the L293D on a 5V pin, but I assumed it is not a big deal..." Translation AKA edited as is common on this forum **I am using common power source for all devices ** – Jan Hus Aug 18 '18 at 18:12
2

the spike caused by motors, drops the controller voltage.

in this case (the pi), it will drop to 4.6 v for example, which is enough to cause to to reboot.

either use an adapter for rpi, or give it another clean power source.

plus, for the same reason DIY quadcopters have separate batteries dedicated for the controller.

1

"The only thing is that I connected the 3.3V of the L293D on a 5V pin, but I assumed it is not a big deal..."

Translation AKA edited as is common on this forum **I am using common power source for all devices **

IT IS A HUGE DEAL ! Electromechanical devices are 1. power hungry 2. when initialized /started they are EXTREMELY power hungry - tech term is "power surge" 3. require "HARD" power source - tech term "power source producing SAME power (level) during initial power-up."

Your RPi power goes bellow nominal 3.3V during your devices start causing it to reset.

The solution Provide SEPARATE power for your motors. Make sure RPi outputs are ISOLATED from your devices - optocouplers works fine. Make sure your motors have BEMF "back electromotive force" protection - your hardware diver should do fine.

PS Next post do not spent time making fancy circuits layouts pictures - they do not grantee it is actually wired as shown and invite unnecessary criticism of your post. Your verbal post was all what was needed and you did good job.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.