Mengukur Waktu Pengukuran IMU MPU6500

Mengukur Waktu Pengukuran IMU MPU6500

Pertanyaan #

Berapa waktu yang diperlukan MPU6500 untuk menghasilkan pengukuran percepatan?

Solusi #

Library IMU menggunakan https://github.com/LiquidCGS/FastIMU/blob/main/examples/Calibrated_sensor_output/Calibrated_sensor_output.ino Library yang dipakai adalah FastIMU https://github.com/LiquidCGS/FastIMU Lakukan pengukuran akselerometer 1000 kali, catat waktu total yang diperlukan.

Kode #

// mengukur waktu konversi oleh MPU6500
// pakai delay sederhana saja
// https://github.com/LiquidCGS/FastIMU/blob/main/examples/Calibrated_sensor_output/Calibrated_sensor_output.ino


#include "FastIMU.h"
#include <Wire.h>
#include <ArduinoJson.h>
#include <HTTPClient.h>
#include <WiFiMulti.h>
#include "FS.h"
#include "SD.h"
#include "SPI.h"

#define IMU_ADDRESS 0x68  //Change to the address of the IMU
// #define PERFORM_CALIBRATION //Comment to disable startup calibration
//MPU9250 IMU;  //Change to the name of any supported IMU!
MPU6500 IMU;  //Change to the name of any supported IMU!

// Currently supported IMUS: MPU9255 MPU9250 MPU6886 MPU6500 MPU6050 ICM20689 ICM20690 BMI055 BMX055 BMI160 LSM6DS3 LSM6DSL QMI8658
calData calib = { 0 };  //Calibration data
AccelData accelData;    //Sensor data
//GyroData gyroData;
//MagData magData;

#define SDA 15  // sesuaikan dengan port yang dipakai untuk SDA dan SCL
#define SCL 13
#define LED 22  // Lolin32 Lite

// SD card configuratin
#define REASSIGN_PINS
int sck = 23;
int miso = 5;
int mosi = 18;
int cs = 19;

void setup() {
  Wire.begin(SDA, SCL);
  Wire.setClock(400000);  //400khz clock
  Serial.begin(115200);
  while (!Serial) {
    ;
  }

  int err = IMU.init(calib, IMU_ADDRESS);
  if (err != 0) {
    Serial.print("Error initializing IMU: ");
    Serial.println(err);
    while (true) {
      ;
    }
  }

  if (err != 0) {
    Serial.print("Error Setting range: ");
    Serial.println(err);
    while (true) {
      ;
    }
  }
}

void loop() {
  int i;
  unsigned long begin,end;
  // iterasi 1000x, ukur berapa waktunya
  begin = millis();
  for (i = 0; i < 1000; i++) {
    IMU.update();
    IMU.getAccel(&accelData);
  }
  end = millis();
  Serial.print("time: ");  
  Serial.println(end - begin); // durasi untuk 1000x pengukuran
  delay(1000);
}

Output #

time: 267
time: 266
time: 267
time: 267
time: 267
time: 267
time: 267
time: 267
time: 267

Referensi #

comments powered by Disqus