Advanced example – Pololu Simple User Manual
Page 89
![background image](/manuals/570386/89/background.png)
else
{
smcSerial.write(0x85); // motor forward command
}
smcSerial.write(speed & 0x1F);
smcSerial.write(speed >> 5);
}
void setup()
{
// initialize software serial object with baud rate of 19.2 kbps
smcSerial.begin(19200);
// the Simple Motor Controller must be running for at least 1 ms
// before we try to send serial data, so we delay here for 5 ms
delay(5);
// if the Simple Motor Controller has automatic baud detection
// enabled, we first need to send it the byte 0xAA (170 in decimal)
// so that it can learn the baud rate
smcSerial.write(0xAA); // send baud-indicator byte
// next we need to send the Exit Safe Start command, which
// clears the safe-start violation and lets the motor run
exitSafeStart(); // clear the safe-start violation and let the motor run
}
void loop()
{
setMotorSpeed(3200); // full-speed forward
delay(1000);
setMotorSpeed(-3200); // full-speed reverse
delay(1000);
}
Advanced Example
This example assumes the following connections exist between the Arduino and the Simple Motor Controller:
• Arduino digital pin 3 to Simple Motor Controller TX
• Arduino digital pin 4 to Simple Motor Controller RX
• Arduino digital pin 5 to Simple Motor Controller RST
• Arduino digital pin 6 to Simple Motor Controller ERR
• Arduino GND to Simple Motor Controller GND
There is nothing special about Arduino pins 3 through 6; you can use any free digital pins other than 0 and 1 (the
Arduino’s hardware serial lines) if you change the pin definitions at the top of the sample program accordingly. See
for more information on connecting a serial device to the Simple Motor Controller.
This program demonstrates how to initiate serial communication with the Simple Motor Controller and how to send
commands to set the motor speed, read variables, and change the temporary motor limits. For information about the
serial commands used by this sample code, refer to
. It will be more interesting if you have input power
and a motor connected to your Simple Motor Controller (see
), but you can see some interesting things
even without a motor connected by using the Status tab of the Simple Motor Control Center application to monitor
the effect this sketch has on the controller’s variables (see
#include
#define rxPin 3 // pin 3 connects to SMC TX
#define txPin 4 // pin 4 connects to SMC RX
#define resetPin 5 // pin 5 connects to SMC nRST
#define errPin 6 // pin 6 connects to SMC ERR
SoftwareSerial smcSerial = SoftwareSerial(rxPin, txPin);
// some variable IDs
Pololu Simple Motor Controller User's Guide
© 2001–2014 Pololu Corporation
6. Using the Serial Interface
Page 89 of 101