abish7643 / ESP32Cam-I2CSensors

Use TwoWire to Create Custom I2C Bus on an AI-Thinker ESP32Cam & Interface I2C Sensors (BME280).
21 stars 1 forks source link

Can't get any I2C device working on the CAM module #4

Open starrobin34 opened 3 weeks ago

starrobin34 commented 3 weeks ago

Hey,

I tried doing the same as you. I can find the I2C address when scanning but can't get the I2C devices to initialize.

include

include

include

include "MPU9250.h"

// -----------------I2C-----------------

define I2C_SDA 14 // SDA Connected to GPIO 14

define I2C_SCL 15 // SCL Connected to GPIO 15

TwoWire WIRE = TwoWire(0);

int flashPin = 4;

MPU9250 mpu;

void setup() { Serial.begin(115200); while (!Serial) ; Serial.println("Test"); Wire.end(); WIRE.begin(I2C_SDA, I2C_SCL, 100000); // WIRE.begin(I2C_SDA, I2C_SCL, 50000); delay(2000);

    MPU9250Setting setting;
    setting.accel_fs_sel = ACCEL_FS_SEL::A16G;
    setting.gyro_fs_sel = GYRO_FS_SEL::G2000DPS;
    setting.mag_output_bits = MAG_OUTPUT_BITS::M16BITS;
    setting.fifo_sample_rate = FIFO_SAMPLE_RATE::SMPL_200HZ;
    setting.gyro_fchoice = 0x03;
    setting.gyro_dlpf_cfg = GYRO_DLPF_CFG::DLPF_41HZ;
    setting.accel_fchoice = 0x01;
    setting.accel_dlpf_cfg = ACCEL_DLPF_CFG::DLPF_45HZ;

    if (!mpu.setup(0x68, setting))
    { // change to your own address
        while (1)
        {
            Serial.println("MPU connection failed. Please check your connection with `connection_check` example.");
            delay(5000);
        }
    }

I am getting this error:

[ 2464][E][Wire.cpp:422] beginTransmission(): could not acquire lock [ 2470][E][Wire.cpp:526] write(): NULL TX buffer pointer [ 2475][E][Wire.cpp:448] endTransmission(): NULL TX buffer pointer I2C ERROR CODE : 4 [ 2482][E][Wire.cpp:481] requestFrom(): NULL buffer pointer

Help greatly appreciated!

abish7643 commented 3 weeks ago

@starrobin34

  1. This may not be required before you even initialise the bus. Wire.end();

  2. Just checked the library you were using, the mpu setup function accepts the I2C interface as the third argument. So, you should pass the TwoWire instance you created to that function.

    bool setup(const uint8_t addr, const MPU9250Setting& mpu_setting = MPU9250Setting(), WireType& w = Wire) 
    {
    ...