Create a gist now

Instantly share code, notes, and snippets.

This Arduino-sketch reads sensor data from the MPU6050 and stores it in the EEPROM.
#include <EEPROM.h>
#include <MPU6050.h>
#include <I2Cdev.h>
#include <Wire.h>
MPU6050 accelgyro;
int k = 0;
int n = 1025;
int ax, ay, az;
int gx, gy, gz;
int pushButton = 2;
int led = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// make the pushbutton's pin an input:
pinMode(pushButton, INPUT);
// make the LED an output
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
Wire.begin();
accelgyro.initialize();
}
// the loop routine runs over and over again forever:
void loop() {
//starts the data logging when button is pushed
while(n==1025){
int buttonState = digitalRead(pushButton);
Serial.println(buttonState);
if (buttonState == 1){
n = 0;
digitalWrite(led, HIGH);
Serial.println(buttonState);
}
delay(3);
}
// reads the sensor data and stores acceleration in x-direction to the EEPROM for about 10s
while(n<1024){
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
//Serial.println(ax);
k = (ax/514)+128;
Serial.println(k);
EEPROM.write(n, k);
n = n + 1;
//Serial.println(millis()/1000);
delay(10);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment