Skip to content

Problems using library with Arduino NANO BLE Sense  #7

@redflowIT

Description

@redflowIT

Hi Aster94
I'm using library with an Arduino BLE Sense with embedded Gyroscope and an external micro display. It seems it needs seconds to stabilize values, should I use an external IMU or what I'm doing wrong?

`#include <Arduino.h>
#include <Arduino_LSM9DS1.h> // Sensoristica
#include <U8g2lib.h> // Display
#include <SensorFusion.h> // Calcolo

// Inizializzazione DISPLAY
U8G2_LD7032_60X32_F_4W_SW_SPI u8g2(U8G2_MIRROR, /* clock=/ 9, / data=/ 8, / cs=/ 11, / dc=/ 10, / reset=/ 12); // PROTOTIPO SALDATO SU BASETTA
//U8G2_LD7032_60X32_F_4W_SW_SPI u8g2(U8G2_MIRROR, /
clock=/ 11, / data=/ 12, / cs=/ 9, / dc=/ 10, / reset=*/ 8);

const int samplingCicleBeforeRefresh = 30;
SF fusion;

float xAcc, yAcc, zAcc;
float xGyro, yGyro, zGyro;
float xMag, yMag, zMag;
float deltat;

int roll, pitch, yaw;

void setup() {
Serial.begin(115200);
//while (!Serial);
Serial.println("Started");

if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while (1);
}
//filter.begin(sensorRate);

u8g2.begin();
deltat=fusion.deltatUpdate();
// Abbasso il PIN per poter attivare il display (aggancio la massa)
pinMode(A0, OUTPUT);
digitalWrite(A0, LOW);
}

void refreshDisplay(int yaw, int pitch, int roll)
{
char buff[16];

u8g2.clearBuffer();
u8g2.setFont(u8g2_font_artosserif8_8u);
snprintf (buff, sizeof(buff), "R%d ", yaw);
u8g2.drawStr(10,10,buff);
Serial.print(buff);
snprintf (buff, sizeof(buff), "F%d ", pitch);
u8g2.drawStr(10,19,buff);
Serial.print(buff);
snprintf (buff, sizeof(buff), "I%d ", roll);
u8g2.drawStr(10,28,buff);
Serial.println(buff);
u8g2.sendBuffer();
}

void loop() {
// read accelerometer & gyrometer:
IMU.readAcceleration(xAcc, yAcc, zAcc);
IMU.readGyroscope(xGyro, yGyro, zGyro);
IMU.readMagneticField(xMag, yMag, zMag);

deltat = fusion.deltatUpdate(); //this have to be done before calling the fusion update
//choose only one of these two:
//fusion.MahonyUpdate(xGyro, yGyro, zGyro, xAcc, yAcc, zAcc, deltat); //mahony is suggested if there isn't the mag and the mcu is slow
fusion.MadgwickUpdate(xGyro * DEG_TO_RAD, yGyro * DEG_TO_RAD, zGyro * DEG_TO_RAD, xAcc, yAcc, zAcc, xMag, yMag, zMag, deltat); //else use the magwick, it is slower but more accurate

// print the heading, pitch and roll
roll = round(fusion.getRoll());//round(fusion.getRoll()-90);
pitch = round(fusion.getPitch());
yaw = round(fusion.getYaw());//round(180-fusion.getYaw());

//Serial.print("Y ");
//Serial.print(yaw);
//Serial.print(" P ");
//Serial.print(pitch);
//Serial.print(" R ");
//Serial.println(roll);

refreshDisplay (yaw, pitch, roll);
}`

Thank you
Regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions