Advanced example – Pololu Simple User Manual
Page 93
// 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
command[0] = 0xAA;
sendBlocking(command, 1); // 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
}
// program execution starts here
int main()
{
setup();
while (1) // loop forever
{
setMotorSpeed(3200);
delay_ms(1000);
setMotorSpeed(-3200);
delay_ms(1000);
}
}
Advanced Example
This example assumes the following connections exist between the Orangutan and the Simple Motor Controller:
• Orangutan pin PD0 to Simple Motor Controller TX
• Orangutan pin PD1 to Simple Motor Controller RX
• Orangutan pin PC0 to Simple Motor Controller RST
• Orangutan pin PC1 to Simple Motor Controller ERR
• Orangutan GND to Simple Motor Controller GND
Pins PD0 and PD1 are the Orangutan’s hardware serial receive and transmit lines, respectively, and must be connected
to the Simple Motor Controller as described above for this sample program to work. There is nothing special about
pins PC0 and PC1, however; you can connect any free digital pins to the Simple Motor Controller RST and ERR pins
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 program has on the controller’s variables (see
#include
#define resetPin IO_C0 // pin PC0 connects to SMC nRST
#define errPin IO_C1 // pin PC1 connects to SMC ERR
// some variable IDs
#define ERROR_STATUS 0
#define LIMIT_STATUS 3
#define TARGET_SPEED 20
#define INPUT_VOLTAGE 23
#define TEMPERATURE 24
// some motor limit IDs
#define FORWARD_ACCELERATION 5
#define REVERSE_ACCELERATION 9
#define DECELERATION 2
Pololu Simple Motor Controller User's Guide
© 2001–2014 Pololu Corporation
6. Using the Serial Interface
Page 93 of 101