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).
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
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.
Here is the physical wiring
You can enable SPI on the Raspberry Pi using raspi-config
Go into “Interfacing Options”
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”
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:
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):
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?
Looks like you need to calibrate the compass. Look at this guide.
In summary, you need to run calibrateBerryIMU.py to get the max and min values from the compass. You then need to include these in your code
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.