TReX Jr. and Arduino Uno Serial Communication Problems

Hello, I am doing a project involving:

2x TRex Jr. Motor Drivers
2x Arduino Uno R2
2x Pololu item 1551: Dagu Rover 5 Tracked Chassis with Encoders

And am having trouble getting the TReX Jr’s to work properly after having them work just a few days earlier.

The TReX are set for serial communication, with all the jumpers taken out except the BEC Jumper.

The setup is that the TReX Jr is wired from the rx, tx, and g to the arduino pins 4, 5, and ground respectively. The TReX is then powered by the 6xAA battery case supplied with the tracked chassis, whose DC motors are hooked up to the TReX Jr.

I’ve tried mixing and matching between Arduinos, Motor Drivers, Chassis, and wires nothing seems to affect that it all suddenly stopped working.

The code used is:

#include <SoftwareSerial.h>
#define txPin 4
#define rxPin 5

SoftwareSerial pololu(rxPin, txPin); //send recieve
void setup()
{
 // Define the appropriate input/output pins
 pinMode(rxPin, INPUT);
 pinMode(txPin, OUTPUT);
 
 // Begin communicating with the pololu interface
 Serial.begin(9600);
 pololu.begin(19200);
} 

void loop()
{
 // Loop through 127 to 0, forward
 for(int i = 127; i >= 0; i--)
 {
   // Say that we are setting our speed
   Serial.print("Setting speed to: ");
   Serial.println(i, DEC);
   
   // Set speed to motor 0 and forward
   SetSpeed(0, true, i);
   delay(100);
 }
 
 // Loop through 0 to 127, backward
 for(int i = 0; i < 128; i++)
 {
   // Say that we are setting our speed
   Serial.print("Setting speed to: ");
   Serial.println(i, DEC);
   
   // Set speed to motor 0 and forward
   SetSpeed(0, true, i);
   delay(100);
 }
} 

void SetSpeed(int MotorIndex, boolean Forward, int Speed)
{
  // Validate motor index
 if(MotorIndex < 0 || MotorIndex > 1)
   return;
 
 // Validate speed
 if(Speed < 0)
   Speed = 0;
 else if(Speed > 127)
   Speed = 127;
 
 // Send the "set" command based on the motor
 // Note that we do not accelerate to the
 // speed, we just instantly set it
 unsigned char SendByte = 0;
 if(MotorIndex == 0)
   SendByte = 0xC2;
 else if(MotorIndex == 1)
   SendByte = 0xCA;
 
 // If we go backwards, the commands are the same
 // but minus one
 if(!Forward)
   SendByte--;
 
 // Send the set speed command byte
 pololu.write(SendByte);
 
 // Send the speed data byte
 pololu.write(Speed);
}

It was working fine up until yesterday, and now I can’t figure out what’s wrong. I have already tried restoring factory defaults for serial communication and it has not done anything. Any help would be greatly appreciated.

Hello.

So you are saying both TReX Jrs were initially working, and then, at the same time, both independently stopped working? Can you describe exactly what you were doing right before they stopped working? Did you change your program or rewire your system? Also, can you more explicitly describe the connections between your Arduino and your TReX Jr (you mention rx and tx, but the pins labeled “RX” and “TX” on the TReX Jr are for RS-232 serial; you should be connecting the Arduino to the “SO” and “SI” pins).

Also, do you have access to a USB-to-serial adapter? If so, you could try controlling the boards directly from your computer to rule out an Arduino software problem.

- Ben