C.Han
Posts: 2
Joined: Thu Jan 24, 2019 6:26 pm

Motors not moving (Alphabot )

Thu Jan 24, 2019 6:35 pm

I got a AlphaBot by Waveshare. Wrote a simple code but the motors just wont move.

Code: Select all

import RPi.GPIO as gpio
import time

gpio.setmode(gpio.BOARD)

gpio.setup(12, gpio.OUT)
gpio.setup(21, gpio.OUT)

gpio.output(12, True)
gpio.output(21, True)
time.sleep(2)

gpio.cleanup()
the connection is of following:
Image

pcmanbob
Posts: 9612
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Motors not moving (Alphabot )

Thu Jan 24, 2019 7:44 pm

Hi.

First off you image does not show up, try uploading it to an image sharing site and then post a link to it instead.

As your code is using board numbering are you sure you are using the correct pins.

Image

so the pin numbers are to 2 columns in the middle.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
Burngate
Posts: 6313
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Motors not moving (Alphabot )

Fri Jan 25, 2019 10:08 am

Managed to extract your image and have posted it here, reduced in size.
hwhsrTib.png
hwhsrTib.png (50.06 KiB) Viewed 570 times
It doesn't say in that, but since it uses P6 for ENA, and board pin 6 is ground, I guess they're using BCM numbering.

pcmanbob
Posts: 9612
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Motors not moving (Alphabot )

Fri Jan 25, 2019 12:02 pm

So using the information form your image you need to connect the motor driver board like this.

Image

included a ground connection as but this may already be included in another part of the circuit.

Then to drive the motors you need to set the direction using IN1 - IN4 then enable them using ENA, ENB

so the code could look like this

Code: Select all

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(12, GPIO.OUT) # IN1
GPIO.setup(13, GPIO.OUT) # IN2
GPIO.setup(6, GPIO.OUT)  # ENA
GPIO.setup(20, GPIO.OUT) # IN3
GPIO.setup(21, GPIO.OUT) # IN4
GPIO.setup(26, GPIO.OUT) # ENB

# set direction
GPIO.output(12, HIGH
GPIO.output(13, LOW)
GPIO.output(20, HIGH)
GPIO.output(21, LOW)

# enable motors
GPIO.output(6, HIGH)
GPIO.output(26, HIGH)

# run motors for 10 seconds
time.sleep(10)

# stop motors
GPIO.output(6, LOW)
GPIO.output(26, LOW)


GPIO.cleanup()
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Return to “Python”