13.2 Based on the RPi-Spark basic driver architecture (Spark Drive mode)

JMRPi.Spark is RPi-Spark hardware driver library, it be installed with RPi-Spark SDK at same time. You can use them directly to build stand-alone applications and be used with other open source libraries. But using driver development more complicated than using RPiSparkModule.

Create a file named: 13_2_0_mpu6050.py, and type the content below:

import RPi.GPIO as GPIO
from JMRPiSpark.Drives.Attitude.MPU6050 import MPU6050
from JMRPiSpark.Drives.Attitude.MPU6050 import DEF_MPU6050_ADDRESS

GPIO.setmode(GPIO.BCM)
myAttitude = MPU6050( DEF_MPU6050_ADDRESS )
myAttitude.setAccelRange( MPU6050.ACCEL_RANGE_2G )
myAttitude.setGyroRange( MPU6050.GYRO_RANGE_250DEG )
myAttitude.open()
print( myAttitude.getAllData ( ) )
myAttitude.sleep()    # close MPU6050

Execute the following command in the terminal:

$> python 13_2_0_mpu6050.py

You can see the current position data in the terminal window, for example:

{'gyro': {'y': -96.20610687022901, 'x': 96.96946564885496, 'z': -94.25190839694656}, 'accel': {'y': 3.5673604736328124, 'x': 0.28490999755859375, 'z': 7.886500268554687}, 'temp': 29.823529411764707}

 

Was this article helpful?

YES     |     NO

 

Enjoying the project? Spotted a mistake? Any opinions on the website? Let us know!