Using the LSM9DS19 axis inertia measurement module, we have created a program that repeats the acquisition and display of acceleration, gyro, magnetism, and temperature sensor values over an I2C connection.
If you look at the raw data, A is the acceleration sensor, G is the gyro sensor, M is the magnetic sensor, XYZ is the axis, Temp is the temperature sensor (mysterious value).
What is the program that converts the raw data value of this sensor to acceleration (m/S^2), gyro (dps), magnetism (gauss), and temperature (°C)?
#!/usr/bin/python
# -*-coding:utf-8-*-
import smbus
import time
addressG = 0x6a
addressA = 0x6a
addressM = 0x1c
getG = 0x18
getA = 0x28
getM = 0x28
getTemp = 0x15
CTRL_REG1_G = 0x10
CTRL_REG4 = 0x1E
CTRL_REG5_XL = 0x1F
CTRL_REG3_M = 0x22
bus = smbus.SMBus(1)
bus.write_byte_data(addressG,CTRL_REG1_G,0b00100000)#gyro/accelodr and bw
bus.write_byte_data(addressG,CTRL_REG4,0b00111000)#enable gyroaxis
bus.write_byte_data(addressA,CTRL_REG5_XL,0b00111000)#enable accelerometer
bus.write_byte_data(addressM,CTRL_REG3_M,0b000000)#enable mag continuous
default (alterdata):
return altdata if altdata<32768 else altdata-65536
# Raw data of gyro, acceleration, magnetic, and temperature sensors are acquired and displayed repeatedly.
while True:
dataA=bus.read_i2c_block_data(addressA,getA,6)
rawAX=dataA[0]|dataA[1]<8
rawAY=dataA[2]|dataA[3]<8
rawAZ=dataA[4]|dataA[5]<8
AX=alter(rawAX)
AY=alter(rawAY)
AZ=alter(rawAZ)
print "AX:"+"%d"%AX+",
print "AY:"+"%d"%AY+",
print "AZ:"+"%d"%AZ+""
dataG=bus.read_i2c_block_data(addressG,getG,6)
rawGX=dataG[0]|dataG[1]<8
rawGY=dataG[2]|dataG[3]<8
rawGZ=dataG[4]|dataG[5]<8
GX=alter(rawGX)
GY=alter(rawGY)
GZ=alter(rawGZ)
print "GX:"+"%d"%GX+",
print "GY:"+"%d"%GY+",
print "GZ:"+"%d"%GZ+""
dataM=bus.read_i2c_block_data(addressM,getM,6)
rawMX=dataM[0]|dataM[1]<8
rawMY=dataM[2]|dataM[3]<8
rawMZ=dataM[4]|dataM[5]<8
MX=alter(rawMX)
MY=alter(rawMY)
MZ=alter(rawMZ)
print "MX:"+"%d"%MX+",
print "MY:"+"%d"%MY+",
print "MZ:"+"%d"%MZ+""
dataTemp=bus.read_i2c_block_data(addressG,getTemp,2)
rawTemp=dataTemp[0]|dataTemp[1]<8
print "Temp:"+"%d"%rawTemp+""
print("-------------------------------------------")
time.sleep(1)
It may have already been resolved, and
This is not a direct answer, but
The library for Arduino converts Raw data to a directly readable value.
Search the library source by calAccel or calcGyro
© 2024 OneMinuteCode. All rights reserved.