ESP32 MPU9250 Error ‘Serial’ Was Not Declared

Posted on

Permasalahan

Library MPU9250 dari SparkFun adalah sebuah library yang dirancang untuk memudahkan pengguna dalam mengakses dan menggunakan sensor MPU9250. Sensor MPU9250 adalah sebuah sensor inersial yang menggabungkan accelerometer, gyroscope, dan magnetometer dalam satu paket. Namun, saat digunakan pada ESP32, MPU9250 ini muncul Error seperti berikut:

/home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp: In member function ‘void MPU9250::magCalMPU9250(float, float)’:
/home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp:634:3: error: ‘Serial’ was not declared in this scope
Serial.println(F(“Mag Calibration: Wave device in a figure 8 until done!”));
^~
/home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp:634:3: note: suggested alternative: ‘Stream’
Serial.println(F(“Mag Calibration: Wave device in a figure 8 until done!”));
^~
Stream
/home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp: In member function ‘uint8_t MPU9250::writeByteSPI(uint8_t, uint8_t)’:
/home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp:730:55: error: ‘MSBFIRST’ was not declared in this scope
_spi->beginTransaction(SPISettings(_interfaceSpeed, MSBFIRST, SPI_MODE));
^~ /home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp:730:55: note: suggested alternative: ‘SPI_MSBFIRST’ _spi->beginTransaction(SPISettings(_interfaceSpeed, MSBFIRST, SPI_MODE)); ^~
SPI_MSBFIRST
/home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp: In member function ‘uint8_t MPU9250::readMagByteSPI(uint8_t)’:
/home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp:797:5: error: ‘Serial’ was not declared in this scope
Serial.println(F(“Timed out”));
^~
/home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp:797:5: note: suggested alternative: ‘Stream’
Serial.println(F(“Timed out”));
^~
Stream
/home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp: In member function ‘uint8_t MPU9250::writeMagByteSPI(uint8_t, uint8_t)’:
/home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp:823:5: error: ‘Serial’ was not declared in this scope
Serial.println(F(“Timed out”));
^~
/home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp:823:5: note: suggested alternative: ‘Stream’
Serial.println(F(“Timed out”));
^~
Stream
/home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp: In member function ‘uint8_t MPU9250::readBytesSPI(uint8_t, uint8_t, uint8_t*)’:
/home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp:891:53: error: ‘MSBFIRST’ was not declared in this scope
_spi->beginTransaction(SPISettings(SPI_DATA_RATE, MSBFIRST, SPI_MODE));
^~ /home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp:891:53: note: suggested alternative: ‘SPI_MSBFIRST’ _spi->beginTransaction(SPISettings(SPI_DATA_RATE, MSBFIRST, SPI_MODE)); ^~
SPI_MSBFIRST
/home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp: In member function ‘bool MPU9250::magInit()’:
/home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp:998:3: error: ‘Serial’ was not declared in this scope
Serial.print(“MPU9250::magInit to return “);
^~
/home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp:998:3: note: suggested alternative: ‘Stream’
Serial.print(“MPU9250::magInit to return “);
^~
Stream
/home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp: In member function ‘void MPU9250::kickHardware()’:
/home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp:1007:53: error: ‘MSBFIRST’ was not declared in this scope
_spi->beginTransaction(SPISettings(SPI_DATA_RATE, MSBFIRST, SPI_MODE));
^~ /home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp:1007:53: note: suggested alternative: ‘SPI_MSBFIRST’ _spi->beginTransaction(SPISettings(SPI_DATA_RATE, MSBFIRST, SPI_MODE)); ^~
SPI_MSBFIRST
/home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp: In member function ‘uint8_t MPU9250::ak8963WhoAmI_SPI()’:
/home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp:1028:3: error: ‘Serial’ was not declared in this scope
Serial.print(“Old slave address: 0x”);
^~
/home/neon/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/MPU9250.cpp:1028:3: note: suggested alternative: ‘Stream’
Serial.print(“Old slave address: 0x”);
^~
Stream

Baca juga:

Cara Perbaiki

Untuk perbaiki ini sangat sederhana. Ikuti cara berikut:

  • Buka file MPU9250.h
    Saat ini saya menggunakan linux dan library ini ada di alamat :
    /home/user/Arduino/libraries/SparkFun_MPU-9250_9_DOF_IMU_Breakout/src/
  • Tambahkan #include <Arduino.h>
    Tambahkan #include didalam file MPU9250.h, sehingga akan seperti ini:
ESP32 MPU9250 Error 'Serial' was not declared

  • Save
    Sekarang, silahkan simpan file tersebut
  • Done
    Sekarang lakukan Compile atau Verify ulang kode programnya.

Sampai disini permasalahan ESP32 MPU9250 Error telah selesai diperbaiki. Semoga bermanfaat.