From ac308127b0998b4140b536db127e588bba5035ae Mon Sep 17 00:00:00 2001 From: shrkey Date: Tue, 16 Feb 2016 14:43:27 +0000 Subject: [PATCH] Updated Mk1 code example (markdown) --- Mk1-code-example.md | 55 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/Mk1-code-example.md b/Mk1-code-example.md index 879fb64..e078681 100644 --- a/Mk1-code-example.md +++ b/Mk1-code-example.md @@ -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 + \ No newline at end of file