Using magnetic sensor

Announcements

Measure CO2 When It Matters - Infineon’s XENSIV™ PAS CO2 now comes in SparkFun Red. Check it now!

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
WaltSnowrancruz
Level 1
Level 1
5 sign-ins First question asked Welcome!

Hi

I want to get the three coordinates values of the magnetic field measured by the sensor of my phone. For this, I get a handle to the SensorManager by using sm=(SensorManager)getApplicationContext().getSystemService(Context.SENSOR_SERVICE), then get the sensor with cm=sm.getDefaultSensor(SensorManager.SENSOR_MAGNETIC_FIELD). I then register a SensorEventListener to the SensorManager with sm.registerListener(new SensorListener(),cm,SensorManager.SENSOR_DELAY_UI).

The classSensorListener is a class of my own implementing the SensorEventListener interface. In it's OnSensorChanged method, I get the values from the sensor and I display them. The problem is that I only get the values 1,0 and 0. And they are rarely updated (I have put a counter on the onSensorChanged calls to see how often the update takes place). Changing the time to SENSOR_DELAY_NORMAL doesnot improve anything.

To check if the problem was related to the magnetic sensor, I have added, in the same way, a listener to an accelerometer sensor. The result is very confusing : now, the magnetic sensor generates updates, but not the accelerometer one. And if I remove the accelerometer omegle.2yu.co sensor event listener, I still receive the magnetic sensor events which where missing before adding the accelerometer sensor event listener.(???????????)

Any idea about what is wrong in omeglz my code?

0 Likes
1 Reply
Deepa_V
Moderator
Moderator
Moderator
First comment on KBA 50 likes received 250 replies posted

Hi @WaltSnowrancruz ,

This forum is for Infineon Products and we regret that we cannot offer support for your issue.  Do let us know if you face any issues with our products. 

Best Regards,

Deepa

0 Likes