Manuel Mercury V1
Découvrez comment voler rapidement et facilement, connectez votre altimètre pour télécharger vers le site web Altimeter Cloud et accédez à toutes les fonctionnalités avancées également. Si vous êtes bloqué ou si vous débutez, c'est l'endroit où il faut être.

Exemple de code : accéléromètre et gyroscope LSM6DSO32

PDF

Cet exemple montre comment vous pouvez vous connecter à l'IMU LSM6DSO32 (Accéléromètre & Gyroscope) et lire les valeurs.
Vous devez vous assurer d'activer les capteurs en utilisant la broche VACC comme indiqué dans ce code.

Une fois programmé, appuyez sur le bouton d'alimentation pour redémarrer le Mercury, puis connectez un moniteur série.

Utiliser Arduino IDE ? Notre programmateur en ligne inclut Mercury_Pins.h par défaut afin que les noms de broches fonctionnent sans problème. Si vous utilisez Arduino IDE ou un autre programmateur, copiez le contenu de l'onglet Mercury_Pins.h et collez-le en haut de votre programme.
/*
 * Mercury LSM6DSO32 Example
 * Reads accelerometer and gyroscope data from the LSM6DSO32 IMU
 * and outputs to Serial every 500ms.
 *
 * Wiring: Connect LSM6DSO32 to the I2C port (SDA/SCL)
 * I2C address: 0x6B (SDO/SA0 HIGH on Mercury board)
 *
 * Library: Adafruit LSM6DS (auto-installed by compiler)
 */

#include "Wire.h"
#include "Adafruit_LSM6DS.h"
#include "Adafruit_LSM6DSO32.h"
#include "Mercury_Pins.h"

Adafruit_LSM6DSO32 imu;

void setup() {
    Serial.begin(115200);
    delay(1000);

    Serial.println("LSM6DSO32 IMU Example");
    Serial.println("=====================");

    // Power on the sensor rail
    pinMode(VACC, OUTPUT);
    digitalWrite(VACC, HIGH);
    delay(100);

    // Start I2C on Mercury pins
    Wire.begin(SDA, SCL);

    // Initialise the IMU at address 0x6B
    if (!imu.begin_I2C(0x6B)) {
        Serial.println("ERROR: LSM6DSO32 not found at 0x6B!");
        Serial.println("Run the I2C Scanner example to check your address.");
        while (1) delay(100);
    }

    Serial.println("LSM6DSO32 connected at 0x6B");

    // ââ Accelerometer setup ââ
    // Range options: 4G, 8G, 16G, 32G
    imu.setAccelRange(LSM6DSO32_ACCEL_RANGE_16_G);

    // Data rate options: 12.5, 26, 52, 104, 208, 416, 833, 1660, 3330, 6660 Hz
    imu.setAccelDataRate(LSM6DS_RATE_104_HZ);

    // ââ Gyroscope setup ââ
    // Range options: 125, 250, 500, 1000, 2000 degrees per second
    imu.setGyroRange(LSM6DS_GYRO_RANGE_250_DPS);

    // Data rate (same options as accelerometer)
    imu.setGyroDataRate(LSM6DS_RATE_104_HZ);

    Serial.println("Accel: 16G range | Gyro: 250 dps range | Rate: 104Hz");
    Serial.println();
}

void loop() {
    // Read all sensor data in one call
    sensors_event_t accel, gyro, temp;
    imu.getEvent(&accel, &gyro, &temp);

    // Accelerometer (m/s^2)
    Serial.printf("Accelerometer (X/Y/Z) m/s2: %+7.2f  %+7.2f  %+7.2f",
        accel.acceleration.x,
        accel.acceleration.y,
        accel.acceleration.z);

    // Separator
    Serial.print("    |    ");

    // Gyroscope (degrees per second)
    Serial.printf("Gyro (X/Y/Z) dps: %+7.2f  %+7.2f  %+7.2f\n",
        gyro.gyro.x,
        gyro.gyro.y,
        gyro.gyro.z);

    delay(500);
}

#pragma once
/*
 * Mercury (ESP32-C6) Pin Definitions
 * Board-specific GPIO assignments
 */

// ââ Status LED (NeoPixel) ââ
#define LEDPOWER      3    // NeoPixel power (drive HIGH to enable)
#define LED           2    // NeoPixel data signal

// ââ I2C Bus ââ
#define SDA           21   // I2C data
#define SCL           22   // I2C clock

// ââ Sensor Power ââ
#define VACC          20   // Sensor power rail (drive HIGH to enable)

// ââ General Purpose Ports ââ
#define GP06          6    // GP06 port
#define GP07          7    // GP07 port

// ââ High Current Output ââ
#define OUT1          5    // High current output (e.g. pyro / relay)

// ââ Battery Bar LEDs ââ
#define BL1           4    // Battery LED 1 (lowest)
#define BL2           14   // Battery LED 2
#define BL3           15   // Battery LED 3
#define BL4           18   // Battery LED 4
#define BL5           19   // Battery LED 5 (highest)

// ââ Indicators ââ
#define DISK          8    // Disk activity LED

// ââ Analogue / Detection ââ
#define BATIN         0    // Battery voltage (1:1 divider)
#define USBDETECT     1    // USB power detect (HIGH = USB present)
#define BUTTON        9    // BUTTON on the board, boot button but can be used