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 #267 background imageLoading...
Page #267 background image
267
Chapter 25 Attitude Sensor MPU6050
www.freenove.com
support@freenove.com
Python 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 Python code.
cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/Python_Code/25.1.1_MPU6050RAW
2. Use python command to execute code "MPU6050RAW.py".
python MPU6050RAW.py
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
19
20
21
22
23
24
25
im port MPU6050
im port time
mpu = MPU6050.MPU6050() #instantiate a MPU6050 class object
accel = [ 0]*3 #store accelerometer data
gyro = [0]*3 #store gyroscope data
def setup():
mpu. dmp_initialize() #initialize MPU6050
def loop():
w hile(True):
accel = mpu. get_acceleration() #get accelerometer data
gyro = mpu. get_rotation() #get gyroscope data
print("a/g:%d\t%d\t%d\t%d\t%d\t%d
"%(accel[0],accel[1],accel[2],gyro[0],gyro[1],gyro[2]))
print("a/g:%.2f g\t%.2f g\t%.2f g\t%.2f d/s\t%.2f d/s\t%.2f
d/s"%(accel[0]/16384.0,accel[1]/16384.0,
accel[2]/16384.0,gyro[0]/131.0,gyro[1]/131.0,gyro[2]/131.0))
time.sleep(0.1)
if __name__ == '__main__': # Program start from here
p rint("Program is starting ... ")
setup()
try:
loop()

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