Instructables

*Preliminary* SPI on the Pi: Communicating with a SPI 3-axis accelerometer using a Raspberry Pi

Picture of *Preliminary* SPI on the Pi: Communicating with a SPI 3-axis accelerometer using a Raspberry Pi
Step by step guide on how to setup Raspbian, and communicate with a SPI device using bcm2835 SPI library (NOT bit banged!)

This is still very preliminary... I need to add better pictures of physical hookup, and work through some of the awkward code.

Step 1: Starting with a blank SD card, download Raspbian image, and install onto SD card

Visit http://www.raspberrypi.org/downloads for instructions on how to install Raspbian

I downloaded:
    Raspbian image, and used
    Win32DiskImager to install on SD card

There's also more information at http://elinux.org/RPi_Easy_SD_Card_Setup

Step 2: Connect Raspberry Pi to TV/Monitor, and run through initial setup

Picture of Connect Raspberry Pi to TV/Monitor, and run through initial setup
(Internet connection not required yet)

Set timezone
enable SSH
Update

Then, Finish.

Terminal code:
reboot

Step 3: Optional: Operate Pi headless

Picture of Optional: Operate Pi headless
Excellent tutorial at
http://elinux.org/RPi_Remote_Access

I use Putty (Windows) or Terminal (Mac) to connect with SSH

Step 4: Recommended: Update OS

Terminal Code:
sudo apt-get update
sudo apt-get upgrade

Step 5: Optional: Setup IP Address e-mailer

I've set up my Pi to e-mail me it's IP address each time it boots.  This makes my life easier when I need to remote login using SSH.

Excellent tutorial at
http://elinux.org/RPi_Email_IP_On_Boot_Debian

Step 6: Optional - Setup VNC

Picture of Optional - Setup VNC
Excellent tutorial at
http://elinux.org/RPi_VNC_Server

I didn't go through the entire tutorial... just the following steps:
$ sudo apt-get install tightvncserver
$ tightvncserver
$ vncserver :1 -geometry 1200x800 -depth 24

And, I created a script to keep my typing to a minimum.

Step 7: Install BCM2835 SPI Library

https://gist.github.com/3183536

Excellent documentation (and examples) at http://www.open.com.au/mikem/bcm2835

Terminal code:
cd;
// wget http://www.open.com.au/mikem/bcm2835/bcm2835-1.5.tar.gz; // My Pi can't figure out this URL - unable to resolve host name?
wget http://67.192.60.197/mikem/bcm2835/bcm2835-1.5.tar.gz
tar xvfz bcm2835-1.5.tar.gz;
cd bcm2835-1.5;
./configure;
make;
sudo make install

Step 8: Get ADXL362 SPI example

Note: Code is still very basic... need to improve


get ADXL362_RaspPi from https://github.com/annem/ADXL362_RaspPi
(How to do this on Pi, using wget?  I'm having trouble with this... "unable to resolve host address 'github.com'")

Step 9: Phyiscally connect ADXL362 breakout to Raspberry Pi GPIO

Picture of Phyiscally connect ADXL362 breakout to Raspberry Pi GPIO
More details to come...

More info about ADXL362 (ultra low power 3-axis accelerometer) at analog.com/ADXL362

Connect 3v3, GND, SPI0 MOSI, SPI0 MISO, SPI0 SCLK, SPI0 CE0 N on Raspberry Pi to
VDDand VIO, GND (2), MOSI, MISO, SCLK, and CSB on ADXL362 Breakout board.


Step 10: Compile and Run ADXL362_RaspPi

Picture of Compile and Run ADXL362_RaspPi
terminal code:
gcc -o ADXL362_RaspPi -I ../bcm2835-1.5/src ../bcm2835.c ADXL_RaspPi.c
sudo ./ADXL362_RaspPi

Which I combines into a script called compileADXL362.
 
Remove these adsRemove these ads by Signing Up
julioterra1 year ago
I had to update the following command in order to get this tutorial to work:
(1) updated inputs (denoted by -I in command)
(2) updated the path from ../bcm2835.c to ../bcm2835-1.5/src/bcm2835.c
(3) updated file name from ADXL_RaspPi.c to ADXL362_RaspPi.c

gcc -o ADXL362_RaspPi -I ../bcm2835-1.5/src ../bcm2835.c ADXL_RaspPi.c