Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
starrobin34 opened this issue Oct 31, 2024 · 1 comment
Open

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

starrobin34 opened this issue Oct 31, 2024 · 1 comment

Comments

@starrobin34
Copy link

starrobin34 commented Oct 31, 2024

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 <Arduino.h>
#include <Wire.h>
#include <SPI.h>
#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
Copy link
Owner

abish7643 commented Oct 31, 2024

@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) 
{
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants