I’m using a arduino mega and SimpleFOC Shield testing the AS5048A megnetic sensor via Spi The sketch didn’t work at first so I declared the spi pins it works but when I turn my motor in the cw direction the sensor data goes ccw and vise versa, trued multiple AS5048A Encoders Samething, even in other sketches when the motor is initializing and align with the sensor it says the sensor is ccw Could someone point my in the right direction literally here’s the code
#include <SimpleFOC.h>
// Define the SPI pins
const int spiMISO = 50; // MISO pin
const int spiMOSI = 51; // MOSI pin
const int spiSCK = 52; // SCK pin
const int spiSS = 53; // SS (Slave Select) pin
SPISettings spiSettings(1000000, MSBFIRST, SPI_MODE1);
// SPI settings (clock speed, bit order, SPI mode)
// MagneticSensorSPI(MagneticSensorSPIConfig_s config, int cs)
// config - SPI config
// cs - SPI chip select pin
// magnetic sensor instance - SPI
MagneticSensorSPI sensor = MagneticSensorSPI(AS5048_SPI, spiSS);
void setup() {
// Monitoring port
Serial.begin(115200);
// Initialize SPI communication
SPI.begin();
// Initialize magnetic sensor
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 and getVelocity
sensor.update();
// Display the angle and the angular velocity to the terminal
Serial.print(sensor.getAngle());
Serial.print(“\t”);
Serial.println(sensor.getVelocity());
}