Can I use IMU sensor (MPU9250) with Wio Terminal?

When I attached Grove IMU sensor (MPU9250) with Wio terminal,
it shows that the errors and not compiled at all.

Example codes are starting as follows;

#include “Wire.h”

// I2Cdev and MPU9250 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include “I2Cdev.h”
#include “MPU9250.h”
#include “BMP280.h”

// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU9250 accelgyro;
I2Cdev I2C_M;

and the results are as follows;

C:\Users\user\Documents\Arduino\libraries\Grove_IMU_10DOF_v2.0-master\I2Cdev.cpp: In static member function ‘static int8_t I2Cdev::readBytes(uint8_t, uint8_t, uint8_t, uint8_t*, uint16_t)’:
C:\Users\user\Documents\Arduino\libraries\Grove_IMU_10DOF_v2.0-master\I2Cdev.cpp:276:62: error: ‘BUFFER_LENGTH’ was not declared in this scope
for (uint8_t k = 0; k < length; k += min(length, BUFFER_LENGTH)) {
^~~~~~~~~~~~~
C:\Users\user\Documents\Arduino\libraries\Grove_IMU_10DOF_v2.0-master\I2Cdev.cpp:276:62: note: suggested alternative: ‘REG_DSU_LENGTH’
for (uint8_t k = 0; k < length; k += min(length, BUFFER_LENGTH)) {
^~~~~~~~~~~~~
REG_DSU_LENGTH
C:\Users\user\Documents\Arduino\libraries\Grove_IMU_10DOF_v2.0-master\I2Cdev.cpp: In static member function ‘static int8_t I2Cdev::readWords(uint8_t, uint8_t, uint8_t, uint16_t*, uint16_t)’:
C:\Users\user\Documents\Arduino\libraries\Grove_IMU_10DOF_v2.0-master\I2Cdev.cpp:416:70: error: ‘BUFFER_LENGTH’ was not declared in this scope
for (uint8_t k = 0; k < length * 2; k += min(length * 2, BUFFER_LENGTH)) {
^~~~~~~~~~~~~
C:\Users\user\Documents\Arduino\libraries\Grove_IMU_10DOF_v2.0-master\I2Cdev.cpp:416:70: note: suggested alternative: ‘REG_DSU_LENGTH’
for (uint8_t k = 0; k < length * 2; k += min(length * 2, BUFFER_LENGTH)) {
^~~~~~~~~~~~~
REG_DSU_LENGTH

Hi @youngil_sohn, Can you share the code, I’ll try replicate the error!

also keep in mind, Wio Terminal is comes with the inbuilt LIS3DHTR based Accelerator , in case you don’t know. Wiki: https://wiki.seeedstudio.com/Wio-Terminal-Getting-Started/

^^ I already mastered the internal IMU sensors ^^
please see my video for this ^^ : https://youtu.be/XAQ2tjaLBfI

My task is to compare two IMU sensors one is internal in Wio Terminal and the other is the grove sensor (from Seeedstudio)

the codes are just the example codes like the followings;
and the only problem occurred while including “I2Cdev.h”

===============================================================

#include “Wire.h”
// I2Cdev and MPU9250 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include “I2Cdev.h”
#include “MPU9250.h”
// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU9250 accelgyro;
I2Cdev I2C_M;
uint8_t buffer_m[6];

int16_t ax, ay, az;
int16_t gx, gy, gz;
int16_t mx, my, mz;

float heading;
float tiltheading;
float Axyz[3];
float Gxyz[3];
float Mxyz[3];

void setup()
{
// join I2C bus (I2Cdev library doesn’t do this automatically)
Wire.begin();

// initialize serial communication
// (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
// it's really up to you depending on your project)

Serial.begin(38400);

// initialize device

Serial.println("Initializing I2C devices...");
accelgyro.initialize();

// verify connection
Serial.println("Testing device connections...");
Serial.println(accelgyro.testConnection() ? "MPU9250 connection successful" : "MPU9250 connection failed");
delay(1000);
Serial.println("     ");
//  Mxyz_init_calibrated ();

}

void loop()
{
getAccel_Data();
getGyro_Data();
Serial.printf("%4.2f %4.2f %4.2f %4.2f %4.2f %4.2f\n",
Axyz[0], Axyz[1], Axyz[2], Gxyz[0], Gxyz[1], Gxyz[2]);
delay(10);
}

void getAccel_Data(void)
{
accelgyro.getMotion9(&ax, &ay, &az, &gx, &gy, &gz, &mx, &my, &mz);
Axyz[0] = (double) ax / 16384;
Axyz[1] = (double) ay / 16384;
Axyz[2] = (double) az / 16384;
}
void getGyro_Data(void)
{
accelgyro.getMotion9(&ax, &ay, &az, &gx, &gy, &gz, &mx, &my, &mz);
Gxyz[0] = (double) gx * 250 / 32768;
Gxyz[1] = (double) gy * 250 / 32768;
Gxyz[2] = (double) gz * 250 / 32768;
}

It’s a bug in the Wire.h file for the WIO Terminal. The WIO Terminal uses their own Wire.h file which does NOT have BUFFER_LENGTH set.

For example the Arduino UNO version of Wire.h looks like the following:

The WIO Terminal Wire.h version in C:\Users{username}\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.7.6\libraries\Wire that installed with the Board Manager looks like this:

You could set your own #define BUFFER_LENGTH 32 in their Wire.h and it does compile… though it is a hack to do so as we don’t know if that is the true buffer length (it is probably larger).

I would post this as a bug on Github (or here).

Thanks. I will try. I hope to succeed. ^^

Thanks it works ^^

1 Like

@ansonhe97 Please refer this issue to the appropriate software maintainer.

Hi @youngil_sohn @Dennis_Mabrey

Thanks to pointing out. We have also updated our library :smiley:

1 Like