Hello, i'm new and weak in programming. The aim of my project is to drive 2 dc motors (just forward as a start). Using Arduino mega to provide analog inputs (potentiometer) to channel 1 & 2 of my pololu TRex dmc01, . i managed to get past "safe-mode" of the Pololu TRex. The main problem i face is how do i write the motor commands in my program? Eg : 0xC0,0xC8.
The results i am getting so far with the code and wiring connections shown below :
When the potentiometer increased (can be as low as the value of 9), both motors red indicator LED were solid on.
When the potentiometer increased further (~497), only motor 1 red indicator LED remained solid on.
When fully increased(1023), Only motor 1 red and yellow indicator LED was rapidly blinking. Only DC motor 1 was vibrating slightly and produced a slight noise.
Both DC motors failed to move
any help will be appreciated. thanks
int potPin = A1; //middle pin of potentiometer is connected to
int motorPin1 = 9; //channel 1 of TRex is connected to
int motorPin2 = 10; //channel 2 of TRex is connected to
int potValue = 0;
int motorValue1 = 0x0;
int motorValue2 = 0x0;
void setup()
{
Serial.begin(19200);
delay(100);
}
void loop()
{
potValue = analogRead(potPin);
motorValue1 = map(potValue, 0, 1023, 0x0, 0x7F);
motorValue2 = map(potValue, 0, 1023, 0x0, 0x7F);
Serial.write(0xC2); //forward motor 1
Serial.write(0x7F); //fullspeed
Serial.write(0xCA); //forward motor 2
Serial.write(0x7F); //fullspeed
Serial.print("potentiometer = " );
Serial.print(potValue);
Serial.print("\t motorPin1 = ");
Serial.println(motorValue1);
Serial.print("\t\t motorPin2 = ");
Serial.println(motorValue2);
delay(100);
}
It's probably me (lack of Mega knowledge ?) , but what are you doing in this code ?
I can see you are declaring some variable to point to "analog" output pins 9 and 10 which also are connected according to your drawing.
Then you get a potentiometer value, map it to a 7 bits value and send that out to serial.
You are doing nothing with pins 9 and 10 as far as i can see, you're not controlling pins 9 and 10 at all.
Maybe you could tell us what you expect this code to do ?
analogWrite(motorPin1, 0xC2); //forward motor 1
analogWrite(motorPin1, 0x7F); //fullspeed
analogWrite(motorPin2, 0xCA); //forward motor 2
analogWrite(motorPin2, 0x7F); //fullspeed
Nothing happened either. I just want to get the dc motors to move forward as a start. Basically, i am currently doing an auto-docking robot. i already programmed Pololu IR transceiver and SRF08 ultrasonic sensors individually. Once i can get my motors to move, i believe i could make it work with the 2 sensors i mentioned for docking.