Tag Archives: accelerometer

Python Code for BerryIMU – Accelerometer, Gyroscope, Magnetometer & Pressure Sensor

We have updated our git repository with python code for the BerryIMU.

This is specific for the BerryIMU, however the math and code can be applied to any digital IMU, just some minor modifications need to be made. E.g  Pololu MinIMU, Adafruit IMU and Sparkfun IMUs

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

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

 

We have left the code as simple as it can be to make it easier to understand.

The code currently performs angle measurements using the gyroscope and accelerometer , which are fused using a complementary filter. The heading is also calculated using the magnetometer, without tilt compensation.
BerryIMU Raspberry Pi Gyroscope Accelerometer
To view pressure;

pi@raspberrypi ~ $ sudo python berryIMU.py

To view pressure;

pi@raspberrypi ~ $ sudo python bmp180.py

Detailed Guides and Tutorials

In this order;
Guide to interfacing a Gyro and Accelerometer with a Raspberry Pi – Kalman Filter
Create a Digital Compass with the Raspberry Pi – Part 1 – “The Basics”
Create a Digital Compass with the Raspberry Pi – Part 2 – “Tilt Compensation”
Create a Digital Compass with the Raspberry Pi – Part 3 – “Calibration”
Create a Digital Compass with the Raspberry Pi – Part 4- “Smartphone Replica”
Converting values from an Accelerometer to Gs – “ Proper Acceleration”

How to Create an Inclinometer using a Raspberry Pi and an IMU
Raspberry Pi Digital Spirit Level

[wp_ad_camp_4]

Guide to interfacing a Gyro and Accelerometer with a Raspberry Pi

This guide covers how to use an Inertial Measurement Unit (IMU) with a Raspberry Pi . This is an updated guide and improves on the old one found here.

I will explain how to get readings from the IMU and convert these raw readings into usable angles. I will also show how to read some of the information in the datasheets for these devices.

This guide focuses on the BerryIMU. However, the theory and principals below can be applied to any digital IMU, just some minor modifications need to be made.

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

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

 

The code for this guide can be found under the gyro_accelerometer_tutorial01_angles directory.

A note about Gyros and Accelerometers

When using the IMU to calculate angles, readings from both the gyro and accelerometer are needed which are then combined. This is because using either on their own will result in inaccurate readings. And a special note about yaw.

Gyros – A gyro measures the rate of rotation, which has to be tracked over time to calculate the current angle. This tracking causes the gyro to drift. However, gyros are good at measuring quick sharp movements.

Accelerometers – Accelerometers are used to sense both static (e.g. gravity) and dynamic (e.g. sudden starts/stops) acceleration. They don’t need to be tracked like a gyro and can measure the current angle at any given time. Accelerometers however are very noisy and are only useful for tracking angles over a long period of time.

Accelerometers cannot measure yaw.   To explain it simply, yaw is when the accelerometer is on a flat level surface and it is rotated clockwise or anticlockwise.  As the Z-Axis readings will not change, we cannot measure yaw.   A gyro and a magnetometer can help you measure yaw. This will be covered in a future guide.

Here is an excellent tutorial about accelerometers and gyros.

Setting up the IMU and I2C

The IMU used for this guide  is a BerryIMUv3  which uses a LSM6DSL,
that consists of a 3-axis gyroscope plus a 3-axis accelerometer and a LIS3MDL which is a 3-axis magnetometer.

  • LSM6DSL – Accelerometer and gyroscope datasheet can be found here.
  • LIS3MDL – Magnetometer datasheet can be found here

 

This IMU communicates via the I2C interface.

The image below shows how to connect the BerryIMU to a Raspberry Pi

BerryIMUv3 and Raspberry Pi I2C hook up

 

The BerryIMUv3 can also be connected using the Raspberry Pi QWIIC connector and cable;

QWIIC connector Raspberry Pi
QWIIC connector for the Raspberry Pi

 

Continue reading Guide to interfacing a Gyro and Accelerometer with a Raspberry Pi

New Kickstarter Launched – BerryIMU

An accelerometer, gyroscope and magnetometer which is specifically designed for the Raspberry Pi.

 

What is it?

