Giter Club home page Giter Club logo

esp32cam-i2csensors's Introduction

ESP32Cam with I2C Sensor Example

Read detailed blog at how-to-use-i2c-sensor-bme280-with-esp32cam.

I2C Bus

Define SDA and SCL Pins, Pin Number 14 and 15 are selected respectively.

#define I2C_SDA 14
#define I2C_SCL 15

Create a Two Wire Instance.

TwoWire I2CSensors = TwoWire(0);

In setup(), intialize the Two Wire Instance by passing in the SDA & SCL Pins and the clock frequency.

I2CSensors.begin(I2C_SDA, I2C_SCL, 100000);

Interfacing

Expected Error (With Adafruit Library)

An expected error while using Adafruit Libraries is that "sensor_t" will be conflicting with the ESP32Cam Board since it is declared both in Adafruit Library and ESP32Cam Board Library. This happens only when you include "esp_camera.h", that is if you use camera.

In file included from src/main.cpp:4:0:
lib/Adafruit_Unified_Sensor/Adafruit_Sensor.h:155:3: error: conflicting declaration 'typedef struct sensor_t sensor_t'
 } sensor_t;
   ^
In file included from /home/abish/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp32-camera/esp_camera.h:70:0,
                 from src/main.cpp:2:
/home/abish/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/esp32-camera/sensor.h:133:3: note: previous declaration as 'typedef struct _sensor sensor_t'
 } sensor_t;
   ^
*** [.pio/build/esp32cam/src/main.cpp.o] Error 1

Error

Inorder to fix this, rename all the "sensor_t" instances to another name, for example "sensor_t1". I used Sublime Text for renaming all this at once. Also I have attached the modified libraries. Rename yourself if you want to use the latest version of the library when it releases.

esp32cam-i2csensors's People

Contributors

abish7643 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

jakubgencur

esp32cam-i2csensors's Issues

Not an issue

Hi, I´m in a learning phase so sometimes simples things appears to be impossile to me, and one of it is: is this library can be used with ADS1115?
The main goal is to connect a rain sensor on ESP32-CAM, as I can´t use analog ports when WiFi is being used this is my (maybe) only option. Is it possible? Is there any example?

Using ADXL sensor instead of BME280 Sensor

Hello '
I am student from Seoul, South Korea and ESP32 starter.
Nowadays I am really enjoying ADRUINO and got many helps from many GURU.

I am trying to connect motion sensor to esp32-cam and I found your amazing materials.
It is really helpful. Unfortunately I am using ADXL-345 so there is little difference.
Which is i am using #include <Adafruit_ADXL345_U.h> while yours is #include <Adafruit_BME280.h>.
because of this difference I can't Initalize the Sensor correctly.

question

can you tell me the way to solve this problem??

Thanks in advance

SIncerely

Using MPU6050 with Esp32 cam

Great approach. I was interested in interfacing esp32 ai thinker with MPU6050 sensor which should take a similar approach, but it can't find the mpu6050 chip. I'm adding the code I used for reference. Any help would be greatly appreciated.

// Basic demo for accelerometer readings from Adafruit MPU6050

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

#define MPU6050_I2C_SDA 13
#define MPU6050_I2C_SCL 14

TwoWire I2Cmpu = TwoWire(0);
Adafruit_MPU6050 mpu;

unsigned long delayTime;

void setup(void) {
  Serial.begin(115200);
  I2Cmpu.begin(MPU6050_I2C_SDA, MPU6050_I2C_SCL, 100000);

  bool status;
  status = mpu.begin(0x68, &I2Cmpu);
  
  while (!Serial)
    delay(10); // will pause Zero, Leonardo, etc until serial console opens

  Serial.println("Adafruit MPU6050 test!");

  // Try to initialize!
  if (!status) {
    Serial.println("Failed to find MPU6050 chip");
    while (1) {
      delay(10);
    }
  }
  Serial.println("MPU6050 Found!");

  mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
  Serial.print("Accelerometer range set to: ");
  switch (mpu.getAccelerometerRange()) {
  case MPU6050_RANGE_2_G:
    Serial.println("+-2G");
    break;
  case MPU6050_RANGE_4_G:
    Serial.println("+-4G");
    break;
  case MPU6050_RANGE_8_G:
    Serial.println("+-8G");
    break;
  case MPU6050_RANGE_16_G:
    Serial.println("+-16G");
    break;
  }
  mpu.setGyroRange(MPU6050_RANGE_500_DEG);
  Serial.print("Gyro range set to: ");
  switch (mpu.getGyroRange()) {
  case MPU6050_RANGE_250_DEG:
    Serial.println("+- 250 deg/s");
    break;
  case MPU6050_RANGE_500_DEG:
    Serial.println("+- 500 deg/s");
    break;
  case MPU6050_RANGE_1000_DEG:
    Serial.println("+- 1000 deg/s");
    break;
  case MPU6050_RANGE_2000_DEG:
    Serial.println("+- 2000 deg/s");
    break;
  }

  mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
  Serial.print("Filter bandwidth set to: ");
  switch (mpu.getFilterBandwidth()) {
  case MPU6050_BAND_260_HZ:
    Serial.println("260 Hz");
    break;
  case MPU6050_BAND_184_HZ:
    Serial.println("184 Hz");
    break;
  case MPU6050_BAND_94_HZ:
    Serial.println("94 Hz");
    break;
  case MPU6050_BAND_44_HZ:
    Serial.println("44 Hz");
    break;
  case MPU6050_BAND_21_HZ:
    Serial.println("21 Hz");
    break;
  case MPU6050_BAND_10_HZ:
    Serial.println("10 Hz");
    break;
  case MPU6050_BAND_5_HZ:
    Serial.println("5 Hz");
    break;
  }

  Serial.println("");
  delay(100);
}

void loop() {

  /* Get new sensor events with the readings */
  sensors_event_t a, g, temp;
  mpu.getEvent(&a, &g, &temp);

  /* Print out the values */
  Serial.print("Acceleration X: ");
  Serial.print(a.acceleration.x);
  Serial.print(", Y: ");
  Serial.print(a.acceleration.y);
  Serial.print(", Z: ");
  Serial.print(a.acceleration.z);
  Serial.println(" m/s^2");

  Serial.print("Rotation X: ");
  Serial.print(g.gyro.x);
  Serial.print(", Y: ");
  Serial.print(g.gyro.y);
  Serial.print(", Z: ");
  Serial.print(g.gyro.z);
  Serial.println(" rad/s");

  Serial.print("Temperature: ");
  Serial.print(temp.temperature);
  Serial.println(" degC");

  Serial.println("");
  delay(500);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.