Dannihercleston / Monitoramento-de-Deslizamento-de-Encostas-usando-Microcontrolador-MPU6050-MQTT-e-Grafana.

2 stars 0 forks source link

Tarefa para Dann: Programar o ESP32 para adquirir dados do sensor MPU6050. #17

Closed Dannihercleston closed 3 months ago

Dannihercleston commented 3 months ago

Adafruit_MPU6050 mpu; float accelerometerX, accelerometerY, accelerometerZ; float gyroX, gyroY, gyroZ; float temperature;

void setup() { Serial.begin(115200); Wire.begin(); if (!mpu.begin()) { Serial.println("Falha ao iniciar o sensor MPU6050"); while (1); }

unsigned long currentMillis = millis(); // Verificar se é hora de enviar os dados if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis;

// Ler os valores do sensor MPU6050
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);

accelerometerX = a.acceleration.x;
accelerometerY = a.acceleration.y;
accelerometerZ = a.acceleration.z;

gyroX = g.gyro.x;
gyroY = g.gyro.y;
gyroZ = g.gyro.z;

temperature = temp.temperature;