Connecting ADXL345 and Raspberry Pi using SPI or I2C

5 views (last 30 days)
Is there a way in which I can download the .m file used in the video 'Using MATLAB and Raspberry Pi with an Accelerometer', so that I can see how to read the data from an acclerometer via SPI within MATLAB? Or if I could get some form of help with writing my own I would be grateful.
Link to the video: https://uk.mathworks.com/videos/using-matlab-and-raspberry-pi-with-an-accelerometer-94189.html
Alternatively, is there anywhere I could find help connecting reading the same accelerometer via I2C? I can connect it via I2C, gain the address of the ADXL345 as 0x53, but then I can't see how to read the data. I know that the x,y and z data is on 0x32 to 0x37, but I can't see how to return the data within MATLAB. I find the video 'Using MATLAB and Raspberry Pi with an I2C Sensor' somewhat useful until, again it comes to reading the data. Link to video:
https://uk.mathworks.com/videos/using-matlab-and-raspberry-pi-with-an-i2c-sensor-94194.html
I am fairly new to the Raspberry Pi and connecting components via SPI/I2C, so would be very grateful for a simplified explanation/point in the right direction where I can learn more.
  3 Comments
Darren Williams
Darren Williams on 5 Jan 2018
Hi Jayaram, thank you for your help, I have looked in to the registers and have discovered which ones I need to use and what values to write to these registers, and I have produced the code:
However, it just gives me a value of 0? Does this mean that the connection is not established properly? I have run an example code in Python on the Raspbian Pi itself and that appears to work. However this code does seem to obtain block data in a block of 6 bytes from adress '0x53' and register '0x32', is there a method of returning block data from the device within MATLAB? Again it could just be me missing something in the code, or my poor knowledge in this area...
Thanks in advance!
Arvind Srivastav
Arvind Srivastav on 5 Mar 2018
Hi Darren, I'm having a similar problem. Is the output of "address = char(scanI2CBus(rpi))" non-empty in your case?

Sign in to comment.

Answers (0)

Categories

Find more on MATLAB Support Package for Raspberry Pi Hardware in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!