Hello to all participants in this fantastic community,
I am trying to build a turntable; I have already built some with various motors, and now I am very curious to try one using FOC
To get started, I will use the following components:
Raspberry Pi Pico, RP2040
SimpleFOC Mini
motor Gimbal Brushless GM3506
sensor AS5048
I have already seen that there is a very similar discussion to what I want to do:
Is Simple FOC an alternative to BGMC2 from RoverTec
And I have already tried to learn from its mistakes and discoveries to get started, such as using the rp2040 and the need for a closed-loop control.
I’m not very experienced in programming, so I’m trying to take it step by step by starting to test the AS5048 sensor. Below are the data provided by the seller:
Image on the right: Pinout on the board side.
Image on the left: Pinout on the connector side.
As suggested, I am using the example sketch provided by the SimpleFOC library:
Magnetic_Sensor_Spi_example
And this is the code I am using.
#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, 17);
// alternative constructor (chipselsect, bit_resolution, angle_read_register, )
// MagneticSensorSPI sensor = MagneticSensorSPI(10, 14, 0x3FFF);
void setup() {
// monitoring port
Serial.begin(115200);
// initialise magnetic sensor hardware
sensor.init();
Serial.println("Sensor ready");
_delay(1000);
}
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
sensor.update();
// display the angle and the angular velocity to the terminal
Serial.print(sensor.getAngle());
Serial.print("\t");
Serial.println(sensor.getVelocity());
}
I connected the CS pin, the black wire, to pin 17 of the rp2040, powered the sensor with 5V using an external power supply, and connected the rp2040 to pc
The code uploads successfully, but the serial monitor and plotter only display values of 0.00.
The magnet is integrated with the motor and sensor, so I’m quite sure it is correctly polarized for the sensor.
I have also read about issues regarding the sensor’s power supply, but the data provided by the seller only mentions 5V.
Where could I be making a mistake?
Another doubt I have is regarding the last code kindly shared by a user in the discussion link above, where three parameters of the SPI communication are defined:
// sensor data
const int clk = 18;
const int miso = 16;
const int nCS = 17;
Why am I only able to define the CS ?
Thanks to everyone for the help.