ESP32-CAM 和 I2C 总线连接问题

物联网 阿杜伊诺 ESP32
2021-06-14 17:15:54

我正在尝试将 I2C 传感器添加到我的 esp 摄像头,但它无法以任何方式工作。我遵循了一些关于它的教程并有工作代码,但扫描总线显示没有设备。这是草图:

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define I2C_SDA 2
#define I2C_SCL 14

//Adafruit_BME280 bme;

void setup() {
  Serial.begin(115200);
  Serial.println("Setting up I2C bus");
  Wire1.begin(I2C_SDA, I2C_SCL, 100000);
  delay(100);
//  bool status1 = bme.begin(0x76, &Wire1);  
//  if (!status1) {
//    Serial.println("Could not find a valid BME280 sensor, check wiring!");
//  } else {
//    Serial.println("bus created.");
//  }
}

void loop() {
  byte error, address;
  int nDevices;
 
  Serial.println("Scanning...");
 
  nDevices = 0;
  for(address = 1; address < 127; address++ ) {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire1.beginTransmission(address);
    error = Wire1.endTransmission();
 
    if (error == 0) {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
        
      Serial.print(address,HEX);
      Serial.println("  !");
 
      nDevices++;
    } else if (error==4) {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");
 
  delay(5000);           // wait 5 seconds for next scan
}

我尝试了 Wire 和 Wire1 对象,但效果是一样的:

正在扫描...未找到 I2C 设备

我还绑定了几个具有相同效果的不同端口。

所以我的问题是这里出了什么问题,或者我可能忘记了什么。我读过 ESP32-CAM 有 2 个 I2C 总线,其中第二个可以免费使用。我把BME280连线了,所以当总线在那里时应该可以找到它,但是在注释掉相应的设置功能时却没有找到。

0个回答
没有发现任何回复~