Updated Mk1 code example (markdown)
@@ -4,13 +4,64 @@ The first thing to do is to grab the 640Mk1 repository (or the https://github.co
|
||||
|
||||
Put the files **Adafruit_I2C.py** and **Adafruit_PWM_Servo_Driver.py** in your project directory (or path), then create a new file and populate it with the following:
|
||||
|
||||
Grab the required modules
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
from Adafruit_PWM_Servo_Driver import PWM
|
||||
|
||||
Grab the required modules
|
||||
Set up the PWM address and frequency
|
||||
|
||||
pwm = PWM( 0x60, debug=False)
|
||||
pwm.setPWMFreq(1600)
|
||||
|
||||
Set up the PWM address and frequency
|
||||
Set up the Motor Driver modes (this will change for Mk2) There is one pin controlling the mode of each of the three drivers.
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(17, GPIO.OUT)
|
||||
GPIO.setup(27, GPIO.OUT)
|
||||
GPIO.setup(22, GPIO.OUT)
|
||||
# set mode to en/phase
|
||||
GPIO.output(17, GPIO.HIGH)
|
||||
GPIO.output(27, GPIO.HIGH)
|
||||
GPIO.output(22, GPIO.HIGH)
|
||||
|
||||
The motor drivers can work in two ways, the default is IN/IN, when the mode pin for the driver is pushed high then it switches to EN/PHASE - both use two signals.
|
||||
|
||||
IN/IN works as follows
|
||||
|
||||
0 - 0 = coast
|
||||
0 - 1 = reverse
|
||||
1 - 0 = forward
|
||||
1 - 1 = brake
|
||||
|
||||
1 = HIGH, 0 = LOW. You can PWM the high values for reverse and forward - so 4095 = full speed, 3000 = slower, etc.
|
||||
|
||||
EN/PHASE is a lot simpler.
|
||||
|
||||
0 - x = coast
|
||||
1 - 0 = forward
|
||||
1 - 1 = reverse
|
||||
|
||||
There is no brake in this mode, using PWM on the Enable (EN) signal allows speed control, the other signal should be full Low or High.
|
||||
|
||||
So, we've switch to EN/PHASE in this example - next set up PWM channels.
|
||||
|
||||
in1 = 5 #phase
|
||||
in2 = 4 #enable
|
||||
|
||||
in3 = 8 #phase
|
||||
in4 = 9 #enable
|
||||
|
||||
in5 = 0 #phase
|
||||
in6 = 1 #enable
|
||||
|
||||
in7 = 2 #phase
|
||||
in8 = 3 #enable
|
||||
|
||||
in9 = 10 #phase
|
||||
in10 = 11 #enable
|
||||
|
||||
in11 = 7 #phase
|
||||
in12 = 6 #enable
|
||||
|
||||
Reference in New Issue
Block a user