You can simplify your code to test the I2C connection with just the external IMU first. This can be the test code:
Code:
#include "ICM_20948.h"#include <Wire.h>#define SERIAL_PORT Serial#define PIN_QWIIC_SCL 8#define PIN_QWIIC_SDA 9TwoWire qwiic(PIN_QWIIC_SDA, PIN_QWIIC_SCL);#define WIRE_PORT qwiic#define AD0_VAL 0 // Change to 1 if ADR jumper is closedICM_20948_I2C myICM; // I2C objectvoid setup() { // Start serial communication SERIAL_PORT.begin(115200); while (!SERIAL_PORT); // Initialize I2C communication WIRE_PORT.begin(); WIRE_PORT.setClock(400000); // Power up the IMU (if necessary, might not be needed for external IMU) pinMode(PIN_IMU_POWER, OUTPUT); digitalWrite(PIN_IMU_POWER, HIGH); delay(100); // Initialize the IMU bool initialized = false; while (!initialized) { myICM.begin(WIRE_PORT, AD0_VAL); SERIAL_PORT.print("Initialization of the external (I2C) sensor returned: "); SERIAL_PORT.println(myICM.statusString()); if (myICM.status != ICM_20948_Stat_Ok) { SERIAL_PORT.println("Trying again..."); delay(500); } else { initialized = true; SERIAL_PORT.println("External IMU initialized successfully."); } }}void loop() { // Add code to read sensor data if initialization is successful}
Statistics: Posted by aliarifat794 — Tue May 21, 2024 11:16 am