How can I increase the SampleRate of an ADXL345 accelerometer beyond 200 Hz?
조회 수: 16 (최근 30일)
이전 댓글 표시
I connected an ADXL345 accelerometer to an Arduino MKRzero and acquire a signal continuously by Matlab, using the following code:
clearvars
a = arduino('COM7', 'MKRZERO', Libraries='I2C');
sensorobj = adxl345(a);
sensorobj.SampleRate = 200;
sensorobj.SamplesPerRead = 500;
sensorobj.OutputFormat = 'matrix';
[sensorReadings,overrun] = read(sensorobj);
With the default settings it looks like:
- MaxSampleRate = 200 Hz
- MaxSamplesPerRead = 500 samples
As can be read in the file "adxl345.m".
In fact the system acquires correctly with SampleRate = 200 Hz, but if I want to increase the SampleRate and bring it to 800 Hz, which is sustainable by ADXL345, the system does not work.
Reading on the datasheet I found that the MaxSampleRate is linearly related to the value of the BitRate which by default is set to BitRate = 100000 (as can be read in the "sensorBase.m" file), in fact the datasheet says "Due to communication speed limitations, the maximum output data rate when using 400 kHz I2C is 800 Hz and scales linearly with a change in the I2C communication speed. For example, using I2C at 100 kHz would limit the maximum ODR to 200 Hz."
I tried editing the file "sensorBase.m" by setting a BitRate = 400000, and editing the file "adxl345.m" by setting a MaxSampleRate = 800, but the system still does not work.
Can someone help me figure out how to remove the MaxSampleRate = 200 Hz limitation and allow the accelerometer to work with a higher acquisition rate?
Thank you in advance
댓글 수: 0
답변 (1개)
Amal Raj
2024년 7월 1일
Hi Earmello. Unfortunately, directly increasing the SampleRate property of the adxl345 object in MATLAB won't work for the ADXL345 accelerometer. The MATLAB Support Package for Arduino Hardware limits the sample rate to 200 Hz due to I2C communication speed limitations.
You can consider leveraging SPI communication if possible.The ADXL345 supports SPI communication, which allows for higher data transfer rates compared to I2C. If your hardware setup allows for SPI communication, you can explore libraries or custom code to interact with the ADXL345 through SPI and potentially achieve higher sample rates (up to 3.2 kHz according to the datasheet).
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Modeling에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!