Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting extreme readings #1

Open
mikevanis opened this issue Mar 15, 2017 · 3 comments · May be fixed by #6
Open

Getting extreme readings #1

mikevanis opened this issue Mar 15, 2017 · 3 comments · May be fixed by #6
Labels

Comments

@mikevanis
Copy link

Hi @sparkfun,

I'm using this module with an ESP-12 and I'm just running the Basic example. I'm getting very unusual readings. Here is a typical sample:

X: 64895, Y: 425, Z: 64768

What could this be? Have I got a damaged MAG3110? Is there a weird scale value register set somewhere? Any clues would be much appreciated.

EDIT: Upon further investigation - the MAG3110 has two 8-bit registers for each axis. In this library, they're joined and packaged into an int. Shouldn't they be packed into a uint16_t or an unsigned int? Surely there's no sign in the values the magnetometer will spit out. Could I be getting these values due to an overflow?

@ejosh
Copy link

ejosh commented Mar 20, 2017

After digging slightly more into the solution for your issue submitted on this other repo, this should definitely use the signed int16_t, the sensor datasheet at one point refers to returning values from -30,000 to +30,000 for each axis. (Section 5.1.2, p.17)

@bboyho bboyho added the bug label Jun 12, 2019
sanyi added a commit to sanyi/SparkFun_MAG3110_Breakout_Board_Arduino_Library that referenced this issue Jul 14, 2020
Fixes sparkfun#1, according to datasheet section 5.1.2 "X-axis, Y-axis, and Z-axis 16-bit output sample data of the magnetic field strength expressed as signed 2's complement numbers."
@sanyi
Copy link

sanyi commented Jul 14, 2020

Here we can only cast x = (int) values[0]; if we are sure int has the same bite size as (in our specific case) 16. Obviously this is not the case so the sign bit is misinterpreted as 2^15. However being explicit x = (int16_t) values[0]; does the trick.

@DiscoMan18
Copy link

This library perfectly works on ESP32 devices. I checked it. Just change int to int16_t everywhere in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants