From fa212c80e603481375375de8641f071f8afc5d0b Mon Sep 17 00:00:00 2001 From: John Poole Date: Fri, 17 Apr 2026 12:30:56 -0700 Subject: [PATCH] Wire vs. Wire1, still needs to be sorted out. ChatGPT has some tests to clarify which I will try after this commit. Magnetometer is on Wire and RTC is on Wire1, this apparently conflicts with the documentation. Getting values, though when I rotated both standing up and sideways, I did not see values ranging from 0-360. --- exercises/22_compass/README.md | 2 +- exercises/22_compass/src/main.cpp | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/exercises/22_compass/README.md b/exercises/22_compass/README.md index 4ab1bdb..634f9e0 100644 --- a/exercises/22_compass/README.md +++ b/exercises/22_compass/README.md @@ -205,7 +205,7 @@ Suggested workflow: ## Bottom Line -The examples are enough to establish that this sensor is suitable for a live heading and magnetic field display exercise. The only caution is that the example labeled "calibration" is session-local unless we explicitly persist the offsets. The first useful deliverable for this exercise should therefore be a per-unit magnetometer assay plus a serial real-time monitor, followed by persistent calibration storage and then an OLED compass view. +The examples are enough to establish that this sensor is suitable for a live heading and magnetic field display exercise. The only caution is that the example labeled "calibration" is session-local unless we explicitly save in non-volatile memory the offsets. The first useful deliverable for this exercise should therefore be a per-unit magnetometer assay plus a serial real-time monitor, followed by persistent calibration storage and then an OLED compass view. ## Local Helper Scripts diff --git a/exercises/22_compass/src/main.cpp b/exercises/22_compass/src/main.cpp index e694f0b..952c849 100644 --- a/exercises/22_compass/src/main.cpp +++ b/exercises/22_compass/src/main.cpp @@ -398,7 +398,7 @@ void startWebServer() { Serial.println("wifi_ap=failed"); return; } - + Serial.println("wifi_ap=started"); g_server.on("/", HTTP_GET, handleWebIndex); g_server.on("/files", HTTP_GET, handleWebFiles); g_server.on("/download", HTTP_GET, handleWebDownload); @@ -415,17 +415,24 @@ bool probeI2cAddr(TwoWire& wire, uint8_t addr) { } bool detectMagnetometer() { + Serial.printf("Detecting magnetometer, kMagCandidateCount: %u\n", kMagCandidateCount); for (uint8_t i = 0; i < kMagCandidateCount; ++i) { const uint8_t addr = kMagCandidates[i]; - if (!probeI2cAddr(Wire1, addr)) { + Serial.printf(" candidate[%u] = 0x%02X\n", i, kMagCandidates[i]); + // + if (!probeI2cAddr(Wire, addr)) { continue; } + Serial.printf("Found device at 0x%02X, probing for magnetometer...\n", addr); if (addr == 0x3C || addr == 0x3D) { - Wire1.beginTransmission(addr); - Wire1.write((uint8_t)0x00); - if (Wire1.endTransmission(false) == 0 && Wire1.requestFrom((int)addr, 1) == 1) { - const uint8_t marker = Wire1.read(); + //Wire1.beginTransmission(addr); + //Wire1.write((uint8_t)0x00); + //if (Wire1.endTransmission(false) == 0 && Wire1.requestFrom((int)addr, 1) == 1) { + Wire.beginTransmission(addr); + Wire.write((uint8_t)0x00); + if (Wire.endTransmission(false) == 0 && Wire.requestFrom((int)addr, 1) == 1) { + const uint8_t marker = Wire.read(); // was Wire1.read() in original code, but that seems wrong since Wire1 is a different bus if (marker != 0x80) { continue; } @@ -452,7 +459,7 @@ bool initMagnetometer() { return false; } - if (!g_qmc.begin(Wire1, g_magAddress, tbeam_supreme::i2cSda(), tbeam_supreme::i2cScl())) { + if (!g_qmc.begin(Wire, g_magAddress, tbeam_supreme::i2cSda(), tbeam_supreme::i2cScl())) { return false; } @@ -683,7 +690,7 @@ void appSetup() { Serial.println("sd_mount=ok"); g_sd.printCardInfo(); } - + // Next is the failure point g_magReady = initMagnetometer(); if (!g_magReady) { Serial.println("magnetometer_init=failed");