Possible to attach encoder to Esp32-s3 and use it to run odrive connected motor?

Hey there, I am wondering if it is possible to attach an encoder to an Esp32-s3 and use it to run a motor that is connected to an odrive device in some manner? The reason being I have several as5600 encoders, and have created different mounts for motors I have, and would like to use them.

My current/previous setup and an esp32-s3 devkit m connected to a SimpleFOC Mini driver, and I build using PlatformIO, and ideally, I would like to keep this setup. I was hoping I could replace the SimpleFOC Mini with odrive as my motor driver, but still run everything (as much as I can) via the SimpleFOC library setup on the esp32.

Is it possible to use odrive in this manner? If so, where might I look for any sort of examples of how to accomplish this sort of setup? I suppose I might call it ‘using odrive as a passthrough and utilizing it’s driver/power output’.

Hi! Unfortunately the AS5600 is much too slow to be used for proper motor commutation. While this is technically possible (ESP32 acting as a SPI slave and as an encoder for the ODrive), I think it’s generally not the best idea. Could you use an ODrive Micro, and just use the onboard encoder? Then you can take full benefit of ODrive’s FOC loops and current sense.

I certainly understand the concern. I do already have an AMT-103. Now two AS5048A’s and a TLE5012 encoders will be here tomorrow. Then an ST-Link v2 adaper, a few MCP2515 boards, and TJA1050 so I can play around with some CAN communication, will be here sometime today.

The main reason I am doing any of this is that I just like learning and trying new things (was just finishing up a little desktop stepper/belt driven ‘robot’ arm when I learned about bldc and foc, so now going down that rabbit hole), so the fact that this is possible has me intrigued (whether it is ideal/performant or not isn’t really my concern) and I would like to see if I can make it work before moving on to something known working.

I certainly appreciate the info. Are there any repos out there that might have some basic examples of how one might go about accomplishing this?


Edit: In case anyone else who comes across this and may be looking to do something similar.

I came across this: GitHub - hideakitai/ESP32DMASPI: SPI library for ESP32 which use DMA buffer to send/receive transactions and am attempting to get it working. I have to look into what DMA is, as the first library I came across (GitHub - hideakitai/ESP32SPISlave: SPI Slave library for ESP32) says it does not use DMA.

I setup two identical esp32-s3-devkitc-1 n8r2’s, put master on one, slave on another, but slave is not returning what it should, but I will get that figured out and it at least gets me pointed in the right direction.

Yes, doing I2C to SPI is the best option here, but it’s going to give pretty bad performance unfortunately – the ODrive relies on sampling the encoder at a precise instant, and the nondeterminism between the ESP32 I2C reads and the ODrive SPI reads will cause poor performance. Should work okay enough at low speeds. But overall this is definitely more trouble than it’s worth in my opinion - I’d recommend just using the ODrive with your AS5048A in the first place, or writing custom firmware for the ODrive (I’m assuming it’s a v3.6 you have?) to take in raw inverter timing commands over UART/CAN.