2021-08-12 04:30 AM
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
2021-08-12 05:46 AM
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
2021-08-12 06:57 AM
The init function basically enables the accelerometer by writing to the control register.
Thanks Eleon I will try out what you suggested as well,
2021-08-12 07:06 AM
or doing this
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!!
2021-08-12 07:18 AM
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
2021-08-14 12:20 PM
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!!
2021-08-19 12:32 AM
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
2021-08-22 12:45 AM
Hey Eleon,
An explanation for the The I2C method writeto_mem is :
I2C.writeto_mem(addr, memaddr, buf, *, 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!!
2021-08-22 01:22 AM
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.
2021-09-02 05:09 AM