Connecting BerryIMUv3 via SPI to a Raspberry Pi

The accelerometer and gyroscope on the BerryIMUv3 can output data at a rate of 6,664 times a second!  I2C is too slow to read the output at this rate, this is where SPI comes in.

Buy default, BerryIMUv3 is setup to use I2C.  You can complete the SPI interface by placing a solder blob on jumper 7 (JP7).

BerryIMU SPI
Blob on jumper 7

 

SPI uses 4 pins,  and depending on what device you are using these pins could be named differently, which causes confusion.

The most common pin names are;

  • MOSI  (Master out Slave In)
  • MISO  (Master In Slave Out
  • SCLK (Serial Clock)
  • CS (chip select)  This is CE0 or CE1 on the Raspberry PI.

These pins have been highlighted below

Raspberry Pi SPI pins
Raspberry Pi 40 pin header

 

On the BerryIMUv3, they are called;

  • SDI (Slave Data In)
  • SDO (Slave Data Out)
  • SPC (Serial Port Clock)
  • CS (Chip Select)

When we connect a BerryIMUv3 to a Raspberry Pi using SPI, the Raspberry Pi will be acting as a master and the BerryIMUv3 will be acting as a slave. This is how they are connected logically.

BerryIMU SPI
BerryIMU and Raspberry Pi SPI

Here is the physical wiring

Raspberry Pi BerryIMU SPI
Raspberry Pi SPI and BerryIMUv3

 

You can enable SPI on the Raspberry Pi using raspi-config

pi@raspberrypi ~ $ sudo raspi-config

Raspberry Pi SPIGo into "Interfacing Options"

Raspberry Pi SPI
Then select "SPI"

When asked if you want to enable SPI, select "yes"

 

The code for SPI can be found here https://github.com/ozzmaker/BerryIMU/tree/master/python-BerryIMUv3-SPI

One thought on “Connecting BerryIMUv3 via SPI to a Raspberry Pi”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.