82 lines
1.5 KiB
Arduino
Raw Normal View History

2021-01-29 12:31:58 +01:00
//
// FILE: test1.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: minimal demo
// DATE: 2020-07-01
#include "GY521.h"
GY521 sensor(0x69);
uint32_t counter = 0;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Wire.begin();
delay(100);
while (sensor.wakeup() == false)
{
Serial.print(millis());
Serial.println("\tCould not connect to GY521");
delay(1000);
}
sensor.setAccelSensitivity(0); // 2g
sensor.setGyroSensitivity(0); // 250 degrees/s
sensor.setThrottle();
Serial.println("start...");
// set callibration values from calibration sketch.
sensor.axe = 0;
sensor.aye = 0;
sensor.aze = 0;
sensor.gxe = 0;
sensor.gye = 0;
sensor.gze = 0;
}
void loop()
{
sensor.read();
int ax = sensor.getAccelX();
int ay = sensor.getAccelY();
int az = sensor.getAccelZ();
int gx = sensor.getGyroX();
int gy = sensor.getGyroY();
int gz = sensor.getGyroZ();
int t = sensor.getTemperature();
if (counter % 10 == 0)
{
Serial.println("\n\tACCELEROMETER\t\tGYROSCOPE\t\tTEMPERATURE");
Serial.println("\tax\tay\taz\tgx\tgy\tgz\tT");
}
Serial.print(counter);
Serial.print('\t');
Serial.print(ax);
Serial.print('\t');
Serial.print(ay);
Serial.print('\t');
Serial.print(az);
Serial.print('\t');
Serial.print(gx);
Serial.print('\t');
Serial.print(gy);
Serial.print('\t');
Serial.print(gz);
Serial.print('\t');
Serial.print(t);
Serial.println();
counter++;
delay(1000);
}
// -- END OF FILE --