Wiring AS5048A Magnetic Sensor to RP2040

Hey Everyone.

I recently bought a GM3506 Gimbal Motor with a AS5048A magnetic sensor attached and I got it to work on an arduino uno. I had to switch the AS5048A cable from the 3 wire to the 6 wire to get it to work and connected it to the arduino as seen in the image below.

The code I used to connect the AS5048A to the arduino was the following:

MagneticSensorSPI sensor = MagneticSensorSPI(AS5048_SPI, 10);

This all worked great by for my project I don’t actually want to use a Arduino nano I trying to use a RP2040 which is naturally connected to a display (Waveshare RP2040 MCU Board, With 1.28inch Round LCD).

The pins on this RP2040 can be seen below but Im struggling to see how to change the wire connections from the Uno to the RP2040 cause to connect to the Arduino i had to use the SCK, CIPO, COPI, and SS ports. Which ports do i need to connect to on the RP2040 to get the magnetic sensor to work? Does the code from above work on a RP2040 as well?

Yes, you can certainly use this sensor with the RP2040. The RP2040 supports SPI.

The “standard” Pico has this pinout:

You can see which pins are used by the SPI interfaces in the pink boxes. So looking at the pinout of your board, it does look like GPIOs 2,3,4,5 (for SPI0) are available on the header, and also not used by the on-board peripherals.

So you could try pins 2 (SCK), 3 (MOSI/COPI), 4 (MISO/CIPO), 5 (nCS - you can also use any other pin for this).

Hm I’ve tried connected the wire to a pi Pico as follows

I couldn’t get the encoder to run on the same code that worked on the Uno.

#include <SimpleFOC.h>

// MagneticSensorSPI(MagneticSensorSPIConfig_s config, int cs)
//  config  - SPI config
//  cs      - SPI chip select pin 
// magnetic sensor instance - SPI
MagneticSensorSPI sensor = MagneticSensorSPI(AS5048_SPI, 10);
// alternative constructor (chipselsect, bit_resolution, angle_read_register, )
// MagneticSensorSPI sensor = MagneticSensorSPI(5, 14, 0x3FFF);

void setup() {
  // monitoring port

  // initialise magnetic sensor hardware

  Serial.println("Sensor ready");

void loop() {
  // iterative function updating the sensor internal variables
  // it is usually called in motor.loopFOC()
  // this function reads the sensor hardware and 
  // has to be called before getAngle nad getVelocity
  // display the angle and the angular velocity to the terminal

I tried
MagneticSensorSPI sensor = MagneticSensorSPI(AS5048_SPI, 10);
MagneticSensorSPI sensor = MagneticSensorSPI(5, 14, 0x3FFF);
MagneticSensorSPI sensor = MagneticSensorSPI(7, 14, 0x3FFF);

but all i kept on getting was 0 values in the Arduino IDE serial port terminal. Any idea whether its a wiring/hardware issue or whether there’s something I should change in my code? many thanks for the help so far

Is it an issue if 3.3V vs 5V power? Picos like 3.3V while UNOs use 5V…

The sensor has a different configuration depending on which you want to use…