Problem with Wire.h

Dj EKI
Posts: 1
Joined: Sun Jan 22, 2023 6:46 pm

Problem with Wire.h

Postby Dj EKI » Sun Jan 22, 2023 6:57 pm

I have an ESP-WROOM-32 and my programmer is ESP Prog v1.0 (CH340C).

I have a problem with Wire.h.
The ESP hangs at the line:
"Wire.requestFrom(MPU_ADDR, 14, true);"

It only hangs when "Wire.beginTransmission(MPU_ADDR);" previously exists.

What am I doing wrong?

Normally I use an MPU6050 as a library. But with "mpu.initialize();" the program hangs too.

Code: Select all

#include <Wire.h>

const uint8_t MPU_ADDR = 0x68; // I2C address of the MPU-6050
int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;

void setup() {
  byte error;
  Serial.begin(115200);
  Wire.begin(); // sda, scl
  Wire.beginTransmission(MPU_ADDR);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  error = Wire.endTransmission();
    if (error == 0){
      Serial.println("I2C device found");
    } else if(error != 2){
      Serial.println("Error");
    }
  Serial.println("Setup complete");

}

void loop() {

  Wire.beginTransmission(MPU_ADDR);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(true);
  Wire.beginTransmission(MPU_ADDR);
  Serial.println("StartRequest");
  Wire.requestFrom(MPU_ADDR, 14, true); // request a total of 14 registers
  Serial.println("ReadAcX");
  AcX = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
  Serial.println("ReadAcY");
  AcY = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  AcZ = Wire.read() << 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  Tmp = Wire.read() << 8 | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
  GyX = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
  GyY = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  GyZ = Wire.read() << 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)


  Serial.print(AcX); Serial.print(" , ");
  Serial.print(AcY); Serial.print(" , ");
  Serial.print(AcZ); Serial.print(" , ");
  Serial.print(GyX); Serial.print(" , ");
  Serial.print(GyY); Serial.print(" , ");
  Serial.print(GyZ); Serial.print("\n");

}

Fabrizio
Posts: 1
Joined: Fri Apr 12, 2024 4:42 pm

Re: Problem with Wire.h

Postby Fabrizio » Fri Apr 12, 2024 4:43 pm

Hello. Did you solve the problem? I'm having the same issue

Who is online

Users browsing this forum: No registered users and 46 guests