![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVHynAWH1tKa0aP7hyphenhyphenIlFMeIhYfiVBTaSVoeXDQWOZdcV74SAuLh5VB8hSWXm3oJZVnbaNSB8afd_eVAgrVqKuYC7AHb9M-YB2oNxhDMebbl0kL1NenwkPEXxQ2JN855pDNExVHZlxYTrR/s200/Propulsion2.jpg)
Speed is controlled by the PWM pin and takes a value of 0 to 255. Direction is set by a digital high or low. I have not gotten the current feedback to work yet but the documentation says it should be read on the processors "analog to digital (ADC) inputs". I am not sure what exactly that means but I am not getting anything on the pins that I have tried to date though I am not losing sleep about it at the moment.
Code for running a test on the left motor is shown below. Note that this code is based on my Python to Arduino Interface but the commands, less error handling, are 1-1 analogous to what you would code in Arduino directly.
import time
from Py2Ard import interfaceClass
# Specify the port as an argument
my_board = interfaceClass('/dev/ttyUSB0')
leftMotorDir = 26
leftMotorSpeed = 7
print "Setting Pin Mode for Speed"
if my_board.pinModeOutput(leftMotorSpeed) == -1:
print "Error" + my_board.extraReturn
print "Setting Pin Mode for Direction"
if my_board.pinModeOutput(leftMotorDir) == -1:
print "Error" + my_board.extraReturn
print "Commanding Direction Forward"
if my_board.setHigh(leftMotorDir) == -1:
print "Error" + my_board.extraReturn
print "Commanding Speed of 100"
if my_board.pwmWrite(leftMotorSpeed, 100) == -1:
print "Error" + my_board.extraReturn
time.sleep(2)
print "Commanding Direction Backward"
if my_board.setLow(leftMotorDir) == -1:
print "Error" + my_board.extraReturn
print "Commanding Speed of 100"
if my_board.pwmWrite(leftMotorSpeed, 100) == -1:
print "Error" + my_board.extraReturn
time.sleep(2)
print "Commanding Stop"
if my_board.pwmWrite(leftMotorSpeed, 0) == -1:
print "Error" + my_board.extraReturn
No comments:
Post a Comment