3 Axis Accelerometer and 3 Axis Gyroscope With Raspberry Pi
by austinhander in Circuits > Raspberry Pi
20 Views, 0 Favorites, 0 Comments
3 Axis Accelerometer and 3 Axis Gyroscope With Raspberry Pi

This project involves using a Raspberry Pi, connecting it to a 6-axis accelerometer, and sending the data to a MySQL server. The device can be activated with a button and has an RGB LED indicating the state of the device. This is useful as a motion data logger. The design contains a Voltage converter so it can be connected to a 24V DC power source often found in industrial motion systems.
Supplies
Raspberry Pi: $90
RGB LED Module: $10
Push button: $7
Breakout board for Raspberry Pi: $12
Wires: $7
3D Printer filament (for case): $14
M3 screws: $9
24V to 5VDC step down converter: $10
MicroSD card: $11
Total Cost: $190
Connect Components

All of the electrical components need to be connected based on how the diagram describes in order for the code to work properly. If the IO pins are changed, the variables for those pins must be updated in order for it to work properly. A Raspberry Pi breakout board was used along with jumper wires in order to make the connections easier to understand and create. The MPU6050 needs to be connected to SCL, SCA, ground, and 5V. The RGB LED module needs to be connected to 3 IO pins (in this case, 14, 15, and 18), and ground. The button needs to be connected to an IO pin (in this case, it was connected to IO pin 16), and ground.
Create Database
In order for the data to be stored, there first needs to be a database to store it. This database is going to run on the Raspberry Pi itself. Raspberry Pi's do not have the ability to use MySQL, so MariaDB is used instead. I have attached a tutorial to install MariaDB. The video by Coding with Ashwin can be found here.
Programming
The purpose of this device is to start recording gyroscope/accelerometer data when a button is pressed, and then end when it is pressed again. Every time the button is newly pressed, the LED changes color based on whether it is writing data or not, and it creates a data point in a MySQL table, then logs the gyroscope/accelerometer data in a second table, with a value associated with the point in the first table. The program uses a state machine to do this. First, it detects when the button is pressed and changes the state of a variable representing its data sending mode and idle mode. When it is first activated, it goes into the first state "WriteFirst", where it puts the cycle number in the first column. After that, it loops through the second and third states, where it continuously writes the data to the second table every 50 milliseconds. The loop stops when the button is pressed again. The program is attached. In order for the program to work correctly, some dependencies need to be installed, including MySQLdb, which allows you to interface with a MySQL or MariaDB server.
Downloads
Design Case
In order to house all the components, I designed a case for all of the components. The components all screw in using M3 hardware, and the wires are all housed within the case. There is a hole in the lid where the LED can fit, which is flush with the surface of the lid. There are also holes for where the button can fit, and where the serial connections can be accessed on the Raspberry Pi. Lastly, there is a marker on the lid for which direction the case should be oriented. The design is attached below.
Assemble Components


Once the case is 3D printed, screw the Raspberry Pi into the bottom holder, and use double sided tape to attach the power converter, MPU6050, and LED module to the base. Use an M3 tap to tap on the holes in the base, and drill out holes in the top to screw in. Use M3 screws to screw into the base.
Final Product


This is an example of data collected using this device. In this case, pivot motion was controlled by a servo motor, and a pneumatically powered pivot motor. The data show the servo motor offers greater motion profile capability compared to that of an air powered motor.