Skip to main content
Explorer
February 29, 2024
Question

LSM6DSL data retrieval

  • February 29, 2024
  • 4 replies
  • 5061 views

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.

    This topic has been closed for replies.

    4 replies

    Technical Moderator
    March 1, 2024

    Hi @nmorgan ,

    Please try following these steps:

    • Set XL and Gyro full scale and ODR (CTRL1_XL (10h), CTRL2_G (11h))
    • Set FIFO mode to Continous mode and ODR FIFO (FIFO_CTRL5 (0Ah) )
    • Enable FIFO watermark interrupt generation on INT1 pin (FIFO_CTRL1 (06h))
    • Set FIFO sensor decimator both for Gyro and XL (FIFO_CTRL3 (08h))
    • Read FIFO Data out (FIFO_DATA_OUT_L (3Eh), FIFO_DATA_OUT_H (3Fh))

     

    nmorganAuthor
    Explorer
    March 5, 2024

    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.

    Technical Moderator
    March 6, 2024

    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)?

    nmorganAuthor
    Explorer
    March 7, 2024

    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.