In this article, you'll learn how to generate music through an accelerometer and an MPU6050 gyroscope (also referred to as a "gyro sensor"), using the Wekinator open-source software platform to enable machine learning techniques.
The first step of this project is to interface the MPU6050 sensor with an Arduino, which will send the output data to processing.
In processing, we'll calculate the YPR (yaw, pitch, roll) values and draw a 3D model that mimics the movement of the sensor then sends the values to the Wekinator. Finally, the output data is sent to a drum machine made in processing that produces music.
Directions to connect the MPU6050 gyroscope to an Arduino.
On the input side, the sensor will need to be connected to the Arduino. The directions for doing so are shown in the figure below.
Installing the Arduino Libraries
To properly interface the Arduino with the sensor, first download the Arduino library developed for that purpose. You'll also require the I2C library, which you can access through this file folder.
Next, unzip the contents of the file, open the folder titled, "Arduino" and move the I2C and MPU6050 sensor folder to the Arduino library folder.
Example indicating the selected locations of the I2C dev and MPU6050 folders.
Uploading the Code
Start by launching the Arduino IDE software. Navigate to examples under 'File', then MPU6050 and open the MPU6050_DMP6 file.
Example demonstrating how to navigate to MPU6050_DMP6 file in Arduino IDE.
Upload the code found in the Arduino IDE and it should display on the serial monitor.
If it's showing the output data, then you can assume the sensor has successfully interfaced with the Arduino.
Output data displayed in a window confirming the MPU605 sensor has successfully connected interfaced with the Arduino.
To send the data to processing, some changes need to be made to the code.
First, select the line 117 of the code and uncomment it, move up to line 100 and comment that segment of code. If you have trouble with this step, reference the figure below.
An example underlining the lines of code that need to be changed.
If you upload the code again, it will display unreadable characters on the serial monitor.
An example of unreadable character code on the serial monitor window.