AS5600 Angle sensor support?

I am working on a project. I stumbled upon this ecosystem and I am in love. I purchased a gimbal board and an AS5600 magnetic encoder, but now I am realizing that an AS5x4x is required… Seems the 5600 is much more common and cheaper why can’t it also work?

I’ll note the 5600 is I2C and the AS5048 for example is SPI. I dont want to pay a ton of money, and I also don’t want to wait 90 days for new parts to come from china. Any way I can get the AS5600 to work for me?

Hello @Engineering_Nonsense I was just about to implement the I2C magnetic sensor support today. But I just realized that my as5047 doesn’t have I2C communication. I was sure it does. Anyway I ordered the AS5600 and it will be here on Tuesday. So I hope to test it properly next week.
Once when I test it thoroughly I will add it to the Arduino library.

Anyway I have implemented the code, since it is not a big change from the SPI version, the logic is the same just the communication part is different. You can test the code in the branch

If you have time to test it I would really appreciate it, it would help me to iterate faster. Otherwise, I’ll test it next week when I will have the sensors. :smiley:

There are two versions of the AS5048. The type A (AS5048A) using the SPI and PWM interface, while type B (AS5048B) is using the I²C and PWM interface. Unfortunately I also have typ A available, only.
@Antun_Skuric, I tested the SPI communication that works fine, provided there is not to much load on the mc. For testing I²C I have currently no hardware available.

Wow that was fast!:smiley:

I was able to get an angle reading out of the sensor through the sensor test code you shared–I was not, however able to get it to turn the motor, when I tried to upload the other sketch it fried my angle sensor… Even started smoking lol

I also broke a sensor by reading from the wrong address?–I used your code as you posted it without thinking to change the addresses and one of my angle sensors is now bricked or something. I didn’t know this was even possible? but it became unresponsive.

I thankfully have three of them, but now I am thinking I should wait until you test before I burn up my last one lol.

They are so cheap I’ll probably end up just buying a bunch of them. They seem useful for other projects as well.

On those little gimbal boards, is it okay to power from Lipo and USB at the same time?–That’s what I was doing–I uploaded the sketch with everything still connected and it let out magic smoke haha

Hey @Engineering_Nonsense!

I am sorry to hear that, I have no idea why that would happen or what might be causing it.
I am pretty sure that it cannot be the code itself, but I am not 100% :confused:

Did you change the device address and the register address in the code I’ve sent you?
I did not try to put the good addresses in the code at all.

Regarding the burning of the sensor, did you have 3.3V or 5V sensor?
Sometimes on these boards they put the VCC or + sign to the 12V signal. Please be careful with that.
Make sure that the 5V signal you are connecting to is really 5V wire :smiley:
This could maybe explain the burning the sensor with battery and not with USB only.

I will look into it more in depth once when I have sensor and I’ll let you guys know once when I have tested everything properly.

Awesome thanks! :slight_smile:

Hey Guys,

Just a quick update.
The new version (1.4.0) of the library is released and it now supports the I2C magnetic sensors.
You can get it through Arduino Library Manager, directly from the master branch or minimal branch.

The library examples have been updated as well as the documentation. So let me know how it goes!

1 Like

If you are ordering a AS5600 you may need to purchase a 6mm x 2.5 mm diametric magnet as they are not typically included. They cost about $4 for 10 on ebay. My little ax-2804 gimbal motor seemed to have a weak diametric charge ‘built in’ - it was reading 100 magnitude whereas a proper magnet should be 1000+. Seems to work though.

If you are looking for a way to measure magnitude then I’ve written a lib for the as5600:


It exposes a bunch more of the registers on the AS5600 to config and read status e.g. you can tweak onboard filters (trading accuracy for speed) or measure magnitude of fields strength which is useful to tune/adjust the distance of sensor ic to magnet. Haven’t tested it a great deal but most of it should work.

You don’t need my library for SimpleFOC - AS5600 implementation included in SimpleFOC works fine - I’ve tested it.

2 Likes

Interesting. Makes me wonder what else that chip can be used for if we have access to that sort of data. And yeah I found some 4mmx3mm diametric magnets on aliexpress. Got 100 for $5 and quality seems good.

There is a new version of coming out called AS5600L. It allows you to set the i2c address which means more than one device can be attached to the same i2c bus, this was a major flaw in the old version. I wonder if this is the reason that the old AS5600 can be bought for only 2 or 3$

indeed any of the ones from aliexpress are this way. I have some samples of the AS5200L in which you can set the i2c address but didnt try it out though. I think also all the as5600s you get with the white board dont have any analog output, or at least when we tried to get anything from them I couldnt see anything at all on the scope. For low speed applications an i2c multiplexer works fine though…

Hi, I have bought a couple of AS5600 (white cheap boards) to try out.
I’m just playing with the Magnetic_sensor_i2c example, but I see that the range of read values goes from 4.00 to 4.80. The same if instead of read the 0x0E ANGLE register I point to the 0x0C RAW Angle register.
Is it normal? are there any other numbers of precision which aren’t printed?
The magnet is 6x2,5 diametral and there’s 1mm gap between the magnet and the chip.

EDIT:
I made getRawCount() public, and reading that gives me a range from 2610 to 3130. isn’t that strange?
Seems like 9bit of readings… And shouldn’t the counter take also consideration of turns, as I see in the code?

Thanks, Davide.

Hi @dab, I had similar issues when first starting out with the AS5600. The problem was that I was missing the 4.7 kΩ pull up resistors on the SDA and SCL lines. Can you make sure you set set them up properly?

That is strange. I’ve just tested an as5600 using:

MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);

I get 2*PI radians per rotation and raw_count of 0 to 4095 (12 bit).

Feels like the first 3 bits of your 12 bit are always 101 (=2560 decimal) but you can read your last 9 bits. This would give a range of 2560-3071. I’d imagine you’ll probably see it going through that range 8 times a rotations because those 3bits are AWOL.

Can you tell us a bit more about your setup? What board? Does it have pullups on sda, scl? It might be worth playing with the clockspeed of i2C.

I’d also try printing out readArray[0] and readArray[1] inside MagneticSensorI2C::read() There is a bit of bitmasking there that should be grabbing the last 4bits of the first byte and all 8 bits of the second byte.

Those boards have 10k pullups on SDA and SCL, I don’t think the problem is there, because I have consistent readings.
Maybe the problem could be I’m powering the chip with 3,3V? As written in the datasheet I soldered together pins 1 and 2, respectively 5V and 3,3V and powered the board with 3,3V on that pins.
Any of you is powering that chip with 3,3V and has it working?

My test code is this:

#include <SimpleFOC.h>

// Example of AS5600 configuration
//MagneticSensorI2C sensor = MagneticSensorI2C(0x36, 12, 0x0E, 4);
MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);

void setup() {
Serial.begin(115200);
sensor.init();
Serial.println(“Sensor ready”);
_delay(1000);
}

void loop() {
Serial.print(sensor.getAngle());
Serial.print("\t");
Serial.println(sensor.getVelocity());
}

I have some time to test it out.
I added two ints to print values out this way:

int MagneticSensorI2C::read(uint8_t angle_reg_msb) {
// read the angle register first MSB then LSB
byte readArray[2];
uint16_t readValue = 0;
// notify the device that is aboout to be read
Wire.beginTransmission(chip_address);
Wire.write(angle_reg_msb);
Wire.endTransmission(false);

// read the data msb and lsb
Wire.requestFrom(chip_address, (uint8_t)2);
for (byte i=0; i < 2; i++) {
readArray[i] = Wire.read();
}

// depending on the sensor architecture there are different combinations of
// LSB and MSB register used bits
// AS5600 uses 0…7 LSB and 8…11 MSB
// AS5048 uses 0…5 LSB and 6…13 MSB
lsb_read_temp = readArray[1];
msb_read_temp = readArray[0];
readValue = ( readArray[1] & lsb_mask );
readValue += ( ( readArray[0] & msb_mask ) << lsb_used );
return readValue;
}

and I’m finally printing in the serial monitor the Angle, MSB and LSB in Binary, the SUM and the two MASKS.
LSB counts from 00000000 to 11111111 apparently, while MSB
goes from 00001001 to 00001100 and back, in a trangular way (/\\/\/\/\)

…I’m suspecting there could be a problem with the magnet, not being polarized as expected…
EDIT:
AARGH! yes, sorry… I confirm that they sent me the wrong magnets, axially polarized.
so, pay attention and DON’T buy from this link: Aliexpress -DON’T-BUY- link

I’m sorry to having wasted your time for such a silly thing… I’ve mounted the magnets vertically and it works as expected…so sorry…

2 Likes

Is there a way to set or see the as5600 i2c settings and set them such as it states in the datasheet?

Supported Modes
• Random/Sequential read
• Byte/Page write
• Automatic increment (ANGLE register)
• Standard-mode
• Fast-mode
• Fast–mode plus

Our i2c is setup for 400khz but I am just wondering if the as5600 is keeping up or if its 100khz

@dab - I was about to suggest the magnet! It is not a waste of time as we’ve all learnt how to spot dodgy magnets!

@Adam_Donovan - the SimpleFOC library doesn’t support those features. I wrote a library a few months back when I first got the AS5600 that might help - you can read/write registers/config. Be careful of burnAngle() and burnSettings() as these settings can only be burnt once or three times (can’t remember which). IMHO its better to never burn and just set them each time on boot.

The library isn’t supposed to work with SimpleFOC but might help. Didn’t do a massive amount of testing so there might be a couple of bugs.

It’s pretty easy to test whether changing clock speed does anything. Just call sensor.getAngle() in a loop and see how many it does a second. When I test on esp32 I tried 100K, 400K, 1M, and 3.4M. All worked, big improvements up to 1M then negligible improvement to 3.4M. I didn’t need to set anything on the AS5600 to ‘unlock’ these faster speeds.

@Owen_Williams yes we were playing with your code tonight trying to get into it:) 1M hey but how? I think I am.missing where in the code to test that.