Hello all,
I'm currently involved in a project and struggling for this issue for many days..
I badly need help.
I'm aiming to use barometer sensors (MPL115A2 ) and IMU sensors (BNO055) with a MKR1000 board, using I2C.
Two 10k ohm pullup registers are attached on SDL and SDA line respectively (I've also tested many other configurations).
When I use a barometer only, it reads well.
When I use an IMU sensor only, it reads well.
When use the both, only the IMU works and the barometer starts reading strange values.
As shown in the following code and the result, some strange values are read from the barometer.
Please help!! (any clue is welcome!)
The sensor values are not post-processed (e.g., multiplied by coefficients, etc).
Please feel free to comment if there is further information I can provide.
(I've also posted the same issue in Adafruit forum.)
**Code:
#include "Arduino.h"
#include <Wire.h>
#define MPL115A2_ADDRESS (uint8_t) 0x60
#define BNO055_ADDRESS (uint8_t) 0x29
// library functions are minimized for code clarity
// Using MKR1000
// Two 10k ohm pullup registers are attached on SDL and SDA line respectively
void write_reg(uint8_t _addr, uint8_t _reg){
Wire.beginTransmission(_addr) ;
Wire.write(_reg);
if (_addr == MPL115A2_ADDRESS && _reg == 0x12){
Wire.write(0x00);
}
Wire.endTransmission();
delay(30);
}
void read_hex(uint8_t _addr, bool ifPrint){
Wire.requestFrom(_addr, 8 );
for (uint8_t j = 0; j < 8; j++) {
if (ifPrint){
Serial.print(Wire.read(), HEX);
Serial.print(" ");
}else
Wire.read();
}
if (ifPrint)
Serial.print("\n");
delay(30);
}
void setup() {
Serial.begin(115200);
Wire.begin();
Wire.setClock(400000L); // MPL115A2 works for 400K. Not works for e.g., 100K as far as I experienced
delay(3000);
//1) MPL115A2 start conversation and read
Serial.println(" ============ MPL115A2 only ============ ");
for (int i = 0; i<20; i++){
write_reg(MPL115A2_ADDRESS, 0x12); // reg: MPL115A2 start conversation
write_reg(MPL115A2_ADDRESS, 0x00); // reg: MPL115A2 pressure
read_hex(MPL115A2_ADDRESS, 1);
}
//2) read from both MPL115A2 and BNO055
Serial.println(" ============ MPL115A2 and BNO055 ============ ");
for (int i = 0; i<20; i++){
write_reg(MPL115A2_ADDRESS, 0x12); // reg: MPL115A2 start conversation
write_reg(MPL115A2_ADDRESS, 0x00); // reg: MPL115A2 pressure
read_hex(MPL115A2_ADDRESS, 1);
write_reg(BNO055_ADDRESS, 0x20); // reg: BNO055 quaternion
read_hex(BNO055_ADDRESS, 0); // this line doesn't affect the result
}
}
void loop() {
delay(1000);
}
**Printed result of MPL115A2 readings:
============ MPL115A2 only ============
6A 0 82 0 48 1C A8 4E
6A 0 81 C0 48 1C A8 4E
6A 0 82 40 48 1C A8 4E
6A 0 82 0 48 1C A8 4E
6A 0 82 0 48 1C A8 4E
6A 0 82 0 48 1C A8 4E
6A 0 82 0 48 1C A8 4E
6A 0 81 C0 48 1C A8 4E
6A 0 82 0 48 1C A8 4E
6A 0 82 0 48 1C A8 4E
6A 0 81 C0 48 1C A8 4E
6A 0 81 C0 48 1C A8 4E
6A 0 82 40 48 1C A8 4E
6A 0 82 0 48 1C A8 4E
6A 0 82 0 48 1C A8 4E
6A 0 82 0 48 1C A8 4E
6A 0 82 0 48 1C A8 4E
6A 0 82 40 48 1C A8 4E
6A 0 82 0 48 1C A8 4E
6A 40 82 0 48 1C A8 4E
============ MPL115A2 and BNO055 ============
6A 0 82 0 48 1C A8 4E
6A 0 82 0 48 1C A8 4E
6A 40 82 0 48 1C A8 4E
6A 0 81 C0 48 1C A8 4E
6A 0 82 0 48 1C A8 4E
6A 0 82 0 48 1C A8 4E
0 0 2 0 48 1C A8 4E
0 0 1 40 48 1C A8 4E
0 0 2 40 48 1C A8 4E
0 0 2 0 48 1C A8 4E
0 0 2 0 48 1C A8 4E
0 0 1 40 48 1C A8 4E
0 0 2 0 48 1C A8 4E
0 0 2 0 48 1C A8 4E
0 0 2 0 48 1C A8 4E
6A 0 82 0 48 1C A8 4E
6A 0 82 0 48 1C A8 4E
0 0 1 40 48 1C A8 4E
0 0 2 40 48 1C A8 4E
0 0 2 0 48 1C A8 4E