Pleses help about arduino wire.h

I'm new to arduino. I had found an interesting project to work on with, but unfortunately I'm held up at compilation error.

Here is my code:

#include "MPU6050.h"

#include<Wire.h>

const uint8_t MPU_addr=0x68;

int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;

uint8_t minVal=265;

uint8_t maxVal=402;

double x;

double y;

double z;

void setup(){

Wire.begin();

Wire.beginTransmission(MPU_addr);

Wire.write(0x6B);

Wire.write(0);

Wire.endTransmission(true);

Serial.begin(9600);

}

void loop(){

Wire.beginTransmission(MPU_addr);

Wire.write(0x3B);

Wire.endTransmission(false);

Wire.requestFrom(MPU_addr,14,true);

AcX=Wire.read()<<8|Wire.read();

AcY=Wire.read()<<8|Wire.read();

AcZ=Wire.read()<<8|Wire.read();

uint8_t xAng = map(AcX,minVal,maxVal,-90,90);

uint8_t yAng = map(AcY,minVal,maxVal,-90,90);

uint8_t zAng = map(AcZ,minVal,maxVal,-90,90);

x= RAD_TO_DEG * (atan2(-yAng, -zAng)+PI);

y= RAD_TO_DEG * (atan2(-xAng, -zAng)+PI);

z= RAD_TO_DEG * (atan2(-yAng, -xAng)+PI);

Serial.print("AngleX= ");

Serial.println(x);

Serial.print("AngleY= ");

Serial.println(y);

Serial.print("AngleZ= ");

Serial.println(z);

Serial.println("-----------------------------------------");

delay(400);

}

here is the error log

In file included from c:\Users\cmt33\Documents\Arduino\libraries\MPU6050\src/I2Cdev.h:88,
from c:\Users\cmt33\Documents\Arduino\libraries\MPU6050\src/MPU6050.h:40,
from C:\Users\cmt33\Documents\Arduino\WIFI\WIFI.ino:1:
C:\Users\cmt33\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.7\libraries\Wire\src/Wire.h: In function 'void loop()':
C:\Users\cmt33\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.7\libraries\Wire\src/Wire.h:126:13: note: candidate 1: 'uint8_t TwoWire::requestFrom(int, int, int)'
uint8_t requestFrom(int address, int size, int sendStop);
^~~~~~~~~~~
C:\Users\cmt33\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.7\libraries\Wire\src/Wire.h:122:12: note: candidate 2: 'size_t TwoWire::requestFrom(uint8_t, size_t, bool)'
size_t requestFrom(uint8_t address, size_t len, bool stopBit);
^~~~~~~~~~~
C:\Users\cmt33\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.7\libraries\Wire\src/Wire.h:126:13: note: candidate 1: 'uint8_t TwoWire::requestFrom(int, int, int)'
uint8_t requestFrom(int address, int size, int sendStop);
^~~~~~~~~~~
C:\Users\cmt33\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.7\libraries\Wire\src/Wire.h:120:13: note: candidate 2: 'uint8_t TwoWire::requestFrom(uint16_t, uint8_t, bool)'
uint8_t requestFrom(uint16_t address, uint8_t size, bool sendStop);
^~~~~~~~~~~
C:\Users\cmt33\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.7\libraries\Wire\src/Wire.h:126:13: note: candidate 1: 'uint8_t TwoWire::requestFrom(int, int, int)'
uint8_t requestFrom(int address, int size, int sendStop);
^~~~~~~~~~~
C:\Users\cmt33\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.7\libraries\Wire\src/Wire.h:119:12: note: candidate 2: 'size_t TwoWire::requestFrom(uint16_t, size_t, bool)'
size_t requestFrom(uint16_t address, size_t size, bool sendStop);
^~~~~~~~~~~
C:\Users\cmt33\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.7\libraries\Wire\src/Wire.h:126:13: note: candidate 1: 'uint8_t TwoWire::requestFrom(int, int, int)'
uint8_t requestFrom(int address, int size, int sendStop);
^~~~~~~~~~~
C:\Users\cmt33\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.7\libraries\Wire\src/Wire.h:122:12: note: candidate 2: 'size_t TwoWire::requestFrom(uint8_t, size_t, bool)'
size_t requestFrom(uint8_t address, size_t len, bool stopBit);
^~~~~~~~~~~

Welcome to the forum

Your topic was MOVED to its current forum category which is more appropriate than the original as it has nothing to do with Installation and Troubleshooting of the IDE

Do only answer one thing per posting?

best regards Stefan

the posted code compiles without any errors for me with the IDE configured for an Uno

The logfile talks about ESP32

what exact type of microcontroller are you using?
did you install the board-package for this type of microcontroller?

best regards Stefan

i am using wemos D1 R32
board-package is ESP32 2.0.7

Do you answer only one question per Posting?

best regards Stefan

A couple of problems. First, these numbers are too large for an 8-bit unsigned integer:


uint8_t minVal = 265;

uint8_t maxVal = 402;

Second, the line the compiler does not like, is caused by the arguments for the function call not fitting the exact argument types for any of the overloads of the function. Your arguments are (uint8_t, int, bool), cast the 2nd argument to (size_t), or the 1st and 3rd to (int), and the code will compile.

  Wire.requestFrom(MPU_addr, 14, true);

If you have the compiler set to show all warnings, you will get warning messages on an UNO. The ESP32 boards package is not as lenient with converting errors to warnings in the compiler options, so will show an error.

guess i copied the wrong file because i get an warning for above, as well as many others

the following compiled for both UNO and esp32
also corrected warnings about "#endif;" in MPU6050.cpp

#include "MPU6050.h"
#include<Wire.h>
uint8_t MPU_addr=0x68;
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
uint16_t minVal=265;
uint16_t maxVal=402;
double x;
double y;
double z;

void setup (){
    Wire.begin ();
    Wire.beginTransmission (MPU_addr);
    Wire.write (0x6B);
    Wire.write (0);
    Wire.endTransmission (true);
    Serial.begin (9600);
}

void loop (){
    Wire.beginTransmission (MPU_addr);
    Wire.write (0x3B);
    Wire.endTransmission (false);
#if 0
    Wire.requestFrom (MPU_addr, (byte)14, (bool)true);
#else
    Wire.requestFrom (MPU_addr, (byte)14);
#endif

    AcX=Wire.read ()<<8|Wire.read ();
    AcY=Wire.read ()<<8|Wire.read ();
    AcZ=Wire.read ()<<8|Wire.read ();
    uint8_t xAng = map (AcX,minVal,maxVal,-90,90);
    uint8_t yAng = map (AcY,minVal,maxVal,-90,90);
    uint8_t zAng = map (AcZ,minVal,maxVal,-90,90);
    x= RAD_TO_DEG * (atan2 (-yAng, -zAng)+PI);
    y= RAD_TO_DEG * (atan2 (-xAng, -zAng)+PI);
    z= RAD_TO_DEG * (atan2 (-yAng, -xAng)+PI);
    Serial.print ("AngleX= ");
    Serial.println (x);
    Serial.print ("AngleY= ");
    Serial.println (y);
    Serial.print ("AngleZ= ");
    Serial.println (z);
    Serial.println ("-----------------------------------------");
    delay (400);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.