Created
September 24, 2012 14:50
-
-
Save KitWallace/3776335 to your computer and use it in GitHub Desktop.
Devantech CMPS010 module V2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Adafruit_I2C import Adafruit_I2C | |
# =========================================================================== | |
# CMPS10 Class | |
# The CMPS10 board is developed by devantech | |
# Chris Wallace 2012-09-19 | |
# 2012-09-24 addresses corrected, magnetic and true bearings, @property, dXYZ renamed | |
# =========================================================================== | |
class CMPS10(object) : | |
__CMPS10_bearing8 = 0x01 | |
__CMPS10_bearing16 = 0x02 | |
__CMPS10_pitch = 0x04 | |
__CMPS10_roll = 0x05 | |
__CMPS10_X = 0x0A | |
__CMPS10_Y = 0x0C | |
__CMPS10_Z = 0x0E | |
__CMPS10_aX = 0x10 | |
__CMPS10_aY = 0x12 | |
__CMPS10_aZ = 0x14 | |
def __init__(self, address=0x60, debug=False): | |
self.i2c = Adafruit_I2C(address) | |
self.address = address | |
self.debug = debug | |
@property | |
def magnetic_bearing(self): | |
"Reads the high resolution compass bearing" | |
bearing16 = float(self.i2c.readU16(self.__CMPS10_bearing16)) / 10 | |
if (self.debug): | |
print "DBG: magnetic bearing: ", bearing16 | |
return bearing16 | |
def true_bearing(self,declination) : | |
true = ((self.magnetic_bearing + declination) + 360) % 360 | |
if (self.debug) : | |
print "DBG: declination: ", declination," true bearing: ", true | |
return true | |
@property | |
def pitch(self) : | |
"Reads the pitch as a signed 8 bit angle in degrees" | |
pitch = self.i2c.readS8(self.__CMPS10_pitch) | |
if (self.debug): | |
print "DBG: pitch: ", pitch | |
return pitch | |
@property | |
def roll(self) : | |
"Reads the roll as a signed 8 bit angle in degrees" | |
roll = self.i2c.readS8(self.__CMPS10_roll) | |
if (self.debug): | |
print "DBG: roll: ", roll | |
return roll | |
@property | |
def XYZ(self) : | |
"Reads the raw XYZ magnatron values " | |
XYZ = (self.i2c.readS16(self.__CMPS10_X),self.i2c.readS16(self.__CMPS10_Y),self.i2c.readS16(self.__CMPS10_Z)) | |
if (self.debug): | |
print "DBG: raw: ", XYZ | |
return XYZ | |
@property | |
def aXYZ(self) : | |
"Reads the XYZ accelerometer values " | |
aXYZ = (self.i2c.readS16(self.__CMPS10_aX),self.i2c.readS16(self.__CMPS10_aY),self.i2c.readS16(self.__CMPS10_aZ)) | |
if (self.debug): | |
print "DBG: accelerometer: ", aXYZ | |
return aXYZ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment