You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

70 lines
2.3 KiB

#include "MPU9250.h"
#include "MPU9250_asukiaaa.h"
#include "ArduinoJson.h"
// an MPU9250 object with the MPU-9250 sensor on I2C bus 0 with address 0x68
MPU9250 IMU(Wire,0x68);
int status;
void setup() {
// serial to display data
Serial.begin(9600);
while(!Serial) {}
// start communication with IMU
status = IMU.begin();
IMU.setAccelRange(MPU9250::ACCEL_RANGE_8G);
// setting the gyroscope full scale range to +/-500 deg/s
IMU.setGyroRange(MPU9250::GYRO_RANGE_500DPS);
// setting DLPF bandwidth to 20 Hz
IMU.setDlpfBandwidth(MPU9250::DLPF_BANDWIDTH_20HZ);
// setting SRD to 19 for a 50 Hz update rate
IMU.setSrd(19);
}
void loop() {
// dilosi metablitwn typoy json gia tin apostoli dedomenwn
StaticJsonDocument<50> accelarator;
StaticJsonDocument<50> gyroscope;
StaticJsonDocument<50> magnometer;
StaticJsonDocument<200> data;
// read the sensor
IMU.readSensor();
// ta tria eisagogika mpainoun gia na diabazontai os eniaio string apo to rasbery kai na apothikeuontai sthn db
Serial.write("\"\"\"");
// anathesi timon apo ton sensora sthn metabliti typoy accelarator
accelarator["X"] = IMU.getAccelX_mss();
accelarator["Y"] = IMU.getAccelY_mss();
accelarator["Z"] = IMU.getAccelZ_mss();
// eisagogi toy accelator se ena eniaio json data pou tha perilambanei olous tous aisthitires
data["A"] = accelarator;
// anathesi timon apo ton sensora sthn metabliti typoy gyroscope
gyroscope["X"] = IMU.getGyroX_rads();
gyroscope["Y"] = IMU.getGyroY_rads();
gyroscope["Z"] = IMU.getGyroZ_rads();
// eisagogi toy gyroscope se ena eniaio json data pou tha perilambanei olous tous aisthitires
data["G"] = gyroscope;
// anathesi timon apo ton sensora sthn metabliti typoy magnometer
magnometer["X"] = IMU.getMagX_uT();
magnometer["Y"] = IMU.getMagY_uT();
magnometer["Z"] = IMU.getMagZ_uT();
// eisagogi toy magnometer se ena eniaio json data pou tha perilambanei olous tous aisthitires
data["M"] = magnometer;
// apostoli tou eniaiou json data meso bluetooth (seriakh porta)
serializeJson(data, Serial);
// kleisimo twn triwn eisagogikwn kai a;lagi grammhs
Serial.write("\"\"\"\n");
// kathysterhsh 100 msec kai katharismos mnhmhs flush prin thn epanalipsi tou loop
delay(100);
Serial.flush();
}