I connected the pins and tried to run this code, but the printout displays -1 (no data?)
#include <Wire.h>
byte x = 0x00;
void setup() {
Wire.begin();
Serial.begin(9600);
}
void loop() {
Wire.beginTransmission(0xD0);
Wire.write(0x44);
Wire.write(1);
Wire.endTransmission();
Wire.requestFrom(0xD0, 1);
int x = Wire.read();
Serial.print(x);
delay(1000);
}
Please help, I tried to look through the original code for the module to find a way to get the arduino to read the data, but it's very complicated. All I have found so far is a list of I2C addresses.
Thanks
Just one small question, in some of the very complicated official code from the Waveshare site (not the one you just showed me), it defines a bunch of addresses and the each have a high/low thing. What does high and low mean??
Those are the gyro data register addresses. The registers are 1 byte wide. Each reading is an int data type (2 bytes) the high or most significant byte and the low or least significant byte. To combine them back into an int, multiply the MSB by 256 and add the LSB.
The MPu9255/MPU9250 (different manometer) has a MPU6050 and a compass chip in one. the compass is linked to the MPU9055 the same way as you would if you had the MPU6050 and compass as separate chips( secondary i2c link from the MPU6050 to the manometer). So with that in mind the incredible library by by Jeff Rowberg has tons of examples that can help you access all the features available in the MPU9055. I have both the MPU6050 and the MPU9055 And can access all the features with that library including the compass. as for the altimeter you will access it directly with separate code
What is the theory behind MSB and LSB? Is it that 1 byte can only be 256 which would be a crap 'resolution' for something like a gyro? Therefore two bytes are written to form a bigger number?
1 byte can be 0 to 255, 0x00 to 0xFF.
256*256 != 65,535, it is 65,536, which is Not 0xFFFF
(255<<8 ) + 255 = 65,535 // shift MSB into upper 8 bits, add LSB into lower 8 bits
or (255 *256) + 255
or
(uint8_t * 0x100) + uint8_t = uint16_t
(uint8_t <<8 ) + uint8_t = uint16_t
buffer[0] is 8 bit or uint8_t
buffer[1] is 8 bit or uint8_t
<< 8
tells us to shift the buffer[0] over 8 bits and stick it into a 16 bit int (int16_t) that is signed
11001101 now == 1100110100000000
| buffer[1];
Bitwise OR (|)
The bitwise OR operator in C++ is the vertical bar symbol, |. Like the & operator, | operates independently each bit in its two surrounding integer expressions, but what it does is different (of course). The bitwise OR of two bits is 1 if either or both of the input bits is 1, otherwise it is 0. In other words:
so here's the math
buffer[0] = 11001101
buffer[1] = 11110001
1100110100000000 (int) buffer[0] << 8
11110001 (byte) buffer[1]
----------
1100110111110001 (buffer[0] << 8 | buffer[1]) - returned result is a 16 bit int
Ohhh thank you very much. I didn't realize that the << 8 shifted the MSB up by 8. So I was wondering why you would want to merge two bytes XD. What is the highest that a gyro axis output can reach?
Gyroscope Features
Digital-output X-, Y-, and Z-Axis angular rate sensors (gyroscopes) with a user-programmable full scale range of ±250, ±500, ±1000, and ±2000°/sec
External sync signal connected to the FSYNC pin supports image,
Accelerometer Features
Digital-output triple-axis accelerometer with a programmable full scale range of ±2g, ±4g, ±8g and ±16g
Integrated 16-bit ADCs enable simultaneous sampling of accelerometers while requiring no external multiplexer
So I was wondering why you would want to merge two bytes
its simple the communication protocol only uses transfers in 8 bits. so if you need a higher number than 255 you need to add more bits to the byte making it an int. and then if you need more you could add 4 bytes together to make a long