Raspberry Pi connects 9-axis IMU sensor (GY-85 module)

Source: Internet
Author: User
! [GY-85] (http://images.cnblogs.com/cnblogs_com/hangxin1940/466697/o_gy85.jpg "GY-85 ")
9-axis IMU sensor (GY-85 module) can also be seen as three modules 'itg3205 Three-Axis Gyroscope sensor ''' adxl345 three-axis accelerator tilt sensor ''' hmc5883l Electronic Compass'

The GY-85 Module Interface is I2C and can be easily linked to the Arduino/Raspberry Pi.

# Preparations
Make sure the system has installed the quick2wire library, if not, move here to http://www.cnblogs.com/hangxin1940/archive/2013/04/04/2999015.html

Download the thinkbowl i2clibraries library in the appropriate directory

Git clone https://bitbucket.org/thinkbowl/i2clibraries.git

This i2clibraries library exactly contains the three sensor interfaces 'itg3205' adxl345' hmc5883l ', which are easy to develop. Note that the 'i2c _ itg3205.py' interface is used, by default, the address of the corresponding 'itg3205' device is '69'. To save trouble in the future, modify the following codes.

# Address will always be either 0x68 (104) or 0x69 (105)
Def _ init _ (self, port, ADDR = 0x68): # change the ADDR here to 68 and the original value is 69.

# Connection
! [Rasp] (http://images.cnblogs.com/cnblogs_com/hangxin1940/466697/o_rasp_gpio.png "rasp ")

This figure specifies the position of 5 V output and 3 V output in the Two-row gpio real script to specify the direction

! [Rasp] (http://images.cnblogs.com/cnblogs_com/hangxin1940/466697/o_rasp_GPIOs_gy85.png "rasp ")

This figure details the connection between the GY-85's true foot and Raspberry Pi gpio/I2C pin Angle

Although the GY-85 has 8 Real feet, but only four

# Test
Run 'i2cdetect 'to view the currently connected I2C Device
Raspberry Pi:

Sudo i2cdetect-Y 0

Raspberry Pi Type B:

Sudo i2cdetect-Y 1

The IP addresses of all connected I2C devices are displayed.
! [Device] (http://images.cnblogs.com/cnblogs_com/hangxin1940/466697/o_rasp_i2c3.png "3 devices ")

The address '68 'corresponds to the 'itg3205' device, '53' corresponds to the 'adxl345' device, and '1e' corresponds to the 'hmc5883l' device.

Here, the GY-85 module has been smoothly involved in Raspberry Pi

# Retrieve itg3205 gyroscope Information
For more information, go to http://think-bowl.com/raspberry-pi/i2c-python-library-3-axis-mems-gyro-itg-3205-with-the-raspberry-pi/

Create the 'i2c _ itg3205.py' script. Pay attention to the location of the script. Make sure that you can reference the downloaded 'i2clibraries' package or add the downloaded Python package to the Reference Path.

From i2clibraries import i2c_itg3205
From time import *

Itg3205 = i2c_itg3205.i2c_itg3205 (0)

While true:
(Itgready, dataready) = itg3205.getinterruptstatus ()
If dataready:
Temp = itg3205.getdietemperature ()
(X, y, z) = itg3205.getdegpersecaxes ()
Print ("Temp:" + STR (temp ))
Print ("X:" + STR (x ))
Print ("Y:" + STR (y ))
Print ("Z:" + STR (z ))
Print ("")

Sleep (1)

Run this script

Python3 i2c_itg3205.py

Output

Temp: 26.73
X:-8.278260869565218.
Y:-12.869565217391305.
Z:-28.034782608695654

Temp: 26.86
X:-1.808695652173913.
Y: 3.4782608695652173
Z:-13.773913043478261

# Obtain adxl345 three-axis/tilt information
For more information, go to http://think-bowl.com/raspberry-pi/i2c-python-library-3-axis-digital-accelerometer-adxl345-with-the-raspberry-pi/

New script 'i2c _ adxl345.py'

From i2clibraries import i2c_adxl345
From time import *

Adxl345 = i2c_adxl345.i2c_adxl345 (0)

While true:
Print (adxl345)
Sleep (1)

Output

X:-0.40625.
Y: 0.15625
Z:-0.9375

X:-0.40625.
Y: 0.15625
Z:-0.9375

# Obtain hmc5883l Electronic Compass Information
For more information, go to http://think-bowl.com/raspberry-pi/i2c-python-library-3-axis-digital-compass-hmc5883l-with-the-raspberry-pi/
New script 'i2c _ hmc5883l. py'

From i2clibraries import i2c_hmc5883l

Hmc5883l = i2c_hmc5883l.i2c_hmc5883l (0)

Hmc5883l. setcontinuousmode ()
Hmc5883l. setdeclination (9,54)

Print (hmc5883l)

Output

Axis X:-114.08
Axis Y:-345.92
Axis Z:-286.12
Declination: 9 ° 54'
Heading: 261 ° 39'

# Hack it!
The above sample code is very simple, but with 'i2clibraries' and the above sample code, we are enough to develop our own applications.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.