Bonsoir
J'ai pas mal cherché, et j'ai finalement un code qui marche...
// Bus 2 : l'accéléro
#define SDA2 5
#define SCL2 4
#include <Wire.h>
#include "I2Cdev.h"
#include <MPU6050.h>
RTC_DATA_ATTR int bootCount = 0;
MPU6050 accelgyro;
/*
Method to print the reason by which ESP32 has been awaken from sleep
*/
void print_wakeup_reason() {
esp_sleep_wakeup_cause_t wakeup_reason;
wakeup_reason = esp_sleep_get_wakeup_cause();
switch (wakeup_reason)
{
case 1 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
case 2 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
case 3 : Serial.println("Wakeup caused by timer"); break;
case 4 : Serial.println("Wakeup caused by touchpad"); break;
case 5 : Serial.println("Wakeup caused by ULP program"); break;
default : Serial.println("Wakeup was not caused by deep sleep"); break;
}
}
bool InitAccelero () {
Wire.begin(SDA2, SCL2);
accelgyro.initialize();
bool Success = accelgyro.testConnection(); // verify connection
if (Success) {
Serial.println("MPU6050 connection successful");
}
else Serial.println("MPU6050 connection failed");
return Success;
}
void setup() {
Serial.begin(115200);
bool AcceleroSuccess = InitAccelero ();
// instructions from : https://lukelectro.wordpress.com/2016/08/11/how-to-enable-motion-detection-interrupt-on-mpu6050/
accelgyro.resetGyroscopePath();
accelgyro.resetAccelerometerPath();
accelgyro.setInterruptDrive(0);
accelgyro.setInterruptMode(1); // 0=active-high, 1=active-low
accelgyro.setDHPFMode(MPU6050_DHPF_5);
accelgyro.setMotionDetectionThreshold(2); // Threshold in 2mg (ajouté by me)
accelgyro.setMotionDetectionDuration(100); //Duration in ms
accelgyro.setAccelerometerPowerOnDelay(1); // Set accelerometer power-on delay
accelgyro.setFreefallDetectionCounterDecrement(1); // Set Free Fall detection counter decrement
accelgyro.setMotionDetectionCounterDecrement(1); // Set Motion detection counter decrement
accelgyro.setIntMotionEnabled(true);
delay(200); //Take some time to open up the Serial Monitor
//Increment boot number and print it every reboot
++bootCount;
Serial.println("Boot number: " + String(bootCount));
delay(20);
print_wakeup_reason(); //Print the wakeup reason for ESP32
// Configure RTCIO as wakeup source
esp_sleep_enable_ext0_wakeup(GPIO_NUM_13, 0); //1 = High, 0 = Low
//Go to sleep now
Serial.println("Going to sleep now");
delay(200);
esp_deep_sleep_start();
}
void loop() { }
Les connexions :
VCC, GND, SDA sur pin 5, SCL sur pin 4 et INT sur 13.