Pololu TRex DMC01 Analog signal with Arduino Mega

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 :

  1. When the potentiometer increased (can be as low as the value of 9), both motors red indicator LED were solid on.
  2. When the potentiometer increased further (~497), only motor 1 red indicator LED remained solid on.
  3. 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.
  4. 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);    

}

Hi and welcome.

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 ?

Hi

Thanks for pointing that out, i just noticed.

so if i change it to this?

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.

so if i change it to this?

Why are you now writing two different values to each pin?

It would make sense to me to write the mapped values (once each) to the two pins.

A link to the device(s) in question would not be amiss. Some explanation as to how they are connected would be good, too.

Hi. sorry for the late reply. I've been trying to troubleshoot but it still fails.

to answer your question, 0xC2 and 0xCA were taken from pololu trex command documentation.
[

](ftp://http://www.pololu.com/file/0J1/TReX_Commands_v1.2.pdf)

Motor Commands:
? 0xC0 – 0xC3: Set Motor 1
? 0xC4 – 0xC7: Accelerate Motor 1
? 0xC8 – 0xCB: Set Motor 2
? 0xCC – 0xCF: Accelerate Motor 2

Those "motor commands" are not PWM values to write to some pins. They are values to send to the device via a serial port.

Thanks for making it all clear to me. Now i know those commands are of no use in my code. I shall try again.