Manual Mercury V1
Descubre cómo volar rápidamente con facilidad, conecta tu altimeter para subir datos al sitio web de Altimeter Cloud y todas las características avanzadas también. Si estás atascado o apenas comenzando, este es el lugar indicado.

Ejemplo de código: acelerómetro y giroscopio LSM6DSO32

PDF

Este ejemplo muestra cómo puedes conectarte al IMU LSM6DSO32 (Acelerómetro y Giroscopio) y leer los valores.
Necesitas asegurarte de activar los sensores usando el pin VACC según este código.

Una vez programado, presiona el botón de encendido para reiniciar Mercury y luego conecta un monitor Serial.

¿Usas Arduino IDE? Nuestro programador en línea incluye Mercury_Pins.h por defecto para que los nombres de pines funcionen sin problemas. Si estás usando Arduino IDE u otro programador, copia el contenido de la pestaña Mercury_Pins.h y pégalo en la parte superior de tu programa.
/*
 * 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