Detecting a disconnected or non-responsive sensor in firmware

Hello, I’ve had a request from my mechanical engineering collaborator, for my firmware to detect when the sensor (AS5600) has lost connection to my microcontroller (ESP32-S2). I am using the SimpleDCMotor library to request a DC motor to ramp up to velocity, hold a velocity, ramp down velocity back to zero, and then repeat. This part works great.

The problem is that sometimes unexpected mechanical errors occur: the shaft magnet loses alignment with the sensor PCBA, or a cable gets mistakenly disconnected or shaken loose. When this happens, the SimpleDCMotor library instructs the motor to spin up to maximum velocity as it attempts to meet a target velocity without any feedback from the sensor.

Is there a way I can enforce a simple check in my code to check that the sensor is still present? If I could do this, I can stop the firmware, and throw up an error code for him.

Thank you!

Aran

(Yes, my collaborator is also working on making sure this error never happens in the first place, but I would still like my code to be fail safe)

I spent quite some time on this issue for the AS5048A. I cannot tell bout the AS5600, but maybe it’s similar.

Back to the AS5048A: it seems there’s no reliable way to ping it though a SPI connection in order to check that it’s working. Every method I tried failed miserably. This is extremely problematic and one of the reasons I switched to another encoder in my project.

Hi Quentin - thanks, its good to hear that others are encountering this need. My situation with the AS5600 might differ from the AS5048A, as my sensor communicates via I2C

OK I’ve found a way of doing this, scanning for I2C devices on the bus. This Adafruit example code demonstrates the approach well. I will use this to scan for the address of the AS5600 regularly, and try to catch a disconnection event.