Snaresman:
Hello
I have a BME280 temperature, pressure and humid module and a H5883 magnetometer hooked to the same I2C bus on a Mega2560. The BME280 works good. The H5883 works. Bit they won't work together. Separate sketches will work each module. I'm trying to combine them for a weather station. When I do, the BME280 works, but the H5883 will not. -1 for each of the three axis. The wiring is the same for both. I haven't touched it, just the sketches. It has to be an addressing issue in the sketch. How can I get it to talk to both? I want to add more modules later. I've included the sketch I'l working with so far. Any help is appreciated.
So far all my searching shows the physical wiring, the bus protocol and talking to one device.
Snaresman:
Hello
I have a BME280 temperature, pressure and humid module and a H5883 magnetometer hooked to the same I2C bus on a Mega2560. The BME280 works good. The H5883 works. Bit they won't work together. Separate sketches will work each module. I'm trying to combine them for a weather station. When I do, the BME280 works, but the H5883 will not. -1 for each of the three axis. The wiring is the same for both. I haven't touched it, just the sketches. It has to be an addressing issue in the sketch. How can I get it to talk to both? I want to add more modules later. I've included the sketch I'l working with so far. Any help is appreciated.
So far all my searching shows the physical wiring, the bus protocol and talking to one device.
For starter run this I2C scanner sketch and check what the addresses are for each of you chips.
Then I would check that the addresses match what the datasheets say the default addresses should be.
It may be that the address of the H5883 is manually set to an address other than the default through the hardware a address pin.
In that case you would have to modify the library to use the non-default address of your actual chip.
That is one possibility anyway, and that is where I would start.
// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011
#include <Wire.h>
void setup() {
Serial.begin (115200);
// Leonardo: wait for serial port to connect
while (!Serial)
{
}
Serial.println ();
Serial.println ("I2C scanner. Scanning ...");
byte count = 0;
Wire.begin();
for (byte i = 8; i < 120; i++)
{
Wire.beginTransmission (i);
if (Wire.endTransmission () == 0)
{
Serial.print ("Found address: ");
Serial.print (i, DEC);
Serial.print (" (0x");
Serial.print (i, HEX);
Serial.println (")");
count++;
delay (1); // maybe unneeded?
} // end of good response
} // end of for loop
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
} // end of setup
void loop() {}