Unfortunately there aren't really tutorials to get this thing running with the Raspi. So I got to work myself.
I started by testing if the motor works if I hook it up directly to the battery. That works fine.
Then I had a good look at the H-bridge. There are 4 big wire inputs, marked with B-, B+, M+ and M-
From this tutorial I understand that the B and the M stand for Battery and Motor. So I hooked them up to my battery and motor.
Furthermore, there are 8 small pins on the H-bridge, which are
From this diagram I found that the left two (VCC and GND) are 5V power supply and ground. So I hooked them up to a 5V and ground pin on my Raspi.
Code: Select all
VCC R_IS R_EN RPWM GND L_IS L_EN LPWM
And from this point on it gets tricky. I guess that:
- R_EN and L_EN are used to ENable the motor to turn Right or Left (correct?)
- RPWM and LPWM are used to determine the motor speed using Pulse-width modulation (correct?)
- I have no idea what R_IS and L_IS are for. Does it have something to do with measuring current flowing through?
So if the above is true. I suppose that I can hook up R_EN to a normal GPIO pin and write HIGH to it and at the same time send a 100% pulse width to RPWM to get it to turn right.
Following this logic I hooked up the wires as follows:
and then wrote the following code:
Unfortunately, nothing happens, at all. No errors, no movement, nothing.
Code: Select all
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) R_EN = 11 RPWM = 12 GPIO.setup(R_EN, GPIO.OUT) GPIO.setup(RPWM, GPIO.OUT) GPIO.output(R_EN, True) p = GPIO.PWM(RPWM, 100) # inspired by https://sourceforge.net/p/raspberry-gpio-python/wiki/PWM/ try: while True: p.start(100) # duty cycle of 100% except KeyboardInterrupt: pass p.stop() GPIO.cleanup()
So I've been trying about a zillion combinations with code and wires, including using WiringPi with Python bindings. And I saw it moving once, for just a fraction of a second. But despite the effort I put into reproducing what I did, it never moved again. I checked the battery directly on the motor again, and that still works, so my battery is still alive.
So from here I'm kinda lost. Since I'm more of a software man I don't really know how to debug hardware.
Can any brighter mind than me give me some tips and hints on what I'm doing wrong or how I can debug this? All tips are welcome!