2024-02-29 10:18 AM
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...
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.
2024-03-01 12:02 AM
Hi @nmorgan ,
Please try following these steps:
2024-03-05 11:59 AM
Thank you for your reply!
After implementing your changes, my fifo remains empty, and its status registers concur this.
I was able to read one piece of data directly from 28 and 29, though they do not update with new data, even when set in continuous mode.
2024-03-06 02:11 AM
Hi @nmorgan ,
That sounds strange. Can you give me more information about your setup?
In addition, are you able to get the outputs without FIFO (from reg 22h)?
2024-03-07 10:28 AM
Sure!
I'm using an Analog Discovery 2 to talk to the chip, alongside some python drivers to handle i2c with the device. I am able to talk to other chips with this setup, so I can confirm that it does work.
Reading 22h gives me 0.