Hello There...
First, please watch my code..
#include <Wire.h>
extern "C" {
#include "utility/twi.h" // from Wire library, so we can do bus scanning
}
#define TCAADDR 0x70
#define hellee 0x71
void tcaselect(uint8_t i) {
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
void helle(uint8_t i) {
if (i > 7) return;
Wire.beginTransmission(hellee);
Wire.write(1 << i);
Wire.endTransmission();
}
#include <Wire.h>
#include <MechaQMC5883.h>
MechaQMC5883 qmc0;
MechaQMC5883 qmc1;
MechaQMC5883 qmc2;
MechaQMC5883 qmc3;
MechaQMC5883 qmc4;
void setup() {
Wire.begin();
Serial.begin(9600);
qmc0.init();
qmc1.init();
qmc2.init();
qmc3.init();
qmc4.init();
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
//Serial.println("CLEARSHEET");
// Serial.println("CLEARDATA");
//Serial.println("x,y,z,azimuth");
//qmc.setMode(Mode_Continuous,ODR_200Hz,RNG_2G,OSR_256);
}
void loop() {
int x0, y0, z0;
int x2, y2, z2;
int x3, y3, z3;
int x4, y4, z4;
int x5, y5, z5;
int x6, y6, z6;
int x7, y7, z7;
int x1, y1, z1;
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
tcaselect(4);
//Serial.println("CLEARDATA");
//Serial.println("LABEL,TIME,TEMP,HUMI")
//float azimuth; //is supporting float too
qmc0.read(&x0, &y0, &z0);
Serial.print(x0);
Serial.println(" a0");
// Serial.print(y0);
// Serial.println(" b0");
Serial.print(z0);
Serial.println(" c0");
tcaselect(5);
//Serial.println("CLEARDATA");
//Serial.println("LABEL,TIME,TEMP,HUMI")
//float azimuth; //is supporting float too
qmc1.read(&x1, &y1, &z1);
Serial.print(x1);
Serial.println(" a1");
// Serial.print(y0);
// Serial.println(" b0");
Serial.print(z1);
Serial.println(" c1");
tcaselect(6);
//Serial.println("CLEARDATA");
//Serial.println("LABEL,TIME,TEMP,HUMI")
//float azimuth; //is supporting float too
qmc2.read(&x2, &y2, &z2);
Serial.print(x2);
Serial.println(" a2");
// Serial.print(y0);
// Serial.println(" b0");
Serial.print(z2);
Serial.println(" c2");
tcaselect(7);
//Serial.println("CLEARDATA");
//Serial.println("LABEL,TIME,TEMP,HUMI")
//float azimuth; //is supporting float too
qmc3.read(&x3, &y3, &z3);
Serial.print(x3);
Serial.println(" a3");
// Serial.print(y0);
// Serial.println(" b0");
Serial.print(z3);
Serial.println(" c3");
helle(2);
qmc4.read(&x4, &y4, &z4);
Serial.print(x4);
Serial.println(" a4");
// Serial.print(y0);
// Serial.println(" b0");
Serial.print(z4);
Serial.println(" c4");
delay(1000);
}
I have 2 trouble about this code..
First,When I run this code, only tcaselect(7) show a result and others are all 0. So I change tcaselect(7)
to tcaselect(4) and then run, the tcaselect(4) change tcaselect(5) until 7 and then Finally I get full of the data.... How horrible.. When I reboot my computers power, (That mean next day or something..)
I Do the same thing for about 7 minute. I just want the data at first running So Could you solve my problem?
And second, I mention 'helle' is second tca9548 chip but when I run the code, tcaselect(7) and helle(2) value was same. Maybe it would be combined.. So When I eliminate helle then tcaselect(7) value going to normal.. What sould I do ![]()