The Trex Jr. Motor controller is versatile in the sense that it allows you to define easily which pins to use to receive and send commands. The Trex Jr. relies on sending byes of data back and forth between the arduino and the controller via the physical serial port of the arduino and a software serial port of the Trex Jr.
To hook it up, you will use the TTL (SI and SO pins) of the Trex jr. (most likely). The SI pin is the recieve pin of the controller and is connected to the pin that is defined as RX on the arduino (pin 5 in my example code). The SO is the transmit pin and it gets connected to the TX pin of the arduino (pin 4 in my example). Also the grounds need to be connected between the controllers.
Trex Jr. pin connection |
SI ->TX (Arduino pin 4) and SO -> RX (Arduino pin 5) |
Code:
//Pololu Trex Jr.
#include SoftwareSerial.h //add <> around software serial.h
#define TXPIN 4
#define RXPIN 5
SoftwareSerial pololu(RXPIN, TXPIN);
void setup() {
pinMode(RXPIN, INPUT);
pinMode(TXPIN, OUTPUT);
Serial.begin(9600);
pololu.begin(19200); //Trex jr. Serial port
}
void loop() {
pololu.write(0xC2); //Send byte to target motor 1 forwards
pololu.write(127); Set motor 1 speed
pololu.write(0xC9); //Send byte to target motor 2 forwards
pololu.write(127); Set motor 2 speed
}
The command documentation for the Trex Jr. can be found here.
No comments:
Post a Comment