Issue regarding MT6835 encoder

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);
}

Hi @filal253 , welcome to SinpleFOC!

Your code looks ok actually. Which MCU type is this running on?

Could you maybe also share some details of the wiring between MCU and sensor?

Hi, I’m running it on an ATmega32U4 pro micro. This is the hookup diagram:


In the meantime I wrote my own script which reads the registers 0x003-0x006 over SPI and does the angle conversion, and that worked correctly.