|
2 | 2 | #include <ODriveArduino.h> |
3 | 3 | #include <SoftwareSerial.h> |
4 | 4 |
|
5 | | -SoftwareSerial odrive_serial(8, 9); // RX (ODrive TX), TX (ODrive RX) |
| 5 | +// Documentation for this example can be found here: |
| 6 | +// https://docs.odriverobotics.com/v/latest/guides/arduino-guide.html |
| 7 | + |
| 8 | + |
| 9 | +//////////////////////////////// |
| 10 | +// Set up serial pins to the ODrive |
| 11 | +//////////////////////////////// |
| 12 | + |
| 13 | +// Below are some sample configurations. |
| 14 | +// You can comment out the default one and uncomment the one you wish to use. |
| 15 | +// You can of course use something different if you like |
| 16 | +// Don't forget to also connect ODrive ISOVDD and ISOGND to Arduino 3.3V/5V and GND. |
| 17 | + |
| 18 | +// Arduino without spare serial ports (such as Arduino UNO) have to use software serial. |
| 19 | +// Note that this is implemented poorly and can lead to wrong data sent or read. |
| 20 | +// pin 8: RX - connect to ODrive TX |
| 21 | +// pin 9: TX - connect to ODrive RX |
| 22 | +SoftwareSerial odrive_serial(8, 9); |
| 23 | +int baudrate = 19200; // Must match what you configure on the ODrive (see docs for details) |
| 24 | + |
| 25 | +// Teensy 3 and 4 (all versions) - Serial1 |
| 26 | +// pin 0: RX - connect to ODrive TX |
| 27 | +// pin 1: TX - connect to ODrive RX |
| 28 | +// See https://www.pjrc.com/teensy/td_uart.html for other options on Teensy |
| 29 | +// HardwareSerial& odrive_serial = Serial1; |
| 30 | +// int baudrate = 115200; // Must match what you configure on the ODrive (see docs for details) |
| 31 | + |
| 32 | +// Arduino Mega or Due - Serial1 |
| 33 | +// pin 19: RX - connect to ODrive TX |
| 34 | +// pin 18: TX - connect to ODrive RX |
| 35 | +// See https://www.arduino.cc/reference/en/language/functions/communication/serial/ for other options |
| 36 | +// HardwareSerial& odrive_serial = Serial1; |
| 37 | +// int baudrate = 115200; // Must match what you configure on the ODrive (see docs for details) |
| 38 | + |
| 39 | + |
6 | 40 | ODriveArduino odrive(odrive_serial); |
7 | 41 |
|
8 | 42 | void setup() { |
9 | | - // This baudrate must match the baudrate configured on the ODrive. |
10 | | - // Note that the default ODrive baudrate is 115200, so this example requires |
11 | | - // to change the baudrate on the ODrive accordingly (see docs for explanation), |
12 | | - odrive_serial.begin(19200); |
| 43 | + odrive_serial.begin(baudrate); |
13 | 44 |
|
14 | | - Serial.begin(115200); |
| 45 | + Serial.begin(115200); // Serial to PC |
15 | 46 |
|
16 | 47 | delay(10); |
17 | 48 |
|
|
0 commit comments