2017-10-20 01:46 AM
Hello all,
my problem is the output of the x,y and z registers.
The content of the registers change when moving, but only with fast movement. The values change during the acceleration. Unfortunately, after the movement the values fall back to the same value again. The problem is, the values are the same in any orientation. My program accepts different values for x, y and z register in different positions, but the sensor doesn’t change these values. When the sensor is horizontal I accept g_z = 1, g_x = 0, g_y = 0 and when I turn it by 90 degrees I estimate g_z = 0,
g_y = 1, g_x = 0
at least the values should be different. However the values are the same.
Maybe I made some mistakes in the register settings or the sensor is not able to do this?????
My register settings:
Address value
0x1f 0xc0= 1100 0000 // edit: revised
0x20 0x77= 0111 0111
0x23 0x80= 1000 0000
0x24 0x70= 0111 0000
0x2e 0x80= 1000 0000
2017-10-20 02:17 AM
The configuration seems to be correct, I think the problem will be in your reading procedure. Please check that you red both low and high part of the output registers. I would recommend you to start read the data without using FIFO, because it is little bit more complex.
Note: 0xC0 = 1100 0000
2017-10-20 08:00 AM
Hello Miroslav,
i changed the sensor to non-FIFO mode, but the values are still the same in any direction.
Here is how I convert the data from the register to mg:
uint8_t hight;
uint8_t low; int16_t result; double result1;low = readvalue(0x28);
hight = readvalue(0x29);
result = ((hight<<8) | low) >> 6; // convert to 10 bit
if(result & 1<<9){result |= (1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(1<<10); //convert 10 bit in 16 bit two's complement }result1 = result*4 / 1024.0; // *4 because 2g mode, 1024 because of 10 bit
2017-10-20 08:30 AM
The conversion is not correct (i.e. result = ((hight<<8) | low) >> 6; you rotate the high byte in 8 bit variable).
Use following commands, it will also manage the two's complement format.
result = ((int16_t)high<<8)+(uint16_t)low;
result = result>>6; // in case of normal mode = 10bit output
result1 = result * 4; // LSB to mg (FS=2g), see sensitivity in datasheet
2017-10-20 09:13 AM
Okay, thank you!
Now I have other values, but the basic values in the registers still not changing.
Do you have another idea??
2017-10-23 04:06 AM
I guess you are not reading all the output values and because the BDU is enable the data are not updated. You can try to disable BDU, to confirm this theory
You can also share the complete code so I can look at it.
2017-10-24 01:26 AM
Okay,
Here is how I set the sensor:
sensor::sensor(char i){
char I2C_ADDR = i; vector <string> a; a.push_back('i2cset -y 0 0x19 0x24 0x00'); a.push_back('i2cset -y 0 0x19 0x2e 0x00'); a.push_back('i2cset -y 0 0x19 0x1f 0xc0'); a.push_back('i2cset -y 0 0x19 0x23 0x00'); a.push_back('i2cset -y 0 0x19 0x20 0x57'); a.push_back('i2cset -y 0 0x19 0x30 0x00'); for(auto tmp : a) system(tmp.c_str()); this->fd = open('/dev/i2c-0', O_RDWR); if (fd < 0) { cout << 'Error opening file: ' <<endl; } if (ioctl(fd, I2C_SLAVE, I2C_ADDR) < 0) { cout << 'ioctl error: ' <<endl; }}Here is how I read the sensor(&sharpinclude <linux/i2c-dev.h>):
char sensor::readvalue(char hex){
char arr = hex; write(fd, &arr ,1); read(fd, &arr, 1); return arr;}and here is how I print out the values:
I only show one axis, because they are all alike.
int8_t hight;
uint8_t low; int16_t ergebnis;cout <<endl;
low = readvalue(0x28); cout << hex << +low << ' '; hight = readvalue(0x29); cout << hex << +hight << ' ';cout << '\t\t' << 'achse x: ';
ergebnis = ((int16_t)hight<<8)+(uint16_t)low;
ergebnis = ergebnis>>6; ergebnis = ergebnis * 4; cout << dec << ergebnis << ' ';2017-10-24 05:32 AM
Does the value change if the BDU is disabled?
Unfortunately I'm not expect on linux programming so I can't help you with that, but the sensor configuration is correct, it will measure acceleration at 100Hz.
2017-10-24 06:07 AM
Unfortunately not
:((
.Maybe i have the wrong sensor. Today I tried a mpu6050 and it gives me the right value of x and y angle. Also the values changing in different positions, but I have to do it with theLIS2DH
Thanks anyway!