wollewald / ICM20948_WE

An Arduino library for the ICM20948 9-axis accelerometer, gyroscope and magnetometer. It contains many example sketches with lots of comments to make it easy to use.
https://wolles-elektronikkiste.de/en/icm-20948-9-axis-sensor-part-i
MIT License
28 stars 5 forks source link

Compass #6

Open minhanh1234 opened 3 months ago

minhanh1234 commented 3 months ago

Hi

Would you know if this chip can calculate compass angle like most magnetometer and would you have any example code to calculate rotation count? Example if i rotate the gyro on a table? (Example: 2 counter clockwise ration)

Thanks

wollewald commented 3 months ago

Hi @minhanh1234, you can use the magnetometer data to make a compass out of it. You would need to determine the max and min values for the x- and y-axes and then interpolate your measured values to determine the direction. However, the magnetic field strength depends on your location (e.g. inside and outside of buildings) or other factors like electric devices which are near to the module. Another factor to consider is that if you vary the z-angle, it will also influence the magnetic measurements. I tried a bit, the it became too complex and I gave up. The other option to determine the direction of the x- and y-direction (yaw-angle) is to constantly measure gyroscope data: angle/time * time = angle. Of course, you will have certain error when using this method and the errors can add up over time. So, in summary, basically it's possible, but I do not have plans to implement this as a feature. Hope this helps a bit.