Go Down

Topic: Pololu TREX motor controller and Arduino problem (Read 488 times) previous topic - next topic

David82

I Can send data to the TREX but don't get any motor LED response

Blue solid, red solid and green flashing but no motor LED activity

all jumpers removed except +=Vcc, and mix

Problem is likely with the code but the code is real simple and should work.. Anyone worked with these enough to know what might be happening?




Code: [Select]

// Included for serial communication
#include <SoftwareSerial.h>

// Define pins you're using for serial communication
// Do not use pins 0 or 1 as they are reserved for
// standard I/O and programming
#define TXPIN 4
#define RXPIN 5

// Create an instance of the software serial
// communication object. This represents the
// interface with the TReX Jr device
SoftwareSerial pololu(RXPIN, TXPIN);

// Main application entry point
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);
  delay(5);
}

// Main application loop
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 0 to: ");
    Serial.println(i, DEC);

    // Set speed to motor 0 and forward
    SetSpeed(0, true, i);
    delay(100);
   
    // Say that we are setting our speed
    Serial.print("Setting speed 1 to: ");
    Serial.println(i, DEC);

    // Set speed to motor 0 and forward
    SetSpeed(1, true, i);
    delay(10);
  }

  // Loop through 0 to 127, backward
  for(int i = 0; i < 128; i++)
  {
    // Say that we are setting our speed
    Serial.print("Setting speed 0 to: ");
    Serial.println(i, DEC);

    // Set speed to motor 0 and forward
    SetSpeed(0, true, i);
    delay(100);
   
    // Say that we are setting our speed
    Serial.print("Setting speed 1 to: ");
    Serial.println(i, DEC);

    // Set speed to motor 0 and forward
    SetSpeed(1, true, i);
    delay(100);
  }
}

// Set the motor index, direction, and speed
// Motor index should either be a 0 or 1
// Direction should be either true for forward or false for backwards
// Speed should range between 0 and 127 (inclusivly)
void SetSpeed(int MotorIndex, boolean Forward, int Speed)
{
  // Validate motor index
  if(MotorIndex < 0 || MotorIndex > 2)
    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;
  else if(MotorIndex == 2)
    SendByte = 0xF0;

  // If we go backwards, the commands are the same
  // but minus one
  if(!Forward)
    SendByte--;

  // Send the set speed command byte
  //pololu.write(SendByte);
  pololu.write(SendByte);
 

  // Send the speed data byte
  pololu.write(Speed);
}


dc42

You are trying to power the Trex from the Arduino's 5V supply. There are 2 problems with this. First, the Arduino +5V line can probably not provide enough current to start the motor. Second, the Trex is specified for a supply of 6V minimum.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.


Go Up