Raspberry Pi IMU

Raspberry Pi Digital Spirit Level

 

In this post we show how to create a Digital Spirit Level using a Raspberry Pi and python.

The code moves that bubbles on the display in relation to the angle read from the IMU.
Parts used in this project;

Any IMU or TFT can be used, however the code would need to be updated to accommodate the different devices. It is best to use a 480×320 TFT as the images are scaled to fit this resolution.

This guide assumes that some basic understanding of an IMU(Accelerometer and Gyroscope)  is already known. And you have one already working with your Raspberry Pi.

If you don’t, we do have some guides which covers this.

BerryIMU Raspberry Pi Gyroscope Accelerometer

 

We have used our existing python code to read the values from the IMU, however we have removed the code related to the magnetometer as it isn’t needed for this project.

Git repository here
The code can be pulled down to your Raspberry Pi with;

pi@raspberrypi ~ $ git clone http://github.com/mwilliams03/BerryIMU.git

 

Placement of IMU

The IMU can be attached anywhere, however it is best to place it in the same orientation as shown below. If you do change the orientation, you will need to update the code accordingly.

spiritLevel1-600

Continue reading

BerryIMU Python Code Update – Kalman Filter and More

We have updated to the python code in our git repo.

It now includes;

  • The elusive Kalman filter.
  • Math needed when the IMU is upside down
  • Automatically calculate loop period.
  • A lot more comments.

What is a Kalman filter?  In a nutshell;
A Kalman filter is, it is an algorithm which uses a series of measurements observed over time, in this context an accelerometer and a gyroscope. These measurements will contain noise that will contribute to the error of the measurement. The Kalman filter will then try to estimate the state of the system, based on the current and previous states, that tend to be more precise that than the measurements alone.

A Kalman filter is more precise than a Complementary filter. This can be seen in the image below, which is the output of a complementary filter (CFangleX) and a Kalman filter (kalmanX) from the X axis plotted in a graph.

The red line (KalmanX) is better at filtering out noisep;

Python Kalman filter Raspberry Pi

 

The code can be found here in our Git repository here
And  can be pulled down to your Raspberry Pi with;

pi@raspberrypi ~ $ git clone https://github.com/mwilliams03/BerryIMU.git

BerryIMU Raspberry Pi Gyroscope Accelerometer

A summary of the code;


def kalmanFilterY ( accAngle, gyroRate, DT):
        y=0.0
        S=0.0

        global KFangleY
        global Q_angle
        global Q_gyro
        global y_bias
        global XP_00
        global XP_01
        global XP_10
        global XP_11
        global YP_00
        global YP_01
        global YP_10
        global YP_11

        KFangleY = KFangleY + DT * (gyroRate - y_bias)

        YP_00 = YP_00 + ( - DT * (YP_10 + YP_01) + Q_angle * DT )
        YP_01 = YP_01 + ( - DT * YP_11 )
        YP_10 = YP_10 + ( - DT * YP_11 )
        YP_11 = YP_11 + ( + Q_gyro * DT )

        y = accAngle - KFangleY
        S = YP_00 + R_angle
        K_0 = YP_00 / S
        K_1 = YP_10 / S

        KFangleY = KFangleY + ( K_0 * y )
        y_bias = y_bias + ( K_1 * y )

        YP_00 = YP_00 - ( K_0 * YP_00 )
        YP_01 = YP_01 - ( K_0 * YP_01 )
        YP_10 = YP_10 - ( K_1 * YP_00 )
        YP_11 = YP_11 - ( K_1 * YP_01 )

        return KFangleY

Raspberry Pi Arduino ATmega

How to Program an AVR/Arduino using the Raspberry Pi GPIO

In this tutorial I am going to show you how to program an AVR(ATmega328) and an Arduino UNO using the GPIO on the Raspberry Pi.

Adding an Arduino or an AVR to your projects will give you much greater flexibility.

 

Hook up the Raspberry Pi to the Arduino UNO or AVR.

 

The image below shows how to connect a Raspberry Pi 2 and an  Arduino UNO. click the image to make it larger

 

Raspberry Pi and Arduino

Continue reading

LED Cube Raspberry Pi

New Kickstarter – VoxCube – 8x8x8 RGB LED Cube for the Raspberry Pi

We have been busy over the last 6 months creating something special!
We have always liked the idea of LED cubes, however there was no easy way to drive these LED cubes with a Raspberry Pi…. until now.

 


VoxCube is an 8x8x8 RGB LED Cube which has been specifically designed for the Raspberry Pi, however it is also compatible with other microcontrollers. E.g. Arduino

Cubes can also be chained together, the image below is four VoxCubes being controller via a Raspberry Pi.

Four VoxCube Raspberry Pi LED

 

Head over to the Kickstarter page for more details.

Kickstarter LED cube

 

 

Blip, blop, bloop…