" Hi Guys,
firstly I want to say Hello to everybody and thanks for adding me to the group
I am working on electronic compass project, my HW are: Arduino Uno, MPU-9255, and 1.8 inch LCD module from Waveshare.
MPU is conected by I2C, LCD by HW_SPI. Everything is working fine but...
My general problem is with raw data readings from magnetometer AK8963C. It connects, reads and show me results but this data are strange. Range of raw data should be from -32760 to 32760. And in some cases readings are almost good in some not.
1. Q
Is my byte shifting for mx, my, mz(those variables are ints) good? -> int16_t mx = ((xl << 8) | xh );
Because in this kind of shiftings where low byte goes to high position in int values of mx/my/mz are in range..almost.
If I change it to int16_t mx = ((xh << 8) | xl ); which most of libraries on github have, the values of mx are not in range they are from -150 to +31 with two times 0. And this is strange.
For checking why I barely read values from xl/yl/zl and xh/yh/zh and those values were:
xl, yl, yz - range from 0 to 255 like should have unsigned 8 bit int, while
xh- has only two values 0 or 255, yh- 0 or 1 and zh - 0 or 255 and what I am thinking, they only change the sign of value, especially that it happens when rotating for about 180 degrees in every axis.
2. Q
Can anybody check those values in his/hers sensor and we can compare? Maybe my MPU is broken or something else. Maybe I am doing something wrong? If You need more code please tell. I am attaching sensor datasheet. All other sensors are switched off(gyroscope and accelerometr).
Here is a sample of code from my library which is change fragment from somebody`s lib. I know that it is not very good but firstly i want to get good readings from registers than make good code. "
Code:
firstly I want to say Hello to everybody and thanks for adding me to the group
I am working on electronic compass project, my HW are: Arduino Uno, MPU-9255, and 1.8 inch LCD module from Waveshare.
MPU is conected by I2C, LCD by HW_SPI. Everything is working fine but...
My general problem is with raw data readings from magnetometer AK8963C. It connects, reads and show me results but this data are strange. Range of raw data should be from -32760 to 32760. And in some cases readings are almost good in some not.
1. Q
Is my byte shifting for mx, my, mz(those variables are ints) good? -> int16_t mx = ((xl << 8) | xh );
Because in this kind of shiftings where low byte goes to high position in int values of mx/my/mz are in range..almost.
If I change it to int16_t mx = ((xh << 8) | xl ); which most of libraries on github have, the values of mx are not in range they are from -150 to +31 with two times 0. And this is strange.
For checking why I barely read values from xl/yl/zl and xh/yh/zh and those values were:
xl, yl, yz - range from 0 to 255 like should have unsigned 8 bit int, while
xh- has only two values 0 or 255, yh- 0 or 1 and zh - 0 or 255 and what I am thinking, they only change the sign of value, especially that it happens when rotating for about 180 degrees in every axis.
2. Q
Can anybody check those values in his/hers sensor and we can compare? Maybe my MPU is broken or something else. Maybe I am doing something wrong? If You need more code please tell. I am attaching sensor datasheet. All other sensors are switched off(gyroscope and accelerometr).
Here is a sample of code from my library which is change fragment from somebody`s lib. I know that it is not very good but firstly i want to get good readings from registers than make good code. "
Code:
C:
uint8_t MPU9255::read_mag()
{
byte drdy_dor = read(MAG_address, 0x02);
dor_status = drdy_dor;
if(drdy_dor==1 || drdy_dor==3)
{
byte xl = read(MAG_address, 0x03);//reading from mag registers from 0x03-0x08
byte xh = read(MAG_address, 0x04);
byte yl = read(MAG_address, 0x05);
byte yh = read(MAG_address, 0x06);
byte zl = read(MAG_address, 0x07);
byte zh = read(MAG_address, 0x08);
byte hofl = read(MAG_address, 0x09);//has to be read to acknowledge status reg that can continue Measurements
hofl_status = hofl; //overflow status
if(hofl!=1)
{
int16_t mx = ((xl << 8) | xh );
int16_t my = ((yl << 8) | yh );
int16_t mz = ((zl << 8) | zh );
return 0;
} return 1;
} return 2;
}
Attachments
-
649.7 KB Views: 1