X893

3D-Accelerometer to GM862

Connect accelerometer chip to GM862 tracker

To use in Python:


class LIS3LV02:
	def __init__(self):
		self.LIS3LV02_ADDR = 0x1D
#		GPIO.setIOdir(13, 0, 0)
		self.i2cbus = IIC.new(3, 12, self.LIS3LV02_ADDR)
		self.Error = 0
		self.Data = [0,0,0]
		if (self.i2cbus.init() == -1):
			print 'LIS3LV02 initialization error (1)'
			self.Error = 1
		elif (self.i2cbus.readwrite('\x20\x87', 0) == -1):
			print 'LIS3LV02 initialization error (2)'
			self.Error = 2
		else:
			ret = self.i2cbus.readwrite('\x0F', 1)
			if (len(ret) == 1 and ord(ret[0]) == 0x3A):
				self.Error = 0
			else:
				print 'LIS3LV02 initialization error (3) : ' + ret
				self.Error = 3

	def Read(self):
		self.Data[0] = 0
		self.Data[1] = 0
		self.Data[2] = 0
		if (self.Error == 0 or self.Error == 4):
			ret = self.i2cbus.readwrite('\xA8', 6)
			if (ret == -1):
				self.Error = 4
				print 'LIS3LV02 read error : %s' + ret
			elif (len(ret) != 6):
				self.Error = 4
				print 'LIS3LV02 read error : %s' + ret
			else:
				self.Error = 0
				for i in range(0,3):
					k = ord(ret[i * 2 + 1])
					k = k << 8;
					k = k + ord(ret[i * 2])
					if (k > 32767):
						k = k - 65536
					self.Data[i] = k;
		return self.Data

0 comment(s) so far

Post your comment

Thanks for your comments

  • Comment

Github
Bitbucket
Codeplex
SF.net

Skype

Subscribe to x893 blog Subscribe