To best describe usage of the 640 Mk1 board, I'll paste the test script I put together and go through each section (Mk2 will be different to this, slightly).
The first thing to do is to grab the 640Mk1 repository (or the https://github.com/adafruit/Adafruit-Motor-HAT-Python-Library) - the code in the main class isn't complete yet (or tested / debugged) but we're primarily after the Adafruit I2C and PWM modules for this example.
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
Set up the PWM address and frequency
pwm = PWM( 0x60, debug=False)
pwm.setPWMFreq(1600)
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 switched 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
Now set the all to coast to start
pwm.setPWM(in1,0,0)
pwm.setPWM(in2,0,0)
pwm.setPWM(in3,0,0)
pwm.setPWM(in4,0,0)
pwm.setPWM(in5,0,0)
pwm.setPWM(in6,0,0)
pwm.setPWM(in7,0,0)
pwm.setPWM(in8,0,0)
pwm.setPWM(in9,0,0)
pwm.setPWM(in10,0,0)
pwm.setPWM(in11,0,0)
pwm.setPWM(in12,0,0)
time.sleep(10)
Set to Full speed forward
print "Set forward"
pwm.setPWM(in1,0,0)
pwm.setPWM(in2,0,4095)
pwm.setPWM(in3,0,0)
pwm.setPWM(in4,0,4095)
pwm.setPWM(in5,0,0)
pwm.setPWM(in6,0,4095)
pwm.setPWM(in7,0,0)
pwm.setPWM(in8,0,4095)
pwm.setPWM(in9,0,0)
pwm.setPWM(in10,0,4095)
pwm.setPWM(in11,0,0)
pwm.setPWM(in12,0,4095)
time.sleep(5)
Stop / Coast
print "Set stop"
pwm.setPWM(in1,0,0)
pwm.setPWM(in2,0,0)
pwm.setPWM(in3,0,0)
pwm.setPWM(in4,0,0)
pwm.setPWM(in5,0,0)
pwm.setPWM(in6,0,0)
pwm.setPWM(in7,0,0)
pwm.setPWM(in8,0,0)
pwm.setPWM(in9,0,0)
pwm.setPWM(in10,0,0)
pwm.setPWM(in11,0,0)
pwm.setPWM(in12,0,0)
time.sleep(5)
Reverse
print "Set reverse"
pwm.setPWM(in1,0,4095)
pwm.setPWM(in2,0,4095)
pwm.setPWM(in3,0,4095)
pwm.setPWM(in4,0,4095)
pwm.setPWM(in5,0,4095)
pwm.setPWM(in6,0,4095)
pwm.setPWM(in7,0,4095)
pwm.setPWM(in8,0,4095)
pwm.setPWM(in9,0,4095)
pwm.setPWM(in10,0,4095)
pwm.setPWM(in11,0,4095)
pwm.setPWM(in12,0,4095)
time.sleep(5)
Stop again
print "Set stop"
pwm.setPWM(in1,0,0)
pwm.setPWM(in2,0,0)
pwm.setPWM(in3,0,0)
pwm.setPWM(in4,0,0)
pwm.setPWM(in5,0,0)
pwm.setPWM(in6,0,0)
pwm.setPWM(in7,0,0)
pwm.setPWM(in8,0,0)
pwm.setPWM(in9,0,0)
pwm.setPWM(in10,0,0)
pwm.setPWM(in11,0,0)
pwm.setPWM(in12,0,0)
time.sleep(5)
Cleanup our pins
# cleanup
GPIO.cleanup()
The library (once complete) will make this a lot simpler as we'll just have to set the mode and the speed for the motor without messing with pins, etc.