mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-08-19 02:43:27 +08:00
improve ardiuno serial connection guide
This commit is contained in:
@@ -1,14 +1,38 @@
|
||||
|
||||
// includes
|
||||
#include <SoftwareSerial.h>
|
||||
#include <ODriveArduino.h>
|
||||
|
||||
// Printing with stream operator
|
||||
// Printing with stream operator helper functions
|
||||
template<class T> inline Print& operator <<(Print &obj, T arg) { obj.print(arg); return obj; }
|
||||
template<> inline Print& operator <<(Print &obj, float arg) { obj.print(arg, 4); return obj; }
|
||||
|
||||
// Serial to the ODrive
|
||||
SoftwareSerial odrive_serial(8, 9); //RX (ODrive TX), TX (ODrive RX)
|
||||
// Note: you must also connect GND on ODrive to GND on Arduino!
|
||||
|
||||
////////////////////////////////
|
||||
// Set up serial pins to the ODrive
|
||||
////////////////////////////////
|
||||
|
||||
// Below are some sample configurations.
|
||||
// You can comment out the default Teensy one and uncomment the one you wish to use.
|
||||
// You can of course use something different if you like
|
||||
// Don't forget to also connect ODrive GND to Arduino GND.
|
||||
|
||||
// Teensy 3 and 4 (all versions) - Serial1
|
||||
// pin 0: RX - connect to ODrive TX
|
||||
// pin 1: TX - connect to ODrive RX
|
||||
// See https://www.pjrc.com/teensy/td_uart.html for other options on Teensy
|
||||
Stream& odrive_serial = Serial1;
|
||||
|
||||
// Arduino Mega or Due - Serial1
|
||||
// pin 19: RX - connect to ODrive TX
|
||||
// pin 18: TX - connect to ODrive RX
|
||||
// See https://www.arduino.cc/reference/en/language/functions/communication/serial/ for other options
|
||||
// Stream& odrive_serial = Serial1;
|
||||
|
||||
// Arduino without spare serial ports (such as Arduino UNO) have to use software serial.
|
||||
// Note that this is implemented poorly and can lead to wrong data sent or read.
|
||||
// pin 8: RX - connect to ODrive TX
|
||||
// pin 9: TX - connect to ODrive RX
|
||||
// SoftwareSerial odrive_serial(8, 9);
|
||||
|
||||
|
||||
// ODrive object
|
||||
ODriveArduino odrive(odrive_serial);
|
||||
|
||||
Reference in New Issue
Block a user