Z Looking Glass: Project SmartSurfaces

A insider's observation of Project SmartSurface

Pololu Motor Controller: Finally, it works with Arduino December 19, 2009

Filed under: Uncategorized — zilinzen @ 2:46 pm

Thanks to those pros on Pololu Forum, I got both both dual and single motor controller board working. There is also a trick I found in order to get Pololu High-Power Motor Driver 18v15 working: set RESET pin as OUTPUT and held it HIGH in your Arduino code.

Here is one of my sample code (along with several functions written specifically for one type of motion) that allows you to control DC motors’ speed live with serial monitor in Arduino

int DIR = 8;
int Mono_PWM = 9;  //PWM1 connects to pin 9
int Reset = 7;
int Mono_PWM_val = 255; //(25% = 64; 50% = 127; 75% = 191; 100% = 255)
int t = 5000;

void setup() {
 Serial.begin(9600);
 pinMode(DIR, OUTPUT);
 pinMode(Mono_PWM, OUTPUT);
 pinMode(Reset, OUTPUT);
 digitalWrite(Reset, HIGH); //When held low, mono board goes to sleep

 Serial.println("Mono Motor Controller Live Control");
 Serial.println("Enter speed number 0-9:");
}

void Mono_Forward(int PWM_Pin, int PWM_val, int DIR_Pin) {
 //Forward: PWM = H && DIR = L;
 analogWrite(PWM_Pin, PWM_val);
 digitalWrite(DIR_Pin, LOW);
}

void Mono_Backward(int PWM_Pin, int PWM_val, int DIR_Pin) {
 //Backward: PWM = H && DIR = H;
 analogWrite(PWM_Pin, PWM_val);
 digitalWrite(DIR_Pin, HIGH);
}

void Mono_Live_Forward(int PWM_Pin, int DIR_Pin) {
 Mono_PWM_val = Serial.read();
 if(Mono_PWM_val >= '0' && Mono_PWM_val <= '9') {
 Mono_PWM_val = 28*(Mono_PWM_val - '0');
 Serial.print("Setting Mono_Motor speed to ");
 Serial.println(Mono_PWM_val);    
 //Warning: forward function must include inside the if loop
 //otherwise the motor will not be controlled.
 Mono_Forward(PWM_Pin, Mono_PWM_val, DIR_Pin);        
 Serial.println("Enter speed number 0-9:");
 }
}

void Mono_Live(int PWM_Pin, int DIR_Pin, char Direction) {
 Mono_PWM_val = Serial.read();
 if(Mono_PWM_val >= '0' && Mono_PWM_val <= '9') {
 Mono_PWM_val = 28*(Mono_PWM_val - '0');
 Serial.print("Setting Mono_Motor speed to ");
 Serial.println(Mono_PWM_val);    
 //Warning: forward function must include inside the if loop
 //otherwise the motor will not be controlled.
 if(Direction == 'f') {  // logic == means equal!
 Mono_Forward(PWM_Pin, Mono_PWM_val, DIR_Pin);   
 Serial.println("moving forward");
 }
 if(Direction == 'b') {
 Mono_Backward(PWM_Pin, Mono_PWM_val, DIR_Pin);
 Serial.println("moving backward");
 }
 Serial.println("Enter speed number 0-9:");
 }
}

void loop() {
 //Mono_Live_Forward(Mono_PWM, DIR);
 //Mono_Live(Mono_PWM, DIR, 'f');
 //Mono_Live(Mono_PWM, DIR, 'b');
 /*
 Mono_Forward(Mono_PWM, Mono_PWM_val, DIR);
 delay(t);
 Mono_Backward(Mono_PWM, Mono_PWM_val, DIR);
 delay(t);
 */
}
Advertisements
 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s