# Error porting MPU6050 library

**URL:** <https://forum.amebaiot.com/t/error-porting-mpu6050-library/1016>\
**Category:** Peripherals\
**Created:** [January 3, 2022, 7:40am UTC](https://forum.amebaiot.com/t/error-porting-mpu6050-library/1016 "2022-01-03T07:40:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![john7](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@john7](https://forum.amebaiot.com/u/john7)\
**Post date:** [January 3, 2022, 7:40am UTC](https://forum.amebaiot.com/t/error-porting-mpu6050-library/1016/1 "2022-01-03T07:40:02Z")

</div>

The library itself compiled good. But when I try to use it

```auto
MPU6050 mpu;

void MPU6050_Calibrate(uint8_t iterations)
{
    mpu.setXAccelOffset(0);
    mpu.setYAccelOffset(0);
    mpu.setZAccelOffset(0);
    mpu.setXGyroOffset(0);
    mpu.setYGyroOffset(0);
    mpu.setZGyroOffset(0);
    
    mpu.CalibrateAccel(6);
    mpu.CalibrateGyro(6); 
}

```

I get the error

> In file included from G:\Sloeber\arduinoPlugin\packages\realtek\hardware\AmebaD\3.1.0\system/component/common/api/platform/platform\_stdlib\_rtl8721d.h:23:0,  
> from G:\Sloeber\arduinoPlugin\packages\realtek\hardware\AmebaD\3.1.0\system/component/common/api/platform/platform\_stdlib.h:39,  
> from G:\Sloeber\arduinoPlugin\packages\realtek\hardware\AmebaD\3.1.0\system/component/common/api/network/include/lwipopts.h:13,  
> from G:\Sloeber\arduinoPlugin\packages\realtek\hardware\AmebaD\3.1.0\system/component/common/network/lwip/lwip\_v2.0.2/src/include/lwip/opt.h:51,  
> from G:\Sloeber\arduinoPlugin\packages\realtek\hardware\AmebaD\3.1.0\system/component/common/network/lwip/lwip\_v2.0.2/src/include/lwip/debug.h:41,  
> from ..\sensors\mpu6050.cpp:5:  
> g:\sloeber\arduinoplugin\packages\realtek\tools\ameba\_d\_asdk\_toolchain\1.0.1\arm-none-eabi\include\ctype.h:14:5: error: expected unqualified-id before ‘int’  
> int \_EXFUN(isalpha, (int \_\_c));  
> ^  
> g:\sloeber\arduinoplugin\packages\realtek\tools\ameba\_d\_asdk\_toolchain\1.0.1\arm-none-eabi\include\ctype.h:14:5: error: expected ‘)’ before ‘int’  
> g:\sloeber\arduinoplugin\packages\realtek\tools\ameba\_d\_asdk\_toolchain\1.0.1\arm-none-eabi\include\ctype.h:14:5: error: expected ‘)’ before ‘int’  
> g:\sloeber\arduinoplugin\packages\realtek\tools\ameba\_d\_asdk\_toolchain\1.0.1\arm-none-eabi\include\ctype.h:14:5: error: expected ‘)’ before ‘int’  
> int \_EXFUN(isdigit, (int \_\_c));

What can cause the problem?

---

<div class="post-metadata">

