Data retrieved via magnetometer

Hello everyone,

I am currently working on a robotics project that requires the use of a magnetometer.

-I’m looking at x y z flux values.
-I also use the “heading” function
-I’ve coded a heading function

When I point the phone north, I get X=0 Y=20, which is normal.
The “heading” function returns 90° and not 0 which may be normal depending on thunkable logic (if trigonometric angle returns 0 = west; 90 = north; 180 = east).

I’ve coded the Atan2 function myself and the modulo returns the same value as the heading (variable “azimut app 2"” = “app variable heading”).

My questions are :

Can I trust the flux reading to make my calculations (the flux respects Y to the top of the screen X from left to right), in order to find north = 90 on all phones that download the application?
In fact, magnetometers have no mounting convention in smartphones, and the data is processed by the devices.
The data streams can be
Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED
or
Sensor.TYPE_MAGNETIC_FIELD
which would not give an orientation relative to the phone but to the sensor itself.

My second question is:
Is it possible to synchronize the accelerometer to correct drift if the phone isn’t perfectly flat?

As shared on a different support channel, we use the library expo-sensors for this component. he doc for that is here:
https://docs.expo.dev/versions/latest/sdk/magnetometer/