TrabalhosGratuitos.com - Trabalhos, Monografias, Artigos, Exames, Resumos de livros, Dissertações
Pesquisar

Configuração Acelerômetro no Arduíno mpu6050 contagem 0 a 10

Por:   •  30/5/2017  •  Pesquisas Acadêmicas  •  1.929 Palavras (8 Páginas)  •  330 Visualizações

Página 1 de 8

#include "I2Cdev.h"

#include "MPU6050_6Axis_MotionApps20.h"

#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE

#include "Wire.h"

#endif

MPU6050 mpu;

#define OUTPUT_READABLE_YAWPITCHROLL

#define LED_PIN 13

bool blinkState = false;

bool dmpReady = false;

uint8_t mpuIntStatus;

uint8_t devStatus;

uint16_t packetSize;

uint16_t fifoCount;

uint8_t fifoBuffer[64];

Quaternion q;

VectorInt16 aa;

VectorInt16 aaReal;

VectorInt16 aaWorld;

VectorFloat gravity;

float euler[3];

float ypr[3];

uint8_t teapotPacket[14] = { '$', 0x02, 0,0, 0,0, 0,0, 0,0, 0x00, 0x00, '\r', '\n' };

volatile bool mpuInterrupt = false;

void dmpDataReady() {

mpuInterrupt = true;

}

int nivel;

void setup() {

#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE

Wire.begin();

TWBR = 24;

#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE

Fastwire::setup(400, true);

#endif

Serial.begin(115200);

while (!Serial);

Serial.println(F("Initializing I2C devices..."));

mpu.initialize();

Serial.println(F("Testing device connections..."));

Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));

Serial.println(F("\nSend any character to begin DMP programming and demo: "));

while (Serial.available() && Serial.read());

while (!Serial.available());

while (Serial.available() && Serial.read());

Serial.println(F("Initializing DMP..."));

devStatus = mpu.dmpInitialize();

mpu.setXGyroOffset(220);

mpu.setYGyroOffset(76);

mpu.setZGyroOffset(-85);

mpu.setZAccelOffset(1788);

if (devStatus == 0) {

Serial.println(F("Enabling DMP..."));

mpu.setDMPEnabled(true);

Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)..."));

attachInterrupt(0, dmpDataReady, RISING);

mpuIntStatus = mpu.getIntStatus();

Serial.println(F("DMP ready! Waiting for first interrupt..."));

dmpReady = true;

packetSize = mpu.dmpGetFIFOPacketSize();

} else {

Serial.print(F("DMP Initialization failed (code "));

Serial.print(devStatus);

Serial.println(F(")"));

}

pinMode(LED_PIN, OUTPUT);

}

void loop() {

if (!dmpReady) return;

while (!mpuInterrupt && fifoCount < packetSize) {

}

mpuInterrupt = false;

mpuIntStatus = mpu.getIntStatus();

fifoCount = mpu.getFIFOCount();

if ((mpuIntStatus & 0x10) || fifoCount == 1024) {

mpu.resetFIFO();

Serial.println(F("FIFO overflow!"));

}

else if (mpuIntStatus & 0x02) {

while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();

mpu.getFIFOBytes(fifoBuffer, packetSize);

fifoCount -= packetSize;

#ifdef OUTPUT_READABLE_QUATERNION

mpu.dmpGetQuaternion(&q, fifoBuffer);

Serial.print("quat\t");

Serial.print(q.w);

...

Baixar como (para membros premium)  txt (6.4 Kb)   pdf (53.4 Kb)   docx (14.6 Kb)  
Continuar por mais 7 páginas »
Disponível apenas no TrabalhosGratuitos.com