Hi all,
I am starting with Simple FOC. My setup
- MCU: Arduino Uno
- Driver: SimpleFOCShield V2.0.1
- Motor: iPower GM5208-12
- Sensor: AS5048A via SPI
I just finished “Getting Started” (testing sensor, testing driver, open loop, closed loop) successfully.
Afterwards I followed the instructions for installing and using PlatformIO. The exact same (+ #include <Arduino.h>) magnetic_sensor_spi_example
#include <Arduino.h>
#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(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());
}
using the platform.ini
[env:uno]
platform = atmelavr
board = uno
framework = arduino
lib_archive = false
monitor_speed = 115200
lib_deps = askuric/Simple FOC@^2.3.0
builds and uploads with two warnings
.pio\libdeps\uno\Simple FOC\src\common\foc_utils.cpp: In function ‘float _sqrtApprox(float)’:
.pio\libdeps\uno\Simple FOC\src\common\foc_utils.cpp:68:21: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
i = * ( long * ) &y;
^
.pio\libdeps\uno\Simple FOC\src\common\foc_utils.cpp:70:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
y = * ( float * ) &i;
^
and the serial monitor shows
0.00 0.00
for angle and velocity.
I tried different things like
- including SPI and Wire in platform.ini
- including #include <SPI.h> and #include<Wire.h> in main.cpp
but did not got any sensor readings.
Can you please give me a hint what I am doing wrong?