Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - RailGun

Pages: 1
1
TinyDuino Processors & TinyShields / TinyShield Motor control question
« on: October 17, 2013, 01:33:51 AM »
Hello,

ive been attempting to control two motors with the TinyShield Motor driver.  The problem ive been running into is that one motor will operate normally while the other moves very slowly or not at all.

I have determined is that the "normally operating" motor can be switched with the one that doesnt operate properly if i swap the output pins in the program.  this leads me to believe that there is some issue with the way i have coded the motor controls.

Note that i am not an expert at coding so i am not sure how to go about adjusting this to make it work properly to control two motors independently.  I feel like it has to do with the way i declared the output pins but im not sure

Code: [Select]
int motoronedir = 4;
int motortwodir = 7;
int motoronepwr = 5;
int motortwopwr = 6; 
int motorSleepPin = A3; // Motor sleep to analog pin 3
int distance = 300; //Change this for distance going forward
int angle = 60; //change if this is not 90 degrees


void setup()
{
pinMode(motoronedir, OUTPUT); // sets the pin as output
pinMode(motortwodir, OUTPUT); // sets the pin as output
pinMode(motoronepwr, OUTPUT); // sets the pin as output
pinMode(motortwopwr, OUTPUT); // sets the pin as output
pinMode(motorSleepPin , OUTPUT); // sets the pin as output

digitalWrite(motoronedir, LOW); // sets the default dir to be forward
digitalWrite(motortwodir, LOW); // sets the default dir to be forward
digitalWrite(motoronepwr, LOW); // sets the default speed to be off
digitalWrite(motortwopwr, LOW); // sets the default speed to be off
digitalWrite(motorSleepPin , HIGH); // sets the sleep mode to be off
}

void loop()
{
//starting delay
digitalWrite(motoronedir, LOW);
digitalWrite(motortwodir, LOW);

analogWrite(motoronepwr, 0);
analogWrite(motortwopwr, 0);
delay(4000);

//Going straight (maybe forward)
digitalWrite(motoronedir, HIGH);
digitalWrite(motortwodir, HIGH);

analogWrite(motoronepwr, 200); //80% speed, change if you want
analogWrite(motortwopwr, 200);
delay(distance);

//Right maybe Left
digitalWrite(motoronedir, LOW);
digitalWrite(motortwodir, LOW);

analogWrite(motoronepwr, 127);
analogWrite(motortwopwr, 127);
delay(angle);

digitalWrite(motoronedir, LOW);  //Giant forward
digitalWrite(motortwodir, HIGH);

analogWrite(motoronepwr, 200); 
analogWrite(motortwopwr, 200);
delay(distance);
analogWrite(motoronepwr, 0);
analogWrite(motortwopwr, 0);
delay(50);
analogWrite(motoronepwr, 200);
analogWrite(motortwopwr, 200);
delay(distance);
analogWrite(motoronepwr, 0);
analogWrite(motortwopwr, 0);
delay(50);
analogWrite(motoronepwr, 200); //80% speed, change if you want
analogWrite(motortwopwr, 200);
delay(distance);
analogWrite(motoronepwr, 0);
analogWrite(motortwopwr, 0);
delay(50);

//Left maybe Right
digitalWrite(motoronedir, HIGH);
digitalWrite(motortwodir, HIGH);

analogWrite(motoronepwr, 127);
analogWrite(motortwopwr, 127);
delay(angle);

digitalWrite(motoronedir, LOW); // forward
digitalWrite(motortwodir, HIGH);

analogWrite(motoronepwr, 200);
analogWrite(motortwopwr, 200);
delay(distance);

//Left maybe Right
digitalWrite(motoronedir, HIGH);
digitalWrite(motortwodir, HIGH);

analogWrite(motoronepwr, 127);
analogWrite(motortwopwr, 127);
delay(angle);

digitalWrite(motoronedir, LOW);  //Giant forward
digitalWrite(motortwodir, HIGH);

analogWrite(motoronepwr, 200); 
analogWrite(motortwopwr, 200);
delay(distance);
analogWrite(motoronepwr, 0);
analogWrite(motortwopwr, 0);
delay(50);
analogWrite(motoronepwr, 200);
analogWrite(motortwopwr, 200);
delay(distance);
analogWrite(motoronepwr, 0);
analogWrite(motortwopwr, 0);
delay(50);
analogWrite(motoronepwr, 200); //80% speed, change if you want
analogWrite(motortwopwr, 200);
delay(distance);
analogWrite(motoronepwr, 0);
analogWrite(motortwopwr, 0);
delay(50);

//Right maybe Left
digitalWrite(motoronedir, LOW);
digitalWrite(motortwodir, LOW);

analogWrite(motoronepwr, 127);
analogWrite(motortwopwr, 127);
delay(angle);

digitalWrite(motoronedir, LOW); // forward
digitalWrite(motortwodir, HIGH);

analogWrite(motoronepwr, 200);
analogWrite(motortwopwr, 200);
delay(distance);


}

Pages: 1
SMF spam blocked by CleanTalk