필터 지우기
필터 지우기

How to view SPI Arduino data from accelerometer within Matlab?

조회 수: 12 (최근 30일)
almolch
almolch 2017년 11월 9일
댓글: Damian Krzaszcz 2022년 1월 22일
I am trying to see the data output of an ADXL345 accelerometer that is connected through SPI to an Arduino. When working within the Arduino IDE I can configure it to show X, Y, and Z values for acceleration, but how do I do this within Matlab? The circuit is set up as described on the Sparkfun website: https://learn.sparkfun.com/tutorials/adxl345-hookup-guide
So far I have added the Arduino as a device and have initiated a connection with the below code:
a=arduino;
dev=spidev(a,'D10')
I am not sure what the next step would be to collect the acceleration data. Any advice is appreciated, thanks!

답변 (1개)

Madhu Govindarajan
Madhu Govindarajan 2017년 11월 9일
Here is a link on how to communicate with external sensors using SPI - https://www.mathworks.com/help/supportpkg/arduinoio/examples/communicate-with-spi-device-on-arduino-hardware.html
From this it looks like they are writing a command and immediately reading the SPI device (which might be necessary for your sensor too). Compare both the spec sheets and you should be able to get going easily.
HTH, Madhu
  댓글 수: 1
Damian Krzaszcz
Damian Krzaszcz 2022년 1월 22일
I have a similar problem.
I followed the instructions in the link.
Here's a snippet of my code:
a = arduino ('COM3', 'Uno', 'Libraries', 'SPI');
ADXL345 = device (a, 'SPIChipSelectPin', 'D10');
data = writeRead (ADXL345, [1, hex2dec ('F2'), 0]);
I created an SPI device, then with the writeRead function I tried to read the registers from 0x31 to 0x37, but to no avail.
In the documentation for the sensor I found that to read these registers in the SPI standard, you need to send the value 0xF2 in the byte sent from the Master, and then the X Y Z registers are received from the slave..
How to solve this problem?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB Support Package for Arduino Hardware에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by