フィルターのクリア

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 Center および File ExchangeMATLAB 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