The first sign that everything is well connected is if the sensor readings are good. This quick test validates that your position sensor is working correctly.
#include<SimpleFOC.h>// MagneticSensorAnalog(uint8_t _pinAnalog, int _min, int _max)// - pinAnalog - the pin that is reading the pwm from magnetic sensor// - min_raw_count - the smallest expected reading. // - max_raw_count - the largest value read. MagneticSensorAnalogsensor=MagneticSensorAnalog(A1,14,1020);voidsetup(){// monitoring portSerial.begin(115200);// initialise magnetic sensor hardwaresensor.init();Serial.println("Sensor ready");_delay(1000);}voidloop(){// 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 getVelocitysensor.update();// display the angle and the angular velocity to the terminalSerial.print(sensor.getAngle());Serial.print("\t");Serial.println(sensor.getVelocity());}
#include<SimpleFOC.h>// Example of AS5600 configuration MagneticSensorI2Csensor=MagneticSensorI2C(AS5600_I2C);voidsetup(){// monitoring portSerial.begin(115200);// configure i2CWire.setClock(400000);// initialise magnetic sensor hardwaresensor.init();Serial.println("Sensor ready");_delay(1000);}voidloop(){// 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 getVelocitysensor.update();// display the angle and the angular velocity to the terminalSerial.print(sensor.getAngle());Serial.print("\t");Serial.println(sensor.getVelocity());}
#include<SimpleFOC.h>// MagneticSensorSPI(MagneticSensorSPIConfig_s config, int cs)// config - SPI config// cs - SPI chip select pin MagneticSensorSPIsensor=MagneticSensorSPI(AS5147_SPI,10);voidsetup(){// monitoring portSerial.begin(115200);// initialise magnetic sensor hardwaresensor.init();Serial.println("Sensor ready");_delay(1000);}voidloop(){// 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 getVelocitysensor.update();// display the angle and the angular velocity to the terminalSerial.print(sensor.getAngle());Serial.print("\t");Serial.println(sensor.getVelocity());}
#include<SimpleFOC.h>// Hall sensor instance// HallSensor(int hallA, int hallB , int cpr, int index)// - hallA, hallB, hallC - HallSensor A, B and C pins// - pp - pole pairsHallSensorsensor=HallSensor(2,3,4,14);voidsetup(){// monitoring portSerial.begin(115200);// initialise sensor hardwaresensor.init();Serial.println("Sensor ready");_delay(1000);}voidloop(){// iterative function updating the sensor internal variables// it is usually called in motor.loopFOC()sensor.update();// display the angle and the angular velocity to the terminalSerial.print(sensor.getAngle());Serial.print("\t");Serial.println(sensor.getVelocity());delay(100);}
#include<SimpleFOC.h>Encoderencoder=Encoder(2,3,500);// interrupt routine initialisationvoiddoA(){encoder.handleA();}voiddoB(){encoder.handleB();}voidsetup(){// monitoring portSerial.begin(115200);// initialise encoder hardwareencoder.init();// hardware interrupt enableencoder.enableInterrupts(doA,doB);Serial.println("Encoder ready");_delay(1000);}voidloop(){// IMPORTANT// read sensor and update the internal variablesencoder.update();// display the angle and the angular velocity to the terminalSerial.print(encoder.getAngle());Serial.print("\t");Serial.println(sensor.getVelocity());}
Setup Steps
Copy the code for your sensor type above
Update parameters to match your setup:
Pin numbers (e.g., A1, 2, 3, 10)
Sensor-specific parameters (impulses per revolution, I2C address, etc.)