0

I'm trying to add I2C sensors to my esp cam but it doesn't work in either way. I followed some tutorials about it and have working code but scanning the bus shows no devices. Here is the sketch:

#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
}

I tried both Wire and Wire1 objects but the effect is the same:

Scanning... No I2C devices found

I also tied a couple of different ports with the same effect.

So my question is what is wrong here or what I possibly forgot if any. I've read that ESP32-CAM have 2 I2C buses from which second should free to use. I ave BME280 wired up so it should be found when the bus is there but it's not found when comment out corresponding piece of setup function.

5
  • Have you made sure that you have a common ground wire between the 2 systems ? Commented May 5, 2021 at 0:40
  • Also, does that board need a pull up resistor or have it in-built in the board ? Commented May 5, 2021 at 0:51
  • Yes,I'm sure about wiring, everything is connected straight to the board so there is a common ground there. Also the board sports the MB programmer so no need for resistor. (what is that for actually ?) Commented May 5, 2021 at 10:48
  • Have you tried to update and upgrade your raspberry? Commented Sep 19, 2021 at 12:30
  • Raspy has nothing to do here, I'm no even using it in this case Commented Oct 26, 2021 at 15:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.