Multiple SPI Magnetic encoders (AS5048 SPI)

Hi,

I tried the example given for magnetic SPI sensor (single sensor using AS5048 SPI) and it worked perfectly.

Now, I’m trying to read two AS5048 SPI modules via SimpleFOC library and just tried to use the modified code bellow. i.e:

#include <SimpleFOC.h>

MagneticSensorSPI encoder1 = MagneticSensorSPI(4, 14, 0x3FFF);
MagneticSensorSPI encoder2 = MagneticSensorSPI(8, 14, 0x3FFF);

void setup() {

Serial.begin(9600);

// initialise magnetic sensor hardware
encoder1.init();
encoder2.init();

_delay(1000);
}

void loop() {

Serial.print(encoder1.getAngle());
Serial.print("\t");
Serial.println(encoder2.getAngle());
}

However, I don’t get the readings for two angles properly. What could be the reason ?
Do I need to manually switch chip select (CS) PIN HIGH/LOW when reading the two sensors ?

You shouldn’t need to pull CS low. The code will do this in the private read() function.

Do both sensors work individually when both sensors are physically wired up? What mcu are you using? This cs pins are both output pins, right?

1 Like

Yes, both sensors work individually and I am using an Arduino Uno for the moment. Pin assignment was as follows.

[ Both sensors were mounted on iPower GBM4108H-120T motors, and I tried this without driving the motors, but rather manually rotating the motors [i.e: motors were not connected to the board and hence the program consisted the lines only related to encoders]

sensor 1:

MISO-MISO (pin 12 of Arduino)
MOSI-MOSI (pin 11 of Arduino
SCK - SCK (pin 13 of Arduino)
CSn - Digital pin 4 of Arduino

sensor 2:

MISO-MISO (pin 12 of Arduino)
MOSI-MOSI (pin 11 of Arduino
SCK - SCK (pin 13 of Arduino)
CSn - Digital pin 8 of Arduino

What is the minimum you need to comment out to get encoder1 working? I think you’ve said that it works if you comment out all 3 lines below but does it work if you just comment the last line or the last two lines?

//MagneticSensorSPI encoder2 = MagneticSensorSPI(8, 14, 0x3FFF);
...
//encoder2.init();
...
//Serial.println(encoder2.getAngle());

1 Like

Thanks a lot Owen for helping out with this. I found the issue. It was my fault that I haven’t checked the wire connections properly. Even though both the sensors worked well individually, when they connected together it didn’t work properly. So I rechecked the wiring and code again as per your suggestions and found that one of the wires (jumper wire) joining two MOSIs pins and Arduino pin has been broken. That caused the issue and when I fixed that both the sensors worked perfectly.

Thanks again !!

1 Like


AS5047P兼容AS5048A,接口更丰富,支持更高的转速和更高的精度。

AS5047P Compatible With AS5048A,The interface is more abundant, supporting higher speed and higher precision.

Hey @MaLin,

AS5047P is a very powerful and adaptable sensor and it is supported with simplefoc library with both SPI and ABI(encoder) and even UVW (hall sensor) if well configured.
We still did not suport the PWM input though, I’m hoping that we will support it soon as well :smiley:

look forward to
nice

hello. I have a question about AS5047.
why it was work in encoder_example(ABI) but when i use velocity_control it doesn’t work.

Are you sure everything is well connected?
I can confirm that my as5047 works wit abi interface with the simple foc.

Are you using the Encoder class

I am sure that my as5047 works on sensor-test-encoder.But,I don’t know why it doesn’t when it work on velocity_motion_control-encoder. I try it many times,but I use AS5600(IIC) it was work.
could you tell me why Init FOC failed?

Are you sure that is the error message for i2c sensor?

MOT: Error: Not found

From what i can see the above message occurs for ‘encoders with index’ that fail to find index using index search.

I’d expect a different message for i2c. Is the motor moving during the init foc calibration?