i tried this 2 methods it shows x=0 y=0 z=0 while with the pro micro board it works perfectly could someone help me please #include <QMC5883LCompass.h> #include <Wire.h>
//TwoWire Wire1(PB11, PB10);
//TwoWire Wire1(1,I2C_FAST_MODE);
TwoWire Wire1(2,I2C_FAST_MODE);
QMC5883LCompass compass;
Looking at your code, it appears that your QMC5883LCompass library code has no knowledge of your Wire1 object.
Usually sensor libraries that employ communications over I2C use the standard Wire library by default, together with the board's SDA and SCL pins.
However, sometimes libraries also permit an additional I2C port to be specified by passing in the address of a second Wire object as argument. For example the Adafruit BMP280 barometer library's constructor allows a second Wire library to be specfied, (but uses the address of the Wire library by default):
Adafruit_BMP280(TwoWire *theWire = &Wire);
Therefore in your sketch you could pass in the address of the Wire1 object (after instantiating/creating it) like this:
Adafruit_BMP280 bmp280(&Wire1);
If you check the code of your QMC5883LCompass library, you'll be able see if it supports this feature.
#include "Arduino.h" #include "Wire.h"
this is the libary it is using i think i should modify from here
/**
INIT
Initialize Chip - This needs to be called in the sketch setup() function.
@newtechai The library as it stands doesn't support an additional Wire object, but it should be possible to easily modify it, so that it can.
I made the changes and for expediency did a compilation test using the Arduino Due, which I know by default supports two I2C ports: Wire and Wire1. This compiled successfully.
Here are the changes that I made to the QMC5883LCompass.h and QMC5883LCompass.cpp files:
Firstly QMC5883LCompass.h:
Change line 11 to:
QMC5883LCompass(TwoWire* p_wire = &Wire);
Then add this line to the list of private variables: