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

(Internet connection not required yet)

Set timezone
enable SSH

Then, Finish.

Terminal code:

Step 3: Optional: Operate Pi Headless

Excellent tutorial at

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

Step 6: Optional - Setup VNC

Excellent tutorial at

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


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

Terminal code:
// 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?
tar xvfz bcm2835-1.5.tar.gz;
cd bcm2835-1.5;
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

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

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.
Awesome instructable. If your RasPi browser nameserver isn't pulling up domains, try: <br> <br># sudo cat &gt;&gt; /etc/resolv.conf <br>nameserver <br>control-z-key <br> <br>This adds the Google public DNS server. You can add any nameserver you want instead of <br> <br>Others can build on this to do hardware SPI instead of bitbanging, saving digital pins and making things faster, cool :)
<p>Ctrl-Z is ugly... When you give instructions, you try to make it 1d10t-proof:</p><p>grep &quot;^nameserver.*$&quot; /etc/resolv.conf &gt; /dev/null ; if [ &quot;${?}&quot; -ne &quot;0&quot; ] ; then echo -en &quot;\nnameserver\n&quot; &gt;&gt; /etc/resolv.conf ; fi</p><p>That way, you are sure the line is added only once in the file with a simple copy&amp;paste and can be run as many times without crippling your DNS resolver.</p><p> is Google's openDNS but the DHCP from your DSL router should have pointed you to a fast accurate DNS, usually looking like (your router is usually a DNS server too in home installations) ; if your DNS is not set, it's probably you've already been fiddling with static manual IP configuration without being too sure of what you were doing (to say it mildly).</p><p> is convenient, but you should never use it for normal operation.</p>
Thanks so much for the tip! I can use all the advice I can get ;) <br> <br>I'll give it a try, and update the tutorial if is works.
Hi All. <br>Before step 10 i suggest to check if in /etc/modprobe.d/raspi-blacklist.conf you have blacklisted spi... I had. The file should look like this: <br> <br># blacklist spi and i2c by default (many users don't need them) <br>#blacklist spi-bcm2708 <br>#blacklist i2c-bcm2708
or just this. <br> <br>git clone git://github.com/annem/ADXL362_RaspPi
I had to update the following command in order to get this tutorial to work: <br>(1) updated inputs (denoted by -I in command) <br>(2) updated the path from ../bcm2835.c to ../bcm2835-1.5/src/bcm2835.c <br>(3) updated file name from ADXL_RaspPi.c to ADXL362_RaspPi.c <br> <br>gcc -o ADXL362_RaspPi -I ../bcm2835-1.5/src ../bcm2835.c ADXL_RaspPi.c <br> <br> <br>
-Try this to do it from command line: <br> <br>1) create a specific directory: <br>mkdir ADXL362_RaspPi <br>cd ADXL362_RaspPi/ <br> <br>2) install Git if you don't have it: <br>sudo apt-get install git <br> <br>3) create a repository and pull from Github: <br>git init . <br>git add . <br>git pull https://github.com/annem/ADXL362_RaspPi.git
You can avoid the email by using IPv6 Link Local. <br>Your raspberry PI will always have the same IPv6 Link Local address every time it boots and it's determined from it's mac address. <br> <br>For example, if your PI has a MAC address of 23:45:67:89:ab:cd, then it's link local address will be fe80::2145:67ff:fe89:abcd. <br> <br>Converting the MAC to link local is as follows: Take the first three octets of MAC and insert FFFE and then the last 3 octets. (all values in hex). <br>For 11:11:11:22:22:22 this results in 1111:11FF:FE22:2222 <br> <br>Then, invert the 0x02 bit of the first octet: 1311:11ff:fe22:2222. <br> <br>Finally place fe80:: in front fe80::1311:11ff:fe22:2222 <br> <br>Now, to communicate with that, you will need to specify the interface ID of the outbound interface on your machine. On rational systems, this is the name of the interface, such as &quot;eth0&quot; on Linux or &quot;en0&quot; on Mac, &quot;fxp0&quot; on BSD, etc. On windows boxes, it's unfortunately a number which has little rime or reason to it, but you should be able to get the correct number from ipconfig /all. <br>
I'll have to tinker with that... thanks! Not familiar with IPv6, yet. Thanks for the tip!

About This Instructable




More by engineerbynight:*Preliminary* SPI on the Pi: Communicating with a SPI 3-axis accelerometer using a Raspberry Pi 
Add instructable to: