=====Motor Treiber TRex DMC=====
Ein Beispiel-Programm zum Ansteuern des TRex DMC durch die Arduino-Plattform:
/*
The circuit:
* RX is digital pin 10 (connect to SO on TRex DMC)
* TX is digital pin 11 (connect to SI on TRex DMC)
*/
#include
SoftwareSerial mySerial(10, 11); // RX, TX
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// set the data rate for the SoftwareSerial port
mySerial.begin(19200);
// further Data-Query Commands: http://www.pololu.com/file/download/TReX_Commands_v1.2.pdf?file_id=0J1
mySerial.write(0x83);
delay(100);
if(mySerial.read() == 1){
Serial.println("Serial is in control!");
}else{
Serial.println("Serial ist not in control!");
}
}
void loop()
{
//Motor 1
mySerial.write(0xC2); //forward motor 1
mySerial.write(20); //Speedvalue from 0 to 127
//Motor 2
mySerial.write(0xCA); //forward motor 2
mySerial.write(20); //Speedvalue from 0 to 127
}
//
erweiterter Code:
//
/*
The circuit:
*connect RX3 Pin 14 to SO on TRex DMC
*connect TX3 Pin 15 to SI on TRex DMC
*/
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(57600);
// initialize connection to trex
Serial3.begin(19200);
// further Data-Query Commands: http://www.pololu.com/file/download/TReX_Commands_v1.2.pdf?file_id=0J1
//Ask the trex module if serial control is enabled
Serial3.write(0x83);
delay(100);
if(Serial3.read() == 1){
Serial.println("Serial is in control!");
}else{
Serial.println("Serial ist not in control!");
}
}
void loop()
{
//drive forward: (Motor 1: 0xC2, Motor 2: 0xCA)
// Motor 1
Serial3.write(0xC2); //forward motor 1
Serial3.write(100); //Speedvalue from 0 to 127
//Motor 2
Serial3.write(0xCA); //forward motor 2
Serial3.write(100); //Speedvalue from 0 to 127
/* drive reverse: (Motor 1: 0xC1, Motor 2: 0xC9)
// Motor 1
Serial3.write(0xC1); //reverse motor 1
Serial3.write(100); //Speedvalue from 0 to 127
//Motor 2
Serial3.write(0xC9); //reverse motor 2
Serial3.write(100); //Speedvalue from 0 to 127
drive left:
// Motor 1
Serial3.write(0xC2); //forward motor 1
Serial3.write(100); //Speedvalue from 0 to 127
//Motor 2
Serial3.write(0xCA); //forward motor 2
Serial3.write(50); //Speedvalue from 0 to 127
drive right:
// Motor 1
Serial3.write(0xC2); //forward motor 1
Serial3.write(50); //Speedvalue from 0 to 127
//Motor 2
Serial3.write(0xCA); //forward motor 2
Serial3.write(100); //Speedvalue from 0 to 127
*/
}