Chapter 25 Attitude Sensor MPU6050
268
26
27
e x cept
KeyboardInterrupt
:
# When 'Ctrl+C' is pressed,the program will exit.
p a ss
A module "
MPU6050
.py" is used in the code. The module include a class used to operate MPU6050. When
used, first instantiate an object.
mpu
=
MPU6050
.
MPU6050
()
In the setup function, the MPU6050 is initialized.
d e f
setup
( ):
mpu
.
dmp_initialize
()
In the loop function, read the original data of MPU6050 and print them out, and then convert the original
data into the corresponding acceleration and angular velocity, then print the converted data out.
d e f
loop
( ):
w h ile
(
True
):
accel
=
mpu
.
get_acceleration
()
#get accelerometer data
gyro
=
mpu
.
get_rotation
()
#get gyroscope data
p r int
(
"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
]))
p r int
(
"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
)
About class MPU6050:
Class MPU6050
This is a class library used to operate MPU6050, which can directly read and set MPU6050. Here are some
member functions:
d e f
_ _init__
(
self
,
a _bus
=
1
,
a _address
=
C
.
MPU6050_DEFAULT_ADDRESS
,
a _ xAOff
=
None
,
a _yAOff
=
None
,
a _zAOff
=
None
,
a _xGOff
=
None
,
a _ yGOff
=
None
,
a _zGOff
=
None
,
a _debug
=
False
):
Constructor
d e f
d mp_initialize
(
self
):
Initialization function, used to wake up MPU6050. Range of accelerometer is ±2g and range of gyroscope
is ±250 degrees/sec.
d e f
g et_acceleration
(
self
): &
d e f
g et_rotation
(
self
):
Get the original data of accelerometer and gyroscope.
For details of more relevant member functions, please refer to MPU6050.py under code folder.
Содержание Ultimate Starter Kit
Страница 1: ...Free your innovation Freenove is an open source electronics platform www freenove com ...
Страница 116: ...Chapter 9 Potentiometer RGBLED 116 www freenove com support freenove com Circuit Schematic diagram ...
Страница 117: ...117 Chapter 9 Potentiometer RGBLED www freenove com support freenove com Hardware connection ...
Страница 136: ...Chapter 12 Joystick 136 www freenove com support freenove com Circuit Schematic diagram Hardware connection ...
Страница 155: ...155 Chapter 14 Relay Motor www freenove com support freenove com Hardware connection OFF 3 3V ...
Страница 173: ...173 Chapter 16 Stepping Motor www freenove com support freenove com Hardware connection ...
Страница 182: ...Chapter 17 74HC595 LEDBar Graph 182 www freenove com support freenove com Circuit Schematic diagram Hardware connection ...
Страница 197: ...197 Chapter 18 74HC595 7 segment display www freenove com support freenove com Circuit Schematic diagram ...
Страница 198: ...Chapter 18 74HC595 7 segment display 198 www freenove com support freenove com Hardware connection ...
Страница 239: ...239 Chapter 22 Matrix Keypad www freenove com support freenove com Circuit Schematic diagram ...
Страница 240: ...Chapter 22 Matrix Keypad 240 www freenove com support freenove com Hardware connection ...
Страница 270: ...Chapter 26 WebIOPi IOT 270 www freenove com support freenove com Circuit Schematic diagram Hardware connection ...