TreX and Arduino

looking for some advice for coding for the TreX. I am using an arduino, that will eventually take in many data points from various sensors and decide how to move the bot, but as of yet I am just trying to get the speed commands to work. Below is the code. Any and all advice would be of great help.

void put(unsigned int m1, unsigned int m2){
  //we use the put command to set the speed of the motors
  Serial.print(0x80,BYTE); //start byte
  Serial.print(0x07,BYTE); //device id, standard for TreX
  Serial.print(0xD0,BYTE); //command number 
  Serial.print(m1,BYTE); //m1 speed
  Serial.print(m2,BYTE); //m2 speed

void setup() {
  Serial.begin(19200); //1920 being the standard for the TreX

void loop() {

  put(127,127); // just trying to see if I can get it to work here. 127 being a speed.
  delay(1000); // delaying a second
  put(100,100); //trying a different speed


Hey Justin,

There are a few problems with your code:

  1. When using the Pololu/Expanded protocol, you need to make sure that all bytes after the 0x80 have their most significant bits cleared (i.e. they need to be less than 128). For example, if your compact protocol command is:

0xD0, 0x7F, 0x7F

The Pololu protocol version is:

0x80, 0x07, (0xD0 - 128), 0x7F, 0x7F

which becomes

0x80, 0x07, 0x50, 0x7F, 0x7F

  1. The TReX motor command byte contains bits that specify the motor directions. Command 0xD0 sets all these direction bits to zero, which means you’re requesting full brake from the motors (this is why you aren’t seeing the motors do anything). If you want to set motor 1 full speed forward (and motor 2 full brake), you want to use command:

0xD2, 0x7F, 0x7F (or Pololu command 0x80, 0x07, 0x52, 0x7F, 0x7F)

I recommend you use the compact commands unless you are planning on having multiple Pololu motor controllers on a single serial line. I also recommend you read over the TReX command documentation so that you understand which bits of the command bytes affect motor direction. Specifically, start with the documentation for commands 0xC0 - 0xC3 and 0xC8 - 0xCB (the Set Motor 1 and Set Motor 2 commands). If the documentation isn’t clear, please let me know and I’ll try to clarify it.

- Ben