AS5048A with Arduino Mega: 0.0 readout

Hi, I connected the AS5048A magnetic sensor to an Arduino Mega board (SPI). I used the example program to test it.


MagneticSensorSPI sensor = MagneticSensorSPI(10, 14, 0x3FFF);

No compiling errors, but only 0.0 readouts. When I change the Mega with an Uno (same sketch, same pins), I get normal readouts.

Any solution? Is it a software bug?


  1. Check pin selection

Arduino Mega SPI pins: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS).

Arduino Nano SPI pins: 10 (SS) Chip Select or any pin, 11 (MOSI), 12 (MISO), 13 (SCK)

Arduino Uno SPI pins: 10 (SS) Chip Select or any pin, 11 (MOSI), 12 (MISO), 13 (SCK)

  1. Check wiring, crossed wires, wrong wires go to the wrong pins.

  2. Check bad / cold connections (pins connected but wire connector is bad).

  3. Check code for separate boards is using the correct pin assignment in the code.

  4. Check target MCU in Arduino IDE/GUI is building for correct target MCU.

  5. Check AS5048A sensor is using correct voltage (3v vs 5v), nano and mega use 5v, but if you select 3v for the sensor, sometimes it works intermittently even though it should not, so you get funny half-assed readings.

Most of the times it’s a combination of some of the aforementioned problems so you got to have extreme patience and trace the problem. Most importantly, the problem is simple so don’t get frustrated and throw the board on the floor and jump on top if it. It doesn’t help. I’ve tried.


1 Like

Thx, that did the trick. I knew this…

1 Like

Hi, I connected the AS5047P magnetic sensor to an Arduino UNO (SPI). It is no problem. The BLDC can work well.
But I changed to Arduino Mega 2560 (SPI). Why the BLDC cannot work? Please refer to the picture. Thanks.
Google Photos

Hi, where did you change the SPI pins in the code? I have RP2040 and I have to change to SPI1 port. Thanks.

You can use any SPIClass object by passing to the sensor.init() method;


This is assuming SPI1 is defined in RP2040. How to initialize an SPIClass object and which ones are available varies by MCU type and board.