Connecting two encoders to simpleFOC shield

Hello! I am trying to drive a gimbal motor by an encoder as an input device. So I have a gimbal bldc motor with its own encoder (AMT103-V) and another encoder (AMT103-V) I want to use to make position control of the motor; and a simpleFOC shield on an arduino UNO. The connections could be like those of the inverted pendulum example. So the two channel of the command encoder will be connected to A1 and A2 (why not to use A0?). But where to connect, on Arduino, the X pin of the encoder?
Thank you

I am doing something similar but using 2 separate microcontrollers, 1 for each position sensor. The motor and position sensor 1 goes to the first controller board with a dedicated motor shield, to ensure that FOC can run as fast as possible when looping. The second position sensor goes to a separate microcontroller, that drives an lcd screen, takes user input to adjust, or auto-determines any drift compensation necessary, then will communicate that back to the FOC controller via TX/RX serial communication.

I have yet to code the serial communication part, that is my final piece. I just need to understand the most optimal way to change motor.move(xxx) in the least blocking way. Maybe via the Controller interface?

Hey @certified_prime ,

You could just use the commander, this would be an option on the SimpleFOC side with very little effort. But on your other microcontroller you would have to implement the ASCII protocol used by Commander. It is certainly possible.

You can also invent your own protocol, the important thing is that you use Serial.available() to check how many bytes you can read, and don’t read more bytes than this or else you will cause blocking delays.

@fdurante ,

The UNO only has 2 interrupt pins, digital pins 2 and 3. To use a second encoder, you would have to use software interrupts. I’m not sure how good the performance would be, but you can give it a try. You can use any input pin for software interrupts.

Hello, thank you very much! My question was misplaced indeed… I was looking for what pin I had to connect to the X pin of the encoder… The X connector could be unconnected if I want to use encoder just as a reference. Its function is for the initialization of the motor but it is not necessary if we want to use the econder to control a motor position/velocity. So I tryed and now it works pretty well. I just used the angle control example together with some code of the encoder reading software interrupt example. But I have to report that the A0 and A1 pins (used in the example) don’t work. And not even A2, A3. While do work pretty well A4 and A5.
But now I am trying another configuration. I’d like to make a position control of motor by an IMU. I connected the IMU 6050 by I2C line and the motor moves but with trembling, imprecise progress. There appears to be interference between the I2C line and the motor control lines.
Does anyone know what could be the problem?

I want to specify that I am using the position angle control example which makes use of pins 9, 5 6, 8 for the motor and 2,3 for the encoder. While A4 and A5 are free (but they are a duplicate of scl and sda lines which actually are used for the I2C connection)


If you’re using them for I2C, you can’t also use pins A4,A5 for an encoder. They can’t share pins…