Arduino library to control the Spectral Micro BLDC controller from an Arduino board, over UART. It sends the driver's text commands from a hardware serial port: set KV, L and R, start a calibration, and print what the driver answers.
Documentation · Download · Examples · Discord
Note
Early stage: the library has four of the driver's commands so far. Updated UART commands, CAN support and more examples are on the to-do list.
The library is not in the Arduino Library Manager. Download the repository and copy its SpectralMicro folder
into your Arduino libraries folder (on Windows Documents\Arduino\libraries):
git clone https://github.com/Source-Robotics/SpectralMicroArduino.git
You need a board with a free hardware serial port (the library takes a HardwareSerial), tested with the Teensy
4.1, wired to the driver's UART connector, a 4-pin JST SH (3V3, GND, TX, RX; the
UART cable has it on both ends). Cross TX and RX, the driver's
TX to the board's RX and the driver's RX to the board's TX, and connect GND. The driver's UART is 3.3 V and runs at
256000 baud by default; 5 V destroys the board, so use a 3.3 V board or a level shifter
(Connectors and pinout).
On a Teensy 4.1, Serial1 (pins 0 and 1) goes to the driver and the USB serial port shows what it answers:
// Tested on Teensy 4.1 with Spectral Micro
// Use serial1 for communication with the Spectral Micro and usb serial for debugging
// Teensy 4.1 has Serial1 on pins 0 and 1, which are the RX and TX pins respectively
#include <SpectralMicro.h>
SerialCommandLibrary mySerial(Serial1);
void setup() {
Serial.begin(256000);
mySerial.begin(256000);
delay(1000); // Give some time for the serial connection to establish
// Example commands
mySerial.KV(0.123);
mySerial.L(1.234);
mySerial.R(2.345);
mySerial.Cal();
}
void loop() {
mySerial.Cal();
Serial.println("testing");
mySerial.loop(); // Continuously check for incoming data
delay(1000); // Give some time for the serial connection to establish
}What each command does and answers: the UART reference in the Spectral Micro manual.
| Product | Firmware | Repository |
|---|---|---|
| Spectral Micro BLDC controller | 101 to 107 (the four commands are the same in each) | Spectral-Micro-BLDC-controller |
Tested with a Teensy 4.1. The STEPFOC stepper controller's firmware 108 has the same four UART commands; the library has not been tested with it. Which firmware your driver runs: the compatibility pages of the Spectral Micro and STEPFOC manuals.
| Example | What it does |
|---|---|
example.ino |
the quick start above, on a Teensy 4.1: opens Serial1 to the driver at 256000 baud, sets KV, L and R and starts a calibration, then every second sends #Cal again, prints testing and prints every line the driver sent |
The class SerialCommandLibrary, in SpectralMicro.h:
| Call | What it does |
|---|---|
SerialCommandLibrary(HardwareSerial& serialPort) |
the serial port wired to the driver, for example Serial1 |
begin(long baudRate) |
opens the port; the driver's default is 256000 |
KV(float value) |
sends #KV <value>: sets the velocity constant, in rpm/V |
L(float value) |
sends #L <value>: sets the phase inductance, in H |
R(float value) |
sends #R <value>: sets the phase resistance, in Ω |
Cal() |
sends #Cal: runs the driver's calibration; it measures R and L, finds the pole pairs, the phase order and the angle offset, and measures Kt, KV and the flux linkage |
loop() |
prints every line the driver sent on the USB serial port (Serial), as Received: <line> |
Each command ends with CR LF. The value is written as Arduino's String(float) writes it, with two decimals.
- Update uart commands
- Add CAN support
- Examples
Ask in Discussions, chat on Discord, report a bug in Issues. Follow Source Robotics:
- The software and hardware are still in development and may contain bugs, errors, or incomplete features.
- Users are encouraged to use this software and hardware responsibly and at their own risk.
Read the manual's safety chapter before you wire and power the driver.
Project is under MIT Licence