Accelerometer visualization 1

1. Processing with sound

The first challenge was to find code that synched Arduino’s serial outputs with a Processing sketch.
I found some good code and a library that could be uploaded to both programs: Jeff Rowberg’s i2cdev library for Arduino (specifically for the MPU 6050 accelerometer I had), and Kartsen Schmidt’s toxiclib library for Processing. It even came with example code for a visualization!

The Arduino code:

Something I discovered in wiring the Arduino was that the digital I/O pin 2 is also known as the Arduino’s external interrupt #0 pin. This corresponded to the MPU’s ‘INT’ pin.


The Processing code:


Here I made sure to specify the name of the Serial port that will be connected to the sketch. The toxiclib library is in the same folder as the sketch.

Final altered code:


Because the Arduino code’s job is solely to display the Serial Data, I mainly worked in the Processing sketch to create a more substantial visualizer.
Using the Minim library didn’t provide me with enough online support for how the function `getVolume()` works. Instead, I found this example sketch using Processing-sound really helpful! It maps each mouse position to the volume and speed of whatever song is being played.
Because the data coming from the console was somewhat skewed, it was difficult to know what values to map to. From an array that controlled the rotation data, I chose the highest (`teapotPacket[8]`) for volume and lowest (`teapotPacket[2]`) for speed. The volume values I know are much less accurate because those changes are much less severe than the changes in speed when demoing.
The song is Windmills of Your Mind by Dusty Springfield.
Instead of the arrow-bird thing that was created in the sketch, I tried out a library of pre-made 3D shapes that work with both P3D and OPENGL. I chose this Bezier horseshoe because it has an obvious front, back, and ends (red and green). So when rotating, you can tell why things are happening where. I only wish there was a better way to read the data… most of the time it would look like this:

Screen Shot 2016-03-13 at 3.56.59 PM Screen Shot 2016-03-13 at 3.57.36 PM

Leave a Reply

Your email address will not be published. Required fields are marked *