LSM6DSL data retrieval
Hi,
I am trying to get accelerometer and gyroscope readings from the LSM6DSL via a python script.
Here is my code so far:
def init(self):
# activate gyro and accel
self.write_reg(0x10,0b0110) #activate accelerometer (writing ODR_XL[3:0] in 0x10) at 416Hz
self.write_reg(0x11,0b0110) #activate gyro (writing ODR_G[3:0] in 0x11)
self.write_reg(0x06,1) # set fifo threshold to 1. only 1 piece of data stored at a time.
self.write_reg(0x08,0b00001001) # acceleromter and gyroscope being written to FIFO
self.write_reg(0x09,0b1) # enable fifo threshold, no other data being stored
self.write_reg(0x0A,0b00110110) # ODR=416, contonuous mode (end in 001 for fifo mode)
self.write_reg(0x12,0b01) # enable block data update (output registers not updated until MSB and LSB have been read)
def read_fifo(self):
status = self.read_reg(0x3A,2,raw=True)# read the FIFO_STATUS1 and FIFO_STATUS2 registers to see how much data is there
print('status:',status)
data= self.read_reg(0x3E,2,raw=True)
char_array = []
for char in data:
char_array.append(data.get('raw'))
print('data:',data['raw'])
ag = imuGyro(i2c)
ag.init()
while(True):
ag.read_fifo()
time.sleep(.5)
In summary, I...
- set activate accelerometer and gyroscope at 416Hz
- set fifo threshold to 1
- enabled both accel and gyro data to be written to the fifo
- enable the fifo threshold
- set ODR to 416Hz in continuous mode
- enabled Block Data Update (BDU)
but when I read the status registers (0x3A-3B), it indicates that the fifo is empty and never updates. Trying to read the fifo produces a few non-numerical characters:
status: {'raw': b'\x00\x10'}
data: b'"\xaa'Ideally, I would like to read the single piece of data available in the threshold, thus clearing it so that I can read the next piece of data. Is my understanding of the operation of this device accurate in what I've written so far? What can I do to achieve my desired result?
Thank you in advance.