**Author:** ![wyy](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wyy](https://forum.amebaiot.com/u/wyy)\
**Post date:** [January 3, 2022, 9:01am UTC](https://forum.amebaiot.com/t/error-porting-mpu6050-library/1016/2 "2022-01-03T09:01:00Z")

</div>

Hi @john7

it looks like a conflict between the mpu6050 library and existing an #define in the RTL8722DM core, probably cause by `_EXFUN` or `isdigit`. I would recommend going through the mpu6050 library, checking to see if `int _EXFUN(isdigit, (int __c));` is used in any critical code sections, and trying to either comment out or modifying the line.

---

<div class="post-metadata">

**Author:** ![john7](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@john7](https://forum.amebaiot.com/u/john7)\
**Post date:** [January 3, 2022, 9:42am UTC](https://forum.amebaiot.com/t/error-porting-mpu6050-library/1016/3 "2022-01-03T09:42:48Z")

</div>

Well…I commented out all lines in mcp6050.cpp and started to include line by line.  
The error appears at #include “I2Cdev.h”

```auto
#ifndef _I2CDEV_H_
#define _I2CDEV_H_

// -----------------------------------------------------------------------------
// I2C interface implementation setting
// -----------------------------------------------------------------------------
#ifndef I2CDEV_IMPLEMENTATION
#define I2CDEV_IMPLEMENTATION I2CDEV_ARDUINO_WIRE
//#define I2CDEV_IMPLEMENTATION I2CDEV_TEENSY_3X_WIRE
//#define I2CDEV_IMPLEMENTATION I2CDEV_BUILTIN_SBWIRE
//#define I2CDEV_IMPLEMENTATION I2CDEV_BUILTIN_FASTWIRE
#endif // I2CDEV_IMPLEMENTATION

// comment this out if you are using a non-optimal IDE/implementation setting
// but want the compiler to shut up about it
#define I2CDEV_IMPLEMENTATION_WARNINGS

// -----------------------------------------------------------------------------
// I2C interface implementation options
// -----------------------------------------------------------------------------
#define I2CDEV_ARDUINO_WIRE 1 // Wire object from Arduino
#define I2CDEV_BUILTIN_NBWIRE 2 // Tweaked Wire object from Gene Knight's NBWire project
                                      // ^^^ NBWire implementation is still buggy w/some interrupts!
#define I2CDEV_BUILTIN_FASTWIRE 3 // FastWire object from Francesco Ferrara's project
#define I2CDEV_I2CMASTER_LIBRARY 4 // I2C object from DSSCircuits I2C-Master Library at https://github.com/DSSCircuits/I2C-Master-Library
#define I2CDEV_BUILTIN_SBWIRE 5 // I2C object from Shuning (Steve) Bian's SBWire Library at https://github.com/freespace/SBWire 
#define I2CDEV_TEENSY_3X_WIRE 6 // Teensy 3.x support using i2c_t3 library

// -----------------------------------------------------------------------------
// Arduino-style "Serial.print" debug constant (uncomment to enable)
// -----------------------------------------------------------------------------
//#define I2CDEV_SERIAL_DEBUG

#ifdef ARDUINO
    #if ARDUINO < 100
        #include "WProgram.h"
    #else
        #include "Arduino.h"
    #endif
    #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
        #include <Wire.h>
    #endif
    #if I2CDEV_IMPLEMENTATION == I2CDEV_TEENSY_3X_WIRE
        #include <i2c_t3.h>
    #endif
    #if I2CDEV_IMPLEMENTATION == I2CDEV_I2CMASTER_LIBRARY
        #include <I2C.h>
    #endif
    #if I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_SBWIRE
        #include "SBWire.h"
    #endif
#endif

#ifdef SPARK
    #include <spark_wiring_i2c.h>
    #define ARDUINO 101
#endif

// 1000ms default read timeout (modify with "I2Cdev::readTimeout = [ms];")
#define I2CDEV_DEFAULT_READ_TIMEOUT 1000

class I2Cdev {
    public:
        I2Cdev();

        static int8_t readBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
        static int8_t readBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);
        static int8_t readBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
        static int8_t readBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);
        static int8_t readByte(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
        static int8_t readWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);
        static int8_t readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
        static int8_t readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);

        static bool writeBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t data);
        static bool writeBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data);
        static bool writeBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data);
        static bool writeBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data);
        static bool writeByte(uint8_t devAddr, uint8_t regAddr, uint8_t data);
        static bool writeWord(uint8_t devAddr, uint8_t regAddr, uint16_t data);
        static bool writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data);
        static bool writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data);

        static uint16_t readTimeout;
};
#endif /* _I2CDEV_H_ */

```

---

<div class="post-metadata">

**Author:** ![john7](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@john7](https://forum.amebaiot.com/u/john7)\
**Post date:** [January 4, 2022, 6:40am UTC](https://forum.amebaiot.com/t/error-porting-mpu6050-library/1016/4 "2022-01-04T06:40:42Z")

</div>

Do we have a MPU6050 library ported to Ameba?

---

<div class="post-metadata">

**Author:** ![wyy](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wyy](https://forum.amebaiot.com/u/wyy)\
**Post date:** [January 4, 2022, 9:17am UTC](https://forum.amebaiot.com/t/error-porting-mpu6050-library/1016/5 "2022-01-04T09:17:53Z")

</div>

There is no existing port for the MPU6050. It should be relatively straightforward to do if it is just using I2C or SPI.