BerryIMU is an inertial measurement unit, or IMU, that measures and reports on velocity, orientation and gravitational forces, using a combination of an accelerometer, gyroscope and a magnetometer.

IMUs can be found in devices like, quad copters, smart phones, segways, Wii Remote etc.. and are used to sense movement and orientation.

BerryIMU for the raspberry pi

Adding BerryIMU to your Pi will open up a whole new world of possibilities.

BerryIMU is specifically designed for the Raspberry Pi and is designed to take some of the complexity out of IMUs and to try and make them more enjoyable to use. BerryIMU includes the latest and greatest sensor ICs.

Head on over to Kickstarter.com to check it out;
https://www.kickstarter.com/projects/2135028730/berryimu-orientation-sensor-for-the-raspberry-pi

PiBBOT V2 – Balancing Robot using a Raspberry Pi

I have spend the last month creating a new version of PiBBOT (Pi Balancing roBOT) , PiBBOT V2.

This version has a sturdier frame and a LCD display. I replaced the 1.8″ TFT with a LCD as the TFT was causing delays in the main loop timing. I also added a very slim battery for the Raspberry Pi.

Main components;

    • RGB backlight LCD 20×4 which shows gyro, accelerometer and complimentary filter angle.
    • Volt Meter to view condition of battery used for motors.
    • RF Receiver RF M4 Receiver – 315MHz. Used to tune PID and then control direction.
    • 1×4 Keypad to turn motors on/off and to reset the gyro.
    • Motors; 9.7:1 Metal Gearmotor 25Dx48L mm with 48 CPR Encoder
    • Wheels; Pololu Wheel 90x10mm
    • IMU; BerryIMU – An accelerometer, gyroscope, magnetometer and barometric/altitude sensor
    • Battery for Motors – 7.2V Tenergy 3800mAh Flat NiMH High Power (38A Drain Rate)
    • Battery for Rasperry Pi – Anker Astro Slim2 4500mAh Ultra-Slim Portable External Battery Charger Power Bank

    Continue reading PiBBOT V2 – Balancing Robot using a Raspberry Pi

    Guide to interfacing a Gyro and Accelerometer with a Raspberry Pi

    A lot of people have asked how I got the readings from the Gyro, Accelerometer, and Compass inertial measurement unit(IMU) which is used to keep PiBBOT upright.

    UPDATED And updated guide has been published here, with cleaner and simpler code.
    BerryIMU Raspberry Pi Gyroscope Accelerometer

    In this guide I will explain how to get readings from the IMU and convert these raw readings into usable angles. I will also show how to read some of the information in the datasheets for these devices. The theory and principals below can be applied to any digital IMU, just some minor modifications need to be made. Eg register values, sensitivity level…

    The code can be found here;
    https://github.com/mwilliams03/Raspberry-Gyro-Acc

    A note about Gyros and Accelerometers

    When using the IMU to calculate angles, readings from both the gyro and accelerometer are needed, which are then combined. This is because using either on their own will result in inaccurate readings.

    Here is why;
    Gyros – A gyro measures the rate of rotation, which has to be tracked over time to calculate the current angle. This tracking causes the gyro to drift. However, gyros are good at measuring quick sharp movements.

    Accelerometers – Accelerometers are used to sense both static (e.g. gravity) and dynamic (e.g. sudden starts/stops) acceleration. They don’t need to be tracked like a gyro and can measure the current angle at any given time. Accelerometers however are very noisy and are only useful for tracking angles over a long period of time.

    Here is an excellent tutorial about accelerometers and gyros;
    http://www.instructables.com/id/Accelerometer-Gyro-Tutorial/?ALLSTEPS

    Setting up the IMU and I2C

    The IMU I use is a MinIMU-9 v2 Gyro, Accelerometer, and Compass which uses a L3GD20 3-axis gyroscope and a LSM303DLHC 3-axis accelerometer and 3-axis magnetometer.
    The datasheets are needed if you want to use these devices;
    L3GD20 datasheet
    LSM303DLHC datasheet

    This IMU communicates via the I2C interface.

    From the images below, you can see how to connect it to the Raspberry Pi. You can also see the orientation of the X, Y and Z axis.

    Temp12 hour GraphGraph

    Continue reading Guide to interfacing a Gyro and Accelerometer with a Raspberry Pi