I have it working using the python library and running the example.py .
Although this is a good start I want to integrate the shield into a project that is web based and uses cgi files to control the motors. The cgi files contain individual GPIO calls to 4 GPIO pins to control the motors. The command for forward is
I would also like to control the motor driver directly without the library by writing to the GPIO pins directly. I thought this code may work but so far now action.
Rather than rewriting all the web base code can you tell me how to achieve my goal as I am going around in circles
I will most appreciate some help on this.
regards
Max
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(18,GPIO.OUT) // GPIO24 M1DIR
GPIO.setup(22,GPIO.OUT) // GPIO25 M2DIR
GPIO.setup(32,GPIO.OUT) // GPIO12 M1PWM
GPIO.setup(33,GPIO.OUT) // GPIO13 M2PWM
GPIO.output(18,False)
GPIO.output(22,False)
GPIO.output(32,False)
GPIO.output(33,False)
time.sleep(5)
# by selection True and False I should be able to turn on and off the motors
GPIO.output(18,False)
GPIO.output(22,False)
GPIO.output(32,True)
GPIO.output(33,True)
time.sleep(5)
GPIO.output(18,False)
GPIO.output(22,False)
GPIO.output(32,False)
GPIO.output(33,False)
GPIO.cleanup()
Yes, by default forum users should be getting email notifications when their posts get replies. You might try checking your spam folder or white list "inbox@pololu.com", which is the address the forum notifications come from.
I also added the code required to set up the pins into etc/rc.local
gpio -g mode 23 out
gpio -g mode 24 out
gpio -g mode 25 out
gpio -g mode 12 out
gpio -g mode 13 out
gpio -g mode 22 out
It is all working well.
However when I call the cgi scripts as the pin is controlled by a true or false the motor when triggered comes on at 100%.
I would like to use the PWM functionality that is built into the motor driver shield.
I know the raspberry pi has 1 pwm pin which is physical pin 12 and GPIO 18
Can you give me an idea how to achieve this with wiringPi.
You should be able to run man gpio on your Raspberry Pi to see a list of options for the gpio utility. It looks like you can use the mode subcommand to change the pin to PWM mode, and then use pwm to set the duty cycle. If that works, you should also try using pwmr to get a PWM frequency of 20 kHz. You might find this video useful, too.
Can you describe how your code is not working? Can you verify that you are actually running your code in /etc/rc.local after making your edits? (Note that you will probably have to reboot.) Also, do you have access to an oscilloscope?
Every time I change the code in rc.local I do reboot
First I run the non pwm versions of the cgi files and all is fine. The motors spin. I have a number of cgi files for forward backward etc and all work as desired
when I change the code in rc.local and in the cgi files and run the programs all I get is a very slight click. but no spinning. May be I need to also configure some other aspect like the frequency
hope this helps
So long as your connections have remained the same, it does sound like there is an issue with generating PWM signals. I recommend using an oscilloscope to look at the output of those PWM pins to see what is happening there.