Hi all , I have purchased a few of your products and I am very happy with the products and service supplied. Thankyou for that.
Briefly, I am trying Robotics for the first time.Very little knowledge. I have built a 3d printer , now getting good prints, I would like go a little further for the grandkids.
My problem with the DRI0044 is connecting to RPi.
I can find lots about Motor Drivers with 3 outputs.
The DRI0044 only has 2 outputs
PWM1 , DIR1 and
PWM2 , DIR2
I know ‘GPIO.setup(m1A, HIGH/LOW)’ etc , how is HIGH and LOW set with one pin.
I see some info re - DFduino UNO , but not having any luck with the code.
I hope you can help with some info /diags or other suggestions.
PWMx and DIRx are inputs. The outputs are Mx+ and Mx-.
So you would connect the RPi PWM pin to the relevant PWM input on the DRI004. Then either tie the matching DIR input high or low if the direction is fixed, or connect it to a digital output pin of the RPi so that the software controls the direction.
Using RPi 3
I have a GPIO(17) pin connected to PWM1
I have a GPIO(27) pin connected to DIR1
I’m not sure what you mean here,
“Then either tie the matching DIR input high or low if the direction is fixed, or connect it to a digital output pin of the RPi so that the software controls the direction.”
Sorry if it’s a dumb question, are you saying,
connect m+ and m- GPIO output pins from RPi to DIR1
i.e. splice 2 leads into 1 ? say GPIO22 & GPIO27 to DIR1
Doesn’t sound right , but that’s only lack of knowledge.
I’ve got plenty of dumb questions.
I have one motor turning and can change speed but only one direction.
Here’s my code;
import RPi.GPIO as GPIO
from time import sleep
PWD1 = 17
DIR1 = 27
pwmA = GPIO.PWM(DIR1,100);
## This runs
sorry for being long winded.
Longwinded is sometimes good - especially if unclear! The only dumb question is the one that’s not asked. And actually, you’re pretty concise.
When he says to tie Dir High or Low, he means connect the Direction input directly to either the positive voltage or ground, respectively. Doing this would mean your motor always turned in the same direction.
If you want to be able to choose which direction your motor spins, you need to connect the Dirx pin to a GPIO pin on the Pi, and control it that way.
The M+ and M- pins connect to your motor (definitely don’t connect them to your Pi!).
If you’re running that script, connecting GPIO 17 to PWM1 and GPIO27 to DIR1 is the right thing to do.
I assume this script is an example you’ve copied from somewhere, so I’ve added some comments to your script to explain what it’s doing:
import RPi.GPIO as GPIO #import library so you can control the GPIO pins
from time import sleep #import the sleep() function, so you can tell the Pi to pause for a bit.
GPIO.setmode(GPIO.BCM) #this sets the numbering convention for your Pi pins to the numbering on the physical chip (as opposed to the pin number on the 40pin header they're conected to - see https://pinout.xyz )
GPIO.setwarnings(False) #This disables warnings (because this program doesn't exit correctly, so it will throw warnings!) See this page on how to exit correctly: http://raspi.tv/2013/rpi-gpio-basics-3-how-to-exit-gpio-programs-cleanly-avoid-warnings-and-protect-your-pi
#Makes code more maintainable and readable by using variables instead of using the actual Pin numbers everywhere - you can just change these lines to reassign the pins and it will propagate through your code.
PWD1 = 17
DIR1 = 27
# set the pins connected to PWD1 and DIR1 to be outputs (configures resistors internally, makes these pins low impedance (resistance)).
#The following line does two things - 1. Creates an instance of a 'GPIO' object called 'pwmA' and
# and 2. Prepares the DIR1 pin to output a PWM signal with a carrier or base frequency of 100Hz
pwmA = GPIO.PWM(DIR1,100);
pwmA.start(0); #This line puts the configuration into action so DIR1 will actually start outputting the PWM, and sets the duty cycle to 0%
pwmA.ChangeDutyCycle(5); #This line changes the duty cycle of DIR1 to 5% (I'm not sure why, as DIR1 should only ever be on or off ie. 100% or 0%).
#Changes DIR1 to output 3.3v
sleep(2) #Tells the Pi to sleep for 2 seconds (all the while DIR1 pin is still high)
pwmA.ChangeDutyCycle(0); #Sets the Dutycycle of DIR1 to 0% (aka, off or 0v)
GPIO.output(DIR1,GPIO.LOW) #Does the same thing as the line above.
Thanks for making a post on our forums
Looks like @Jeff105671 and @Oliver33 have done a fantastic job of answering your questions (thanks guys, it’s great to see the community helping each other out!), but was there anything else you’d like further clarification on?
Thank you Oliver33,
yes , getting great help from these Forum members. Gives me confidence.
Many thanks to you Oliver,
You obviously spent a deal of time on your reply, very much appreciated. It has given me more understanding of the pin/output setup.
The script, I put together with a lot of search and trial and error. A bit of fun . The script ,obviously runs 1 motor. I have expanded it to run 2 motors, it runs fine, I can start and stop the motors as a pair, haven’t tried as single yet. ie 1 on & 1 off
I understand ,controls the speed of the motor (0% - 100%), I have 5% set here. When I have changed the value to 20/40/60%, the motor speed changes ok.
All this happens in only 1 direction,
and stopped -
How do I write script to be able to reverse direction without another
LOW A lot of,you guessd it ,Trial and Error has been tried.
I thought I might be able to have an
input() to select the
f = GPIO.setup(GPIO.HIGH)
r = GPIO.setup(GPIO.LOW)
but ran into some errors.
I hope all this makes sense
I’m not having much success yet , so grateful for any help or directions. ( I had to have a time out yesterday, went fishing. )