I2C 핀은 IMU, 압력 센서 및 확장 포트에 연결됩니다.
SDA는 핀 21에, SCL 핀은 22에 있습니다. 이들은 Mercury_pins.h 파일에 정의되어 있으므로 SDA 및 SCL 이름을 사용할 수 있습니다.Wire.begin(SDA, SCL);
아래 코드는 센서 전원을 활성화하고, I2C를 시작하며, 10초마다 사용 가능한 장치를 스캔합니다.
컴파일하고 Mercury에 업로드한 후 재부팅한 후 시리얼 모니터를 연결하여 출력을 확인합니다.
Arduino IDE를 사용하고 있습니까? 당사의 온라인 프로그래머는 기본적으로 Mercury_Pins.h를 포함하므로 핀 이름이 문제 없이 작동합니다. Arduino IDE 또는 다른 프로그래머를 사용하는 경우, Mercury_Pins.h 탭 내용을 복사하여 프로그램 맨 위에 붙여넣으세요.
/* * Mercury I2C Scanner * I2C 버스를 스캔하고 연결된 모든 장치를 보고합니다. * 조립 후 센서 주소를 확인하는 데 유용합니다. */ #include "Wire.h" #include "Mercury_Pins.h" void setup() { Serial.begin(115200); delay(1000); Serial.println("Mercury I2C Scanner"); Serial.println("===================="); // 센서 레일 전원 켜기 pinMode(VACC, OUTPUT); digitalWrite(VACC, HIGH); delay(100); // 센서 안정화 허용 // Mercury 핀에서 I2C 시작 Wire.begin(SDA, SCL); Serial.println("Sensor power: ON"); Serial.println("I2C bus ready (SDA=" + String(SDA) + " SCL=" + String(SCL) + ")"); Serial.println(); } void loop() { int found = 0; Serial.println("Scanning I2C bus..."); for (int row = 0; row < 128; row += 16) { // Row label for (int col = 0; col < 16; col++) { int addr = row + col; // 예약된 주소 건너뛰기 (0x00-0x07 및 0x78-0x7F) if (addr < 0x08 || addr > 0x77) { continue; } Wire.beginTransmission(addr); int result = Wire.endTransmission(); if (result == 0) { found++; } else { } } } Serial.println(); if (found == 0) { Serial.println("No devices found. Check wiring and sensor power."); } else { Serial.println(String(found) + " device(s) found:"); // 발견된 장치를 일반 이름과 함께 나열하기 위한 두 번째 패스 for (int addr = 0x08; addr <= 0x77; addr++) { Wire.beginTransmission(addr); if (Wire.endTransmission() == 0) { Serial.printf(" 0x%02X", addr); // 일반적인 센서 식별 switch (addr) { case 0x47: Serial.print(" - BMP581 (Mercury Pressure)"); break; case 0x6B: Serial.print(" - LSM6DSO32 (Mercury IMU)"); break; case 0x77: Serial.print(" - BMP390 (Mercury Pressure)"); break; } Serial.println(); } } } Serial.println(); Serial.println("Next scan in 10 seconds..."); Serial.println("---"); delay(10000); }#pragma once /* * Mercury (ESP32-C6) 핀 정의 * 보드별 GPIO 할당 */ // ── Status LED (NeoPixel) ── #define LEDPOWER 3 // NeoPixel power (HIGH로 구동하여 활성화) #define LED 2 // NeoPixel data signal // ── I2C Bus ── #define SDA 21 // I2C data #define SCL 22 // I2C clock // ── Sensor Power ── #define VACC 20 // Sensor power rail (HIGH로 구동하여 활성화) // ── General Purpose Ports ── #define GP06 6 // GP06 port #define GP07 7 // GP07 port // ── High Current Output ── #define OUT1 5 // High current output (예: pyro / relay) // ── Battery Bar LEDs ── #define BL1 4 // Battery LED 1 (최저) #define BL2 14 // Battery LED 2 #define BL3 15 // Battery LED 3 #define BL4 18 // Battery LED 4 #define BL5 19 // Battery LED 5 (최고) // ── Indicators ── #define DISK 8 // Disk activity LED // ── Analogue / Detection ── #define BATIN 0 // Battery voltage (1:1 divider) #define USBDETECT 1 // USB power detect (HIGH = USB present) #define BUTTON 9 // BUTTON on the board, boot button but can be used