How to view SPI Arduino data from accelerometer within Matlab?
4 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
回答(1 个)
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
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 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!