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.
53 lines
1.4 KiB
53 lines
1.4 KiB
5 years ago
|
#include <ArduinoJson.h>
|
||
|
#include <Adafruit_MPU6050.h>
|
||
|
#include <Adafruit_Sensor.h>
|
||
|
#include <Wire.h>
|
||
|
|
||
|
Adafruit_MPU6050 mpu;
|
||
|
|
||
|
void setup(void) {
|
||
|
Serial.begin(115200);
|
||
|
while (!Serial)
|
||
|
delay(10); // pause Zero, Leonardo, etc until serial console opens
|
||
|
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
|
||
|
mpu.setGyroRange(MPU6050_RANGE_500_DEG);
|
||
|
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
|
||
|
delay(100);
|
||
|
}
|
||
|
|
||
|
void loop() {
|
||
|
|
||
|
/* Take a new reading */
|
||
|
mpu.read();
|
||
|
|
||
|
/* Get new sensor events with the readings */
|
||
|
sensors_event_t accel_event, gyro_event, temp;
|
||
|
mpu.getEvent(&accel_event, &gyro_event, &temp);
|
||
|
|
||
|
/*Create new json object from values x,y,z respectively*/
|
||
|
|
||
|
DynamicJsonBuffer jsonBuffer; /*or StaticJsonBuffer,200> jsonBuffer;*/
|
||
|
JsonObject& root=jsonBuffer.createObject();
|
||
|
|
||
|
|
||
|
/*Json object now gets input values from acceleration vectors*/
|
||
|
|
||
|
JsonObject& accel_data=root.createNestedObject("accel_data");
|
||
|
accel_data["x"]=accel_event.acceleration.x;
|
||
|
accel_data["y"]=accel_event.acceleration.y;
|
||
|
accel_data["z"]=accel_event.acceleration.z;
|
||
|
|
||
|
|
||
|
/*Json object now gets input values from gyroscope vectors*/
|
||
|
|
||
|
JsonObject& gyro_data=root.createNestedObject("gyro_data");
|
||
|
gyro_data["x"]=gyro_event.acceleration.x;
|
||
|
gyro_data["y"]=gyro_event.acceleration.y;
|
||
|
gyro_data["z"]=gyro_event.acceleration.z;
|
||
|
|
||
|
/* Print out the values into JSON format*/
|
||
|
root.printTo(Serial);
|
||
|
Serial.println("");
|
||
|
delay(1000);
|
||
|
}
|