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”. The main problem i face is how do i write the motor commands in my program? Eg : 0xC0,0xC8.

wire connections:
Potentionmeter : (middle pin to a breadboard which is in series with a wire connected to A1 and 2 wires to channel 1 & 2 of pololu , +5 and ground)

Pololu : Channel 1 to pin 9 of arduino mega, channel 2 to pin 10, channel 3 to channel 1(unused motor channel), channel 4 and 5 connect to Vcc 5V(unused channels)

any help will be appreciated. thanks


int potPin = A1;
int motorPin1 = 9;
int motorPin2 = 10;
int potValue = 0;
int motorValue1 = 0xC0;
int motorValue2 = 0xC8;



void setup()
{
Serial.begin(9600);
delay(100);

}


void loop()
{
  
  potValue = analogRead(potPin);  
 motorValue1 = map(potValue, 0, 1023, 0, 127);
 motorValue2 = map(potValue, 0, 1023, 0, 127); 

if (motorValue1 == 127)
{
Serial.write(0xC4); //forward motor 1
Serial.write(0x7F); //fullspeed

}
else
{
Serial.write(0xC0);
}


if (motorValue2 == 127)
{
Serial.write(0xCC); //forward motor 2
Serial.write(0x7F); //fullspeed
}
else
{
Serial.write(0xC8);
}


 Serial.print("potentiometer = " );     
 Serial.print(potValue);
 Serial.print("\t motorPin1 = ");
 Serial.println(motorValue1);
 Serial.print("\t\t motorPin2 = ");
 Serial.println(motorValue2);
 delay(100);    

}


 

Hello.

It seems like your code has a limited range for when it will send commands the TReX to change the speed of your motors; the code only commands the motors to go full speed when the potentiometer is exactly the value of 127. You might try changing your code so it responds to a range of values. You also do not send a byte containing the speed after you send the motor commands in the else statements. If you change those and continue to have problems, could you post a wiring diagram and pictures of your setup? Could you also let me know what behavior you are getting and what behavior you expect to get?

- Grant

Hi Grant.

If i want to remove the limited range of my motors, i just have to delete “if and else” statements right?

I did amend the mistakes you pointed out and these are the results i get :

  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.

My aim is just to get both motors to move, be it in full speed or not.

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);    

}


 

Looking at your picture, it looks like the jumpers on the TReX are set for analog mode; however, it looks like your code is trying to send the TReX serial commands. Also, it is very difficult to follow the wires in your picture, but it looks like there are potentially several connection issues. Could you post a diagram or schematic of what you are trying to accomplish?

- Grant

Hope this image is better. Not inclusive of 2 DC motors wires, One power source to supply Trex and Arduino Mega.

Notes: MIX and BEC jumpers are removed. Therefore, middle column of the 5 channels are not connected to anything.
TRex is in Analog mode.

If my code was trying to send Trex in serial command, how do i do it in analog mode then? I solely want to control my robot in analog only.

It sounds like you are trying to control the TReX using a potentiometer. You can directly connect the potentiometer to the TReX and remove the Arduino Mega from your setup. The signal from your potentiometer should go to the corresponding TReX motor channel you want to control. You can find more information about this in the “Signal Connections” sections of TReX user’s guide. You might also find the “RC/Analog in Detail” section helpful for controlling the TReX directly with an analog input.

Was there a particular reason you were trying to integrate the Arduino Mega with your setup?

- Grant

I am trying to make an Auto-Docking robot. I already programmed my Pololu IR Transceiver and ultrasonic SRF08 sensor.

So my ultimate goal is to use Arduino mega as a middle platform for communications between Trex and those two sensors i mentioned.

To get started, I suggest getting the TReX to work in analog mode with just the potentiometer like I mentioned in my last post. Once you get that working, you might try switching to serial control with the Arduino Mega.

- Grant