|
SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
|
A multi-platform sensor driver library for Arduino / PlatformIO / ESP-IDF.
See the changelog for release details. Projects upgrading from v0.4.x should also read the v0.5 migration guide.
v0.5.0 reorganizes driver headers and expands several common interfaces. Most legacy top-level headers remain as deprecated compatibility wrappers, but some projects require source changes. Review the v0.5 migration guide before upgrading.
Install from Library Manager (recommended):
Tools → Manage Libraries...From ZIP
Code → Download ZIPSketch → Include Library → Add .ZIP Library...With Git
Documents/Arduino/libraries/~/Documents/Arduino/libraries/~/Arduino/libraries/SensorLibAdd to your platformio.ini:
From GitHub (latest)
Local library Copy/clone this repository into <your_project>/lib/SensorLib/. PlatformIO will auto-detect it.
SensorLib is published in the ESP-IDF Component Registry. Supports ESP-IDF v4.4+ (recommended v5.1+).
1. Add dependency in project root idf_component.yml:
2. Use in your code:
SensorLib can exclude unused driver families or individual drivers at build time. This is useful when a project only uses one sensor and should not compile the rest of the library.
For ESP-IDF, configure exclusions from menuconfig:
Then open:
Select family-level options such as SENSORLIB_EXCLUDE_IMU, SENSORLIB_EXCLUDE_TOUCH, SENSORLIB_EXCLUDE_PMIC, or select individual drivers such as SENSORLIB_EXCLUDE_BHI260, SENSORLIB_EXCLUDE_TOUCH_GT911, SENSORLIB_EXCLUDE_PCF85063.
Example: build an ESP-IDF project that only uses SensorPCF8563:
Leave CONFIG_SENSORLIB_EXCLUDE_RTC and CONFIG_SENSORLIB_EXCLUDE_PCF8563 disabled so the PCF8563 driver remains available.
For Arduino or PlatformIO source builds, define the same macros in src/SensorBuildOptUser.h before including SensorLib headers:
SENSORLIB_EXCLUDE_ALL can be used to disable every optional driver controlled by SensorLib build options. Prefer the family or per-driver options when you want to keep one driver from the same category enabled.
Raw Bosch *.fw files are not required by the build and are not included. BHI260/BHI360 examples use generated firmware headers under src/bosch/firmware/. If you use a custom Bosch firmware image, convert it to a C/C++ header or provide your own firmware byte array, then pass it with setFirmware().
SensorLib provides two ways to include drivers in your sketch:
Include only the vendor group you need. Best balance of granularity and convenience.
One header pulls in all drivers for a category. Convenient for prototyping, but brings in extra macros and classes you may not need.
Note: All include paths are flat filenames in
src/. This works on Arduino IDE, PlatformIO, and ESP-IDF without subdirectory paths.
GT911 on ESP32 (Arduino)
AXP2101 on ESP32 (Arduino)
AXP517 includes Type-C/TCPC support and a simple USB-PD sink negotiator for requesting fixed PDO voltages.
PD negotiation is interrupt-driven. Hardware must connect PMIC_IRQ to an MCU GPIO, and the application must pass that pin to begin(..., irqPin) or initPdSink(irqPin) before calling requestPd(). Without a valid IRQ pin, the TCPC RX FIFO cannot be serviced reliably and PD voltage requests cannot complete.
Relevant examples:
examples/power/axp517_pd_voltage/examples/power/axp517_pd_auto_request/examples/power/axp517_interrupt/Examples are organized by category in the examples/ directory:
Directory names and .ino files use lowercase snake_case; folder names do not use hyphens.
PlatformIO: Edit platformio.ini and set src_dir to the example you want:
Arduino IDE: File → Open → navigate to the .ino file in examples/.
ESP-IDF: See examples/platform/ for ESP-IDF specific projects.
| Device | Description | I2C | SPI | Header |
|---|---|---|---|---|
| RTC | ||||
| PCF8563 / HYM8563 | Real-time clock | ✔️ | ❌ | SensorPCF8563.hpp |
| PCF85063 | Real-time clock | ✔️ | ❌ | SensorPCF85063.hpp |
| IMU | ||||
| QMI8658 | 6-axis IMU | ✔️ | ✔️ | ImuDrv.hpp |
| BHI260AP | Smart IMU (Bosch) | ✔️ | ✔️ | SensorBHI260AP.hpp |
| BHI360 | Smart IMU (Bosch) | ✔️ | ✔️ | SensorBHI360.hpp |
| Magnetometer | ||||
| QMC6309 | Magnetic Sensor | ✔️ | ❌ | SensorQMC6309.hpp |
| QMC6310U/N | Magnetic Sensor | ✔️ | ❌ | SensorQMC6310.hpp |
| QMC5883P | Magnetic Sensor | ✔️ | ❌ | SensorQMC5883P.hpp |
| QMC5883L | Magnetic Sensor | ✔️ | ❌ | SensorQMC5883L.hpp |
| BMM150 | Magnetic Sensor | ✔️ | ❌ | MagnetometerDrv.hpp |
| Accelerometer | ||||
| BMA422 | Accelerometer | ✔️ | ❌ | SensorBMA422.hpp |
| BMA423 | Accelerometer | ✔️ | ❌ | SensorBMA423.hpp |
| BMA456H | Accelerometer | ✔️ | ❌ | SensorBMA456H.hpp |
| I/O Expander | ||||
| XL9555 | 16-bit I/O Expander | ✔️ | ❌ | IoExpanderDrv.hpp |
| PCA9570 | 4-bit I/O Expander | ✔️ | ❌ | IoExpanderDrv.hpp |
| Haptic | ||||
| DRV2605 | Haptic Driver (TI) | ✔️ | ❌ | HapticDrivers.hpp |
| AW86224 | Haptic Driver (Awinic) | ✔️ | ❌ | HapticDrivers.hpp |
| Light Sensor | ||||
| CM32181 | Ambient Light Sensor | ✔️ | ❌ | LightSensorDrv.hpp |
| LTR553 | Light & Proximity | ✔️ | ❌ | LightSensorDrv.hpp |
| Touch | ||||
| GT911 | Capacitive Touch | ✔️ | ❌ | TouchDrvGoodix.hpp |
| GT9895 | Capacitive Touch | ✔️ | ❌ | TouchDrvGoodix.hpp |
| FT3267 | Capacitive Touch | ✔️ | ❌ | TouchDrvFocalTech.hpp |
| FT5206 | Capacitive Touch | ✔️ | ❌ | TouchDrvFocalTech.hpp |
| FT6206 | Capacitive Touch | ✔️ | ❌ | TouchDrvFocalTech.hpp |
| FT6236 | Capacitive Touch | ✔️ | ❌ | TouchDrvFocalTech.hpp |
| CST226SE | Capacitive Touch | ✔️ | ❌ | TouchDrvCST.hpp |
| CST820 | Capacitive Touch | ✔️ | ❌ | TouchDrvCST.hpp |
| CST816S/T/D | Capacitive Touch | ✔️ | ❌ | TouchDrvCST.hpp |
| CST9217 | Capacitive Touch | ✔️ | ❌ | TouchDrvCST.hpp |
| CST9220 | Capacitive Touch | ✔️ | ❌ | TouchDrvCST.hpp |
| CST3240 | Capacitive Touch | ✔️ | ❌ | TouchDrvCST.hpp |
| CST3530 | Capacitive Touch | ✔️ | ❌ | TouchDrvCST.hpp |
| CHSC5816 | Capacitive Touch | ✔️ | ❌ | TouchDrvChipshine.hpp |
| HI8561 | Capacitive Touch | ✔️ | ❌ | TouchDrvJadard.hpp |
| LED | ||||
| AW9364 | LED Driver (GPIO) | ❌ | ❌ | AW9364LedDriver.hpp |
| PMIC | ||||
| AXP192 | PMIC (XPowers) | ✔️ | ❌ | PmicXPowers.hpp |
| AXP202 | PMIC (XPowers) | ✔️ | ❌ | PmicXPowers.hpp |
| AXP2101 | PMIC (XPowers) | ✔️ | ❌ | PmicXPowers.hpp |
| AXP517 | PMIC (XPowers, Type-C/USB-PD sink) | ✔️ | ❌ | PmicXPowers.hpp |
| BQ25896 | Charger (TI) | ✔️ | ❌ | PmicTI.hpp |
| SY6970 | Charger (Silergy) | ✔️ | ❌ | PmicSilergy.hpp |
| Gauge | ||||
| BQ27220 | Battery Gauge (TI) | ✔️ | ❌ | GaugeDrv.hpp |
| AXP2602 | Battery Gauge (XPowers) | ✔️ | ❌ | GaugeDrv.hpp |
| Other | ||||
| PAW-A350 | Finger Navigation (PixArt) | ✔️ | ❌ | FingerNavigationDrv.hpp |
| Platform | Status | Notes |
|---|---|---|
| ESP32 | ✔️ | Primary target, full support |
| ESP32-S2 | ✔️ | Single-core, USB OTG |
| ESP32-S3 | ✔️ | Dual-core, USB OTG |
| ESP32-C3 | ✔️ | RISC-V single-core |
| ESP32-C6 | ✔️ | RISC-V, Wi-Fi 6 |
Other Arduino-compatible boards (RP2040, nRF52, etc.) may work for I2C devices but are not actively tested.
Wire.setClock(400000) before begin().GT911_SLAVE_ADDRESS_L / GT911_SLAVE_ADDRESS_H). Check the header file for available constants.PMIC_IRQ wiring. Pass the IRQ pin during initialization and use pmic.irq().readStatus(true) in interrupt-driven code so normal PMIC IRQs and TCPC PD alerts are both drained.examples/utility/wire_helper/ to scan the I2C bus.SensorLib is licensed under the MIT License. See LICENSE.
This repository includes third-party code under src/bosch/ from Bosch Sensortec, licensed under the BSD 3-Clause License (BSD-3-Clause).
See THIRD_PARTY_NOTICES.md for details.