Post · 7 min read· pp. 1254–1258

Simple FOC Drivers library

On this page

Library Compile License: MIT arduino-library-badge

The SimpleFOClibrary is kept lean on purpose: motor control algorithms, PWM support for the different MCUs, and generic sensors and communication. Everything that is specific to a particular chip, or that not everyone needs, lives in the SimpleFOCDrivers library:

  • Driver ICs with SPI or I2C configuration, like the DRV8316 or TMC6200
  • Sensor drivers for over 20 position sensor ICs, plus special sensors like the CalibratedSensor
  • Sensorless control with a flux observer, no position sensor needed
  • Communication: CAN, binary and ASCII packet protocols, telemetry, I2C
  • Settings storage: save the motor calibration and tuning to flash or EEPROM
  • Utilities: STM32 CORDIC acceleration, PWM input, motion planning

Source on GitHub

Guides

These modules have a dedicated page in the docs:

GuideWhat it’s for
DRV8316 driverConfiguring and diagnosing the DRV8316 integrated driver, current sensing, fault handling
Calibrated sensorCompensating magnet eccentricity errors with a lookup table
Sensorless flux observerRunning FOC without a position sensor, estimating the angle from the phase currents
Registers, PacketCommander and telemetryReading and writing any motor value, binary and ASCII protocols, monitoring
CAN communicationControlling one or more motors over a CAN bus
Settings storageSaving calibration and tuning so you can skip them on startup

For all the other modules, see the README in each module’s folder, linked in the catalog below.

Installation

The library is available in the Arduino Library Manager and PlatformIO as Simple FOC Drivers.

  • Arduino IDE: Tools > Manage Libraries..., search for Simple FOC drivers and install it.
  • PlatformIO: add it to your platformio.ini:
ini
lib_deps =
    Simple FOC
    SimpleFOCDrivers

To get the newest features before they are released, use the dev branch from GitHub instead: https://github.com/simplefoc/Arduino-FOC-drivers.git#dev.

Usage

Include the library header, and then the header of the module you want to use:

cpp
#include <SimpleFOC.h>
#include <SimpleFOCDrivers.h>
#include "encoders/as5048a/MagneticSensorAS5048A.h"

The modules are designed to slot into normal SimpleFOClibrary code: a sensor driver is a Sensor, a driver IC class is a BLDCDriver, so you link them to the motor exactly like the built-in classes.

Catalog

Motor and gate driver ICs

Drivers for ICs with an SPI or I2C configuration and status interface. They extend the BLDCDriver3PWM / BLDCDriver6PWM classes, so they work as drop-in replacements.

ModuleDescription
DRV8316TI DRV8316 integrated 3-phase driver with current sensing, SPI
DRV8376TI DRV8376 integrated 3-phase driver, SPI
DRV8320 / DRV8323TI DRV832x gate drivers, SPI
TMC6200Trinamic TMC6200 gate driver, SPI
STSPIN32G4ST STSPIN32G4 gate driver with integrated STM32G4 MCU, I2C
SimpleFOCNanoDriver preconfigured for the SimpleFOCNano board

Position sensors

Hardware-specific sensor drivers. Compared to the generic MagneticSensorSPI / MagneticSensorI2C, they support chips the generic classes can’t (SSI, half-duplex SPI, special protocols) and give access to status and configuration registers.

ModuleDescription
AS5047AMS AS5047P / AS5047D, SPI
AS5047UAMS AS5047U, SPI
AS5048AAMS AS5048A, SPI
AS5145AMS AS5145 / AS5045, SSI
AS5600AMS AS5600 / AS5600L, I2C
AEAT-8800-Q24Broadcom AEAT-8800-Q24, mixed SPI/SSI
A1334Allegro A1334, SPI
KTH78xxConntek KTH78xx series, SPI
MA330MPS MagAlpha MA330, SPI
MA730MPS MagAlpha MA730, SPI or SSI
MA735MPS MagAlpha MA735, SPI or SSI
MT6701MagnTek MT6701, SSI
MT6816MagnTek MT6816, SPI
MT6826SMagnTek MT6826S, SPI
MT6835MagnTek MT6835 21-bit, SPI
SC60228SemiMent SC60228, SPI
TLE5012BInfineon TLE5012B, half-duplex SPI (STM32)
STM32 hardware encoderABI quadrature encoders using STM32 timers, no interrupts needed
STM32 low power encoderABI quadrature encoders using STM32 LPTIM timers
ESP32 hardware encoderABI quadrature encoders using the ESP32 pulse counter
STM32 PWM sensorSensors with PWM output, measured with STM32 timers

Special sensors

Sensors that wrap or replace another sensor to improve or extend it.

ModuleDescription
CalibratedSensorCompensates magnet eccentricity with a calibration lookup table
SmoothingSensorExtrapolates the angle between sensor updates, for slow or low-resolution sensors
HysteresisSensorAdds configurable hysteresis to any sensor
LinearHallAnalog (linear) hall sensors with interpolation
Flux observerSensorless control: estimates the rotor angle from the phase currents, requires current sensing

Communication

Most communication modules are built on the registers abstraction: every motor value (target, PID gains, limits, measured currents…) has a register number, and can be read or written the same way over any channel. See Registers, PacketCommander and telemetry.

ModuleDescription
PacketCommanderRead and write registers over serial, in ASCII or binary
TelemetryStream any registers at a fixed rate, for logging and plotting
CANRegister-based CAN protocol, multiple nodes and motors per bus
I2CCommanderRegister-based control over I2C
STM32 speed/dir inputSet the target velocity with PWM speed and direction inputs

All register-based protocols are supported by the Python library PySimpleFOC.

Settings storage

Save motor calibration and settings, so you can skip the calibration on startup. See Settings storage.

ModuleDescription
STM32 flashSTM32G4 on-board flash
SAMD NVMSAMD on-board flash or RWWEE memory
CAT24 I2C EEPROMExternal I2C EEPROMs (unfinished)

Utilities

ModuleDescription
STM32 CORDICHardware-accelerated sine and cosine on STM32 MCUs with a CORDIC unit (e.g. STM32G4)
STM32 PWM inputMeasure PWM inputs with zero CPU overhead
Trapezoidal plannerSimple trapezoidal motion profiles
Voltage senseSupply voltage measurement

How do we decide what goes there?

While working on the SimpleFOClibrary we sometimes develop code that doesn’t directly belong in the core library, or receive contributions that don’t quite fit. The drivers library is their home. It holds code that is:

  • hardware-specific, like a driver for a specific sensor or driver chip
  • related to motor control, but not needed by everyone
  • an implementation of a specific communication protocol

Keep in mind that code in the drivers library is used by fewer people than the core library, so it is less tested and less completely documented, and generally better suited to more experienced users. If you get stuck, ask on the community forum.


Copyright © 2026. Distributed by an MIT license.