AS5048A magnetic angle encoder (SPI) with ESP32
Supply 3.3 V
Bus SPI
Measures angle, rotation
Pins and ESP32 wiring
| Pin | Role | ESP32 pin | Notes |
|---|---|---|---|
| 3V3 | Power | 3V3 | Use this pin with the ESP32. Pin order differs between adapter boards |
| 5V | Not wired to the ESP32 | — | Only for 5 V systems. Leave unconnected when you use 3V3 |
| GND | Ground | GND | |
| CSN | SPI chip select | D5 | |
| CLK | SPI clock | D18 | |
| MOSI | SPI MOSI | D23 | |
| MISO | SPI MISO | D19 | |
| PWM | Output (the part drives it) | D25 | Angle as PWM duty cycle. Optional |
Suggested wiring for the 30-pin ESP32 DevKit, avoiding flash, input-only and strapping pins. BoardPilot checks it for you as you wire.
Starter code (Arduino)
void setup() {
Serial.begin(115200);
pinMode(25, INPUT); // PWM
}
void loop() {
Serial.println(digitalRead(25));
delay(100);
}
Sources
- ams AS5048A/AS5048B datasheet, SPI interface (mode 1), 14-bit angle register 0x3FFF
- ams AS5048A/AS5048B datasheet, 3.3 V or 5 V supply modes
Try it in 3D in BoardPilot
Related parts
ADXL362 ultra-low-power accelerometer (SPI)ArduCAM Mini 2MP camera (OV2640, SPI)MAX31855 K-type thermocouple breakoutMAX31856 universal thermocouple amplifierMAX31865 PT100/PT1000 RTD amplifierMAX6675 K-type thermocouple module
Part data: CC BY 4.0, free to reuse with credit to BoardPilot.