Un exemple d’utilisation d’un encodeur magnétique de référence AS5048 avec la carte Raspberry Pi Pico.


L’encodeur est relié en SPI au Pico via les pins :
- GPIO4 => MISO
- GPIO3 => MOSI
- GPIO6 => SCK
- GPIO5 => CS

Exemple de lecture
[code language=”python”]
#include <SimpleFOC.h>
#include <SPI.h>
#define SPI_MISO 4
#define SPI_MOSI 3
#define SPI_SCK 6
#define SPI_CS 5
MagneticSensorSPI sensor = MagneticSensorSPI(SPI_CS, 14, 0x3FFF);
void setup()
{
SPI.setCS(SPI_CS);
SPI.setSCK(SPI_SCK);
SPI.setRX(SPI_MISO);
SPI.setTX(SPI_MOSI);
SPI.begin();
// initialise magnetic sensor hardware
sensor.init();
}
void loop()
{
sensor.update();
// display the angle and the angular velocity to the terminal
Serial.print(sensor.getAngle());
Serial.print("\t");
Serial.println(sensor.getVelocity());
delay(1000);
}
[/code]
FIN !