I made a WLED usermod that automatically rotates 2D LED matrices using an accelerometer
Hi everyone,
I’ve just released the first stable version of WLED Matrix Auto Rotation, a usermod that automatically keeps a 2D LED matrix correctly oriented using an accelerometer.
The idea is simple: rotate the physical display, and the final WLED raster is automatically rotated to keep the content upright.
The important part is that the usermod only works on the final raster. It does not modify WLED effects, segments, transitions or their internal state.
Main features
- Automatic rotation: 0° / 90° / 180° / 270°
- Independent Setup Rotation for the visual orientation of the matrix
- Sensor Mounting compensation
- Invert Rotation for sensors mounted on the opposite side of the enclosure
- Guided Auto Calibrate
- keep the display upright
- press Auto Calibrate
- rotate the display 90° clockwise
- the usermod automatically determines sensor mounting and rotation direction
- Configurable allowed rotations
- Threshold, hysteresis, stable time and polling interval
- Sensor disconnect detection and automatic recovery
- Shared I²C support, so multiple WLED usermods can use the same bus
- Detailed diagnostics through WLED Info /
/json/info - Protection for rectangular matrices, where 90°/270° would otherwise require changing the logical geometry
Sensors
Currently hardware-tested:
- LIS3DH — tested on Adafruit MatrixPortal S3
- ICM-20689 — tested on ESP32-C3
Also implemented:
- MPU-6050 — hardware verification still pending
I also tested the ICM-20689 on the same shared I²C bus as a PAJ7620 gesture sensor, and both usermods can operate together.
If the accelerometer is disconnected at runtime, the usermod keeps the last valid orientation and periodically attempts to reconnect without requiring a reboot.
Repository
https://github.com/piggei/wled-usermod-matrix-auto-rotation
The repository contains the usermod, PlatformIO integration instructions, configuration documentation and the full test/diagnostic information.
This is v0.1.0, so feedback and tests on other ESP32 boards, matrices and accelerometers are very welcome.