MagneticSensor I2C communication implementation

Hey guys, I just wanted to let you know that I am currently implementing the I2C support for the MagneticSensors and I will release it in the SimpleFOClibrary next week.

If you would like to help me test in the mean time, plese check the test_sensors branch of the Arduino-FOC:

I have just ordered the I2C supporting sensor and it will need some time to arrive. So it would help me a lot if some of you have time to run the code, it would definitely speed up the process.
Let me know if you have any problems/suggestions running the code!

Thanks!

Great, I tested against what I tried to implement with i2c and I can say it works fantastically. -no hunting once tuned with the same settings and faster, I wish I had the time to test and play more(but hey I just did get married and am on about to go on a month long bike ride as honeymoon). I do wonder sometimes about the noise(residual timing frequency conflicts/harmonics) but this is probably going to be very motor specific

Hey @Adam_Donovan congrats, you are a happy man :smiley:

Thanks for testing the code, in the mean time I have bought myself one AS5600 and I have tested the code well and it seams to work well. It does perform worse than SPI sensor though. And one of the reasons is the noise, but also longer read time. Here are Arduino UNO has mean times for loopFOC() +move() with magnetic sensors:

  • SPI - 700us
  • I2C- 1100us

So in general this will mean around 30% worse performance in terms of smoothness and it will limit the top velocity by this much also. But in many applications it will still be good enough.

It is important to say that for higher velocities I2C sensor performs much better than encoder for Arudin UNO.

SimpleFOClibrary will support these sensors from the release version 1.4.0. But the code is already in the master branch if you guys want to use it. I just did not have time to document it properly. When I do I’ll publish the release.
The usage is very straightforward and there should not be too much problems there. You can find how to use it from library examples directly.

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! :smiley:

New here. I’ve tested with as5600. I’m getting good angles from it over i2c.

My setup is esp32 + shield + as5600 + turnigy ax-2804 100t gimbal. I’ve made a couple of changes to get it to compile on esp32, still trying to get it calibrated.
Thanks for hardware/software. A great learning aid!

Hey @Owen_Williams, that is is a great setup. ESP32 is very powerful and will have much better performance than Arduinos. But it is a bit tricky to get it to work. Especially the PWM part.
@David_Gonzalez has made this conversion successfully and I’m sure he can help you with it. I hope to implement the off-the-shelf support for ESP32 using his code soon as well.
Don’t hesitate to post a topic about the troubles you’re having or even GitHub issue. It will make me implement the support earlier :smiley:

The i2c speeds can be increased by setting Wire.setClock
> void MagneticSensorI2C::init(){
>
> //I2C communication begin
> Wire.begin();
> Wire.setClock(1000000); // 1 million
Update: My times are simply for sensor.getAngle() so can’t be compared with loopFOC times above
On my esp32 it is defaulting to 100K speed.
100K -> 559us
400K -> 206us
1M -> 147us
3.4M -> 147us

Hey Owen, thanks for the heads up. I will look into it.
I have talked to @David_Gonzalez yesterday and we were able to integrate ESP32 into the library code. I will try to do the full integration today and publish it as soon as he testes it. :smile:

Excellent. I’ll be looking out for it.