Skip to content

okalachev/flixperiph

Repository files navigation

Arduino drivers for the Flix drone peripherals

This library contains Arduino drivers for the peripherals used in the Flix drone project.

Based on:

MPU-9250/MPU-6500 IMU

Example for SPI-connected IMU:

#include <MPU9250.h>
#include <SPI.h>

MPU9250 IMU(SPI); // no need to specify CS pin, the default pin is used automatically

void setup() {
  IMU.begin();
}

void loop() {
  float gx, gy, gz, ax, ay, az, mx, my, mz;
  IMU.waitForData(); // blockingly read the data, use IMU.read() for non-blocking read
  IMU.getGyro(gx, gy, gz);
  IMU.getAccel(ax, ay, az);
  IMU.getMag(mx, my, mz);
  // Process the data...
}

The library will detect IMU type (MPU-9250 or MPU-6500) automatically. You can use the following method to check the detected type:

if (IMU.isMPU6500()) {
  // MPU6500 detected
} else {
  // MPU9250 detected
}

Notice, that MPU6500 does not include a magnetometer, so magnetometer data will be always zero.

You can also use <MPU6500.h> header and MPU6500 class, which is an alias for MPU9250 class.

Connection

Connecting GY-91 board to ESP32 using VSPI:

  • 3V3 → 3V3
  • GND → GND
  • SCL → IO18
  • SDA (MOSI) → IO23
  • SAO (MISO) → IO19
  • NCS → IO5

Connecting MPU-92.65 board to ESP32 using VSPI:

  • VCC → 3V3
  • GND → GND
  • SCL → IO18
  • SDA (MOSI) → IO23
  • AD0 (MISO) → IO19
  • NCS → IO5

Logging

By default, the library logs some of the errors to the serial output. On ESP32, the default serial port is determined by the Core Debug Output mechanism, thus can be changed using setDebugOutput method:

Serial2.setDebugOutput(true); // all the debug output will now be sent to Serial2

On platforms other than ESP32, the default output port is Serial. On all platforms the debug output can be changed using setLogOutput method:

IMU.setLogOutput(Serial2);

The debug output can be disabled using setVerbosity method:

IMU.setVerbosity(false); // disable debug output

SBUS

Example for SBUS receiver, connected to Serial2:

#include <SBUS.h>

SBUS RC(Serial2, true); // Using Serial2, software inversion enabled

void setup() {
  Serial.begin(115200);
  RC.begin();
}

void loop() {
  if (!RC.read()) return;
  SBUSData data = RC.data();
  for (int i = 0; i < data.NUM_CH; i++) {
    Serial.print(data.ch[i]);
    Serial.print(" ");
  }
}

Connection

Connecting SBUS receiver to ESP32:

  • VIN → 3V3
  • GND → GND
  • SIGNAL → IO16 (RX2)