EasyManuals Logo

Freenove Ultimate Starter Kit User Manual

Freenove Ultimate Starter Kit
286 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #264 background imageLoading...
Page #264 background image
Chapter 25 Attitude Sensor MPU6050
264
www.freenove.com
support@freenove.com
Code
In this project, we will read the acceleration data and gyroscope data of MPU6050, and print them out.
C Code 25.1.1 MPU6050RAW
First observe the project result, and then analyze the code.
1. Use cd command to enter 25.1.1_MPU6050RAW directory of C code.
cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/C_Code/24.1.1_MPU6050RAW
2. Use following command to compile "MPU6050RAW.c", "MPU6050.cpp" and "I2Cdev.cpp", and generate
executable file "MPU6050RAW".
gcc MPU6050RAW.cpp MPU6050.cpp I2Cdev.cpp -o MPU6050RAW
3. Then run the generated file "MPU6050RAW".
sudo ./MPU6050RAW
After the program is executed, the terminal will display the original acceleration and gyroscope data of
MPU6050, as well as the conversion to gravity acceleration and angular velocity as the unit of data. As shown
in the following figure:
The following is the program code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include "I2Cdev.h"
#include "MPU6050.h"
MPU6050 accelgyro; //instantiate a MPU6050 class object
int16_t ax, ay, az; //store acceleration data
int16_t gx, gy, gz; //store gyroscope data
void setup() {
// initialize device
printf("Initializing I2C devices...\n");
accelgyro.initialize(); //initialize MPU6050
// verify connection
printf("Testing device connections...\n");

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Freenove Ultimate Starter Kit and is the answer not in the manual?

Freenove Ultimate Starter Kit Specifications

General IconGeneral
BrandFreenove
ModelUltimate Starter Kit
CategorySingle board computers
LanguageEnglish