Effacer les filtres
Effacer les filtres

How to view SPI Arduino data from accelerometer within Matlab?

12 vues (au cours des 30 derniers jours)
almolch
almolch le 9 Nov 2017
Commenté : Damian Krzaszcz le 22 Jan 2022
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!

Réponses (1)

Madhu Govindarajan
Madhu Govindarajan le 9 Nov 2017
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 commentaire
Damian Krzaszcz
Damian Krzaszcz le 22 Jan 2022
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?

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB Support Package for Arduino Hardware dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by