Giter Club home page Giter Club logo

mpu9255-quaternion-ahrs-stm32's Introduction

MPU9255-Quaternion-AHRS-STM32

Quaternion Based AHRS Estimation Using MPU9250 and STM32G431

Board used is: NUCLEO-G431RB

Detailed information: NUCLEO-G431RB

YouTube, Demo 1

YouTube, Demo 2

Blog Article

Circuit:

How to use?

Include needed librarys:

#include <stdio.h>
#include "mpu9255.h"

Create instance:

MPU9255_t MPU9255;

Add printf function properties:

int _write(int file, char *ptr, int len)
{
	HAL_UART_Transmit(&hlpuart1, (uint8_t*)ptr, len, HAL_MAX_DELAY);
	return len;
}

Define needed variables:

float pitch;
float yaw;
float roll;

Init sensor and wait until init completes. Also, add your I2C instance, &hi2c2 or &hi2c1 or &hi2c3...

while (MPU9255_Init(&hi2c2) == 1);

Delay 3 seconds, this is for after mag. calibration completes

HAL_Delay(3000);

Read all sensor data and calculate Quaternions:

readAll(&hi2c2, &MPU9255);

Assign calculated values to the variables

pitch = MPU9255.pitch;
yaw = MPU9255.yaw;
roll= MPU9255.roll;

Bonus: 3D Visualising using Python and PyGame

Create variable count, right before nain While:

int count;

In while loop, print all axis data every 10 microsecond. This is for prevent UART overflow:

if (count == 10){
  printf("%f\t", yaw);
  printf("%f\t", pitch);
  printf("%f\t\n", roll);
  count = 0;
}
count++;

Download 3dBody.py and change:

ser = serial.Serial('<PORT_NAME>', 115200)

<PORT_NAME> to the your Nucleo's COM port.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.