cancel
Showing results for 
Search instead for 
Did you mean: 

LIS2DW12TR not returning values

YBend.1
Associate III

I am trying to run the ACCEL 10 CLICK based on the LIS2DW12TR on MicroPython on i2c protocol.

A perfectly working code of the ADXL345 is https://github.com/DFRobot/micropython-dflib/blob/master/ADXL345/user_lib/ADXL345.py

Taking this as a reference I tried to run the LIS2DW12TR by making change of respective registers. My code is as follows:https://github.com/Yadnik1/Accel-10-i2c ,however it returns only 0's an output of the three axes and does not sense any change on movement.Can someone please tell me where I may be going wrong.Thank you!!

References:

Accel 10 click:https://www.mikroe.com/accel-10-click

LIS2DW12TR data sheet: https://download.mikroe.com/documents/datasheets/lis2dw12_datasheet.pdf

10 REPLIES 10
Eleon BORLINI
ST Employee

Hi @YBend.1​ ,

I'm not sure you are correctly initializing the device. Can you please explain the steps of the init function below?

def __init__(self,i2c,addr=device):
        self.addr = addr
        self.i2c = i2c
        b = bytearray(1)
        b[0] = 0
        self.i2c.writeto_mem(self.addr,0x21,b)
        b[0] = 16
        self.i2c.writeto_mem(self.addr,0x21,b)
        b[0] = 8
        self.i2c.writeto_mem(self.addr,0x21,b)

The initialization procedure is described for example in the AN5038 application note, p.22:

1. Write 64h in CTRL1 (20h) // Turn on the accelerometer
// ODR = 200 Hz, High-Performance
2. Write 04h in CTRL6 (25h) // FS ±2 g, LOW_NOISE enabled

Otherwise, to check whether it could be an issue of the I2C communication, you can check the value of the WHO_AM_I (0Fh) register.

-Eleon

YBend.1
Associate III

The init function basically enables the accelerometer by writing to the control register.

Thanks Eleon I will try out what you suggested as well,

YBend.1
Associate III
  1. def __init__(self,i2c,addr=device):
  2. self.addr = addr
  3. self.i2c = i2c
  4. b = bytearray(1)
  5. b[0] = 0
  6. self.i2c.writeto_mem(self.addr,0x20,b)
  7. b[0] = 16
  8. self.i2c.writeto_mem(self.addr,0x20,b)
  9. b[0] = 8
  10. self.i2c.writeto_mem(self.addr,0x20,b)

or doing this

  1. def __init__(self,i2c,addr=device):
  2. self.addr = addr
  3. self.i2c = i2c
  4. b = bytearray(1)
  5. b[0] = 0
  6. self.i2c.writeto_mem(self.addr,0x25,b)
  7. b[0] = 16
  8. self.i2c.writeto_mem(self.addr,0x25,b)
  9. b[0] = 8
  10. self.i2c.writeto_mem(self.addr,0x25,b)

Also returns only 0's.Can you please tell me the value of the control register I should use.

Personally I feel the error is occurring in the init function only.The device ID is 0x18 and the status register address seem to be correct.

Thank you very much!!

Hi @YBend.1​ ,

I also think so. But from your _init_ function it looks as you are writing 3 different values in the same register, you just need to write 64h in reg 20h and 04h in 25h.

-Eleon

YBend.1
Associate III

Sorry Eleon,

I tried making changes in the init function accordingly but it is leading to further errors.Can you please make this change in the program, as it getting a bit difficult to follow.I am attaching a detailed commented out version of my code: https://github.com/Yadnik1/Accel10I2C/blob/main/ADXL345.py

It would be grateful if you could please make changes in init function or part of code that this change need to be made.

Thank you very much!!

Hi @YBend.1​ ,

I'm unfortunately not an expert on micropython, and in particular of the "machine" module and the related functions (I2C etc).

You might first share the scope pattern of the I2C so that it is possible to check if the send data are the correct one, and what you et back from the init function.

-Eleon

YBend.1
Associate III

Hey Eleon,

An explanation for the The I2C method writeto_mem is :

I2C.writeto_mem(addrmemaddrbuf*addrsize=8)

Write buf to the peripheral specified by addr starting from the memory address specified by memaddr.

A reference for it can be:https://docs.micropython.org/en/latest/library/machine.I2C.html

Thank you very much!!

YBend.1
Associate III

I also tried writing to the memory in this way:

self.i2c.writeto_mem(self.addr,0x20,b'\x64')

i.e. write 64h in reg 20h for turning on the accelerometer.

Eleon BORLINI
ST Employee

Hi @YBend.1​ ,

did you already try posting your question on the Micropython forum?

-Eleon