1

I want to control 4 DC Motors from a Raspberry Pi. I am just starting by making sure that 1 motor can be controlled. I am following this guide: https://projects.raspberrypi.org/en/projects/physical-computing/14, which explains the wiring configuration for the motor control board to the motor, and how to use the Motor class in the gpiozero library.

I have connected the Motor Control Board powered by dual H-bridge IC L293D http://shop.sb-components.co.uk/products/motorshield-for-raspberry-pi to the Raspberry Pi, and the battery box to the motor control board (switched on). When directly connecting my DC motor to the battery box, the motor spins very fast, so I know that it works. The motor has 2 wires (black and red) which I connect to the holes for Motor 1 on the motor control board as follows:

enter image description here

I am also following the pin documentation for the motor control board:

enter image description here

After everything is connected, I run the following code on the Raspberry Pi (using user Vadim's suggestion):

from gpiozero import Motor

motor1 = Motor(forward=15, backward=13, enable=11)

while True:
    motor1.forward()

However, the motor does not move at all. I was a bit confused by the pin description, as I am not sure what the distinction between 'enable' and 'control' is, as they have a total of 3 GPIO pins (11, 13, and 15), but I have only 2 wires on my motor.

However, I have tried every combination of GPIO values into my code above: Motor(11, 15, 13), Motor(15, 11, 13), Motor(13, 11, 15), etc. None of them get the motor to move. Am I missing something? Should I be directly connecting the motor wires to the pins of the motor controller board? Or something else?

5
  • If you want help put details of what YOU did in your question. Don't expect everyone to follow a link and guess what you did. I read the tutorial but it is unclear (at least to me).
    – Milliways
    Mar 21 at 4:09
  • After the link of the tutorial (which I just included in case anyone wanted a reference), I explained exactly how I wired my motor to the motor control board. Then I explained what I included in my code, and everything that I tried. Mar 21 at 4:13
  • The link to the Motorshield for the Raspberry Pi fails to provide any pin details or describe how to connect. WHAT have to ACTUALLY connected?
    – Milliways
    Mar 21 at 5:36
  • 2
    You have hinted at the connections. We need photos. gpiozero uses Broadcom numbers for GPIO. Hint 11/13/15 are not pin numbers.
    – joan
    Mar 21 at 8:20
  • Thank you joan, that was it! Mar 21 at 18:45

3 Answers 3

2

I found out that what needed to be done was to convert Broadcom numbers to GPIO numbers on the Raspberry Pi, as hinted in user joan's comment.

After following this mapping: https://www.raspberrypi-spy.co.uk/2012/09/checking-your-raspberry-pi-board-version/, the code needed to make the motor run was simply:

from gpiozero import Motor

motor1 = Motor(22, 27)

while True:
    motor1.forward()
1
  • 1
    pinout.xyz has an interactive diagram of the RPi.
    – Dougie
    Mar 21 at 21:05
0

You might find the actual gpiozero documentation for motor clearer although Robot might be more appropriate.

0

You have 3-pin controller board so you should initialize your Motor class with enable pin, e.g. for Motor1:

motor1 = Motor(forward=15, backward=13, enable=11)

Since you got the "Motorshield" you may want to have a look at its documentation and TestMotor.py at their GitHub. It uses PyMotor.py form the same repo as a "driver", so you may want to use it as an alternative.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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