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

3 thoughts on “Connecting BerryIMUv3 via SPI to a Raspberry Pi”

  1. Hi. Thanks for the instructions!
    I set up the Pi/BerryIMU via SPI as shown in this guide.

    I then got the gyro data using this guide:
    https://github.com/ozzmaker/BerryIMU/tree/1bc94c3f51c2e4d8fecb13ab68799f7f998ffd7b/python-BerryIMU-gyro-accel-compass

    Since it did not contain instructions to get the magnetometer data, I copied the magnetometer parts of this code to get the magnetometer as well (I couldn’t use this code entirely because it wasn’t made for SPI):
    https://github.com/ozzmaker/BerryIMU/blob/1bc94c3f51c2e4d8fecb13ab68799f7f998ffd7b/python-BerryIMU-gyro-accel-compass/IMU.py

    I got all the readings in the terminal, however the ‘heading’ values only change less than 10 degrees, even when I turn the IMU a half turn. Can you help with this, please?

  2. Suggestion:
    Would you consider building a BerryGPS IMU Vxx with this device: MS5525DSO, instead of the current baro sensor?
    This would allow one to securely attach pitot and static system hoses, allowing airspeed to be calculated.
    Another useful feature would be the ability to have remote (outside) air temperature sensing ( NTC ) would probably be best.

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.