Hello everyone,
I just got a MT6835 encoder, and to get started I tried to apply the example code. However, I’ve already ran into an issue. No matter the position of the magnet, calling Sensor.getAngle() returns 12867.88, which does not make sense to me. The velocity output is always 0. The getStatus() function seems to work, as it normally returns 000, but does return 010 when the magnet is removed.
Any suggestions would be appreciated.
#include <Arduino.h>
#include "SimpleFOC.h"
#include "SimpleFOCDrivers.h"
#include "encoders/mt6835/MagneticSensorMT6835.h"
#define SENSOR_nCS 18
SPISettings myMT6835SPISettings(1000000, MT6835_BITORDER, SPI_MODE3);
MagneticSensorMT6835 sensor = MagneticSensorMT6835(SENSOR_nCS, myMT6835SPISettings);
long ts;
void setup() {
SimpleFOCDebug::enable();
sensor.init();
ts = millis();
}
void loop() {
sensor.update();
long now = millis();
if (now - ts > 1000) {
ts = now;
SimpleFOCDebug::print("A: ");
SimpleFOCDebug::println(sensor.getAngle());
SimpleFOCDebug::print(" V: ");
SimpleFOCDebug::println(sensor.getVelocity());
SimpleFOCDebug::print(" S: ");
SimpleFOCDebug::println(sensor.getStatus());
Serial.println("----");
}
delay(10);
}