Final Project: Simplinstrument, by Daniel Chin

Instructor: Marcela 
Group Partner: Tristan 
 
Here you will learn about Simplinstrument, our group’s final project for Interaction Lab SP19
 
You control the electronic musical instrument by moving your hand while blowing into a mouthpiece. 

 
 

Design 


Music instruments are difficult. 
 
Piano is difficult. 
Flute is difficult. 
Saxophone is difficult. 
French horn is difficult. 
Violin is difficult. 
 
However, whistle is easy. 
a coach whistle 
The harder you blow, the louder it will sound. Simple and intuitive. 
 
In the same way, you control the Dynamics level (loudness) of Simplinstrument by blowing in to a mouthpiece. 
A box enclosing BMP085 
In the mouthpiece is an air pressure sensor, BMP085. The harder you blow, the higher the air pressure in the mouthpiece will be. 
 
You control the pitch by rotating you hand up and down. The ring on your finger contains a gyroscope, MPU6050. It senses the angular acceleration of your finger to calculate the absolute orientation of your hand. 
 
Simplinstrument is meant for musicians and non-musicians. The goal is for musicians to find it usable and expressive, and for non-musicians to play music without any training. 
 

Scaffolding Mode 


Simplinstrument offer two modes: Expert Mode and Scaffolding Mode. 
 
In Expert Mode, you have access to all white keys (diatonic). 
We tried making all keys available (chromatic), but that turned Simplinstrument into a difficult instrument. So we removed the black keys. 
Only providing the pentatonic scale, however, is not “expert” enough for Expert Mode. 
So we settled with all white keys. 
 
Scaffolding Mode is especially nice. 
A background music plays, whose chord progression is Am-F-C-G. You have access to all pitches within the chord that’s currently playing in the background. In other words, no matter what you do, you always make harmonies. 
 
The Scaffolding Mode turned out to sound way better than we envisioned. Random hand movements created melodies that sounded highly professional. 

 
 

User Feedbacks 


“Make sure the texture of the sound is beautiful” 

Indeed! Texture matters. We chose a synthesizer from Spitfire Audio Labs. It’s free; but it’s awesome. 
 

“Which way does this ring go onto my finger?” 

Good question. It matters because otherwise the gyroscope would give flipped readings. We cleared the confusion by adding a Ring Platform. 
hand take ring off from the platform 
 

“Remove the visual interface” 

At first we had a visual interface to help musicians pinpoint their hand orientation to their desired pitch. It didn’t quite work out. 
Sheldon playing the instrument 
 
Marcela suggested we remove the visual and blindfold the player. That’s exactly what we did. 

 
 

“My hand can’t bend that low” 

We changed the finger orientation input range from (-.5, .3) to (-.3, .3) 
 

“Why not have multi player symphony?” 

That can be achieved by making two copies of Simplinstrument
 

“Allow other body parts to also control the music” 

This is actually what I really want to have in the project. It is only not implemented because of time constrain. 
 

“Add a tutorial” 

No. We should keep things simple and let the player explorer on their own. 
 

Problems and how we solved them 


MPU6050 didn’t work! 

We asked Nick. Nick told us to solder the PINs. It worked. 
I guess one does not simply plug jumper cables into breakout board PINs. 
Photo of breakout board with PINs 
 

The gyroscope outputs angular acceleration, but we need absolute orientation! 

I tried to write an algorithm to integrate the acceleration into orientation. A lot of Linear Algebra: 
Draft paper with math 
 
And I wrote this code: Github link 
 
It worked! 
Processing showing a motion tracking 3D model 
I optimized the code for performance. In the end, one loop on Arduino Uno takes 2 milliseconds. 
code snippet of profiling 
 
However, any sudden movement of the gyroscope would make the algorithm accumulate error. Damn… The time step was still too large. 
Looks like we had to rely on the DMP!!! 
 
DMP refers to the Digital Motion Processor mounted on MPU6050. DMP does fast calculations and outputs the absolute orientation of the chip. Now you ask: “Isn’t that exactly what you need? Why do all the Linear Algebra yourself when you can use DMP?” To answer that, let me quote Arduino Playground: “For this DMP, InvenSense has a discouragement policy, by not supplying enough information how to program the DMP. However, some have used reverse engineering to capture firmware.” 
That is pretty scary! The last thing a programmer wants is the lack of documentation. This is why DMP was my last resort. 
 
However, simplinstrument needs a robust input. So I tried working with DMP. Fortunately, Electronic Cats wrote a very helpful library. It worked the first time I tried. The DMP handles sudden movements pretty perfectly. 
 
The output of DMP is in Quaternion. I tried to learn it, but it was too much. I ended up eyeball the four scalers and simply decided to use quat.y
 

Every now and then, NaN takes over! 

This was a fun one. 
code snippet of NaN checking 
It took me a long time to fix, because I assumed there was a 0/0. After thorough debugging, the problem became clear: 
 
acos(1.0000000001) = NaN! 
 
My mind was blown. I marveled over the difference between doing Math on CPU and doing math on paper. 
 
Once known, the problem was easy to fix – A call to constrain(x, 0, 1)
 

Technical details that are fun to read 


Plot my exhale 

Serial plotter shows readings 
Air pressure connected to Arduino serial plotter 
 

826 and 1608 are 300 Pa apart 

The air pressure sensor seemed to frequently require recalibrating… We thought we bought a trashy sensor, until we suddenly realized that the Studio and the dorm room are 8 floors different in altitude and hence we should expect a 300 Pa difference every time we test the device in a different location. 
 

GUI = API: automated mouse clicks in Ableton 

As mentioned earlier, we used Spitfire Audio Labs to synthesize sound. 
 
The top choice would be to work directly with VST files from Spitfire, but I have no idea how to do that. 
Therefore, we let Ableton deal with Spitfire for us. In Ableton Live, you can import Spitfire Audio Labs as an instrument. 
screenshot of ableton spitfire plugin 
 
Okay! Let’s use something like “Ableton API” to control Ableton then! Unfortunately, my research yielded no result. 
 
At that moment, I was reminded of a project of Tom Scott’s. Why not use macro/bot to simulate mouse clicks and key presses to control Ableton? 
 
And there we have it. I wrote a Python script to use mouse and keyboard to control Ableton GUI. The Python script receives commands from Processing via a TCP socket. Ha! I just pwned my own laptop! Let’s add a firewall to prevent strangers from hijacking my Python script. 
 
Just like this, Ableton became our real-time sound synthesizer, at least for the 22 remaining days of the free trial. 
 

Teach Processing music theory 

Code snippet that defines chords 
 

I2C infinite wait 

Once in a while, our program froze. 
 
Investigation showed it was Arduino that stopped. 
 
Further investigation showed that whenever an MPU6050 library function was called, there was a slight chance of no return, blocking the Arduino code execution. 
 
Both the air pressure sensor and the gyroscope use I2C communication protocol with Arduino. Looking into the MPU6050 library code, I found out that they did not enable timeout when they receive bytes from the sensor via I2C. 
I2CDev provides a timeout argument 
But mpu library supply no timeout argument 
I suspect this is the problem. When a bit is missing, Arduino would wait for the 8th bit but the sensor would never send anything, manifesting an infinite wait. 
 
The only real solution would be to rewrite the library, which I don’t want to do. Instead, I just improved cable connection and minimized the number of calls to the library. The less you call, the less probable Arduino will freeze. Yes, sometimes avoiding the problem is the solution. 
 

Note on & note off for ADSR 

Previously, we didn’t have note on and note off. When you don’t blow, a key is pressed down with dynamics = 0. However, that implementation resulted in a less expressive sound texture. 
 
We added a threshold of air pressure that triggers note on and note off. Now, the pre-programmed ADSR (Attack Decay Sustain Release) of Spitfire Audio can finally be heard. 
 

Gyroscope calibration, the Earth, and the Ring Platform 

A fun thing you will notice if you have a gyroscope: the reading is non-zero even when the gyroscope sits still! 
I thought, this could be the rotation of the Earth! But it isn’t. The numbers don’t add up. 
 
It turned out gyroscopes require calibration. You basically offset the X Y Z angular acceleration reading by a constant value. It’s not hard to do: you just let it sit still and take its reading to be the offset. 
 
Our MPU6050 needed frequent recalibrating. Another reason we made the Ring Platform (mentioned above) is for easy recalibrating: we recalibrating it before the player takes the ring from the platform. 
hand take ring off from the platform 
 

Synchronize BGM 

Our BGM for Scaffolding Mode is downloaded from YouTube. After analyzing it in Audacity, we discovered there are 3.20000 seconds in a measure. Our Processing sketch basically synchronize with the BGM via this code
 
“LOOKUP tables make things especially easy.” – line 26 in bgm.pde 
 

Sustain 

Tristan noticed that the notes cut off too suddenly! So we added Python-level sustain. Now, breathing does not interrupt your music. 
 
See line 35 & 67 in py.py 
 

Humans using Simplinstrument 


My original imagination of using simplinstrument
Me waving hands 
 
How people actually use simplinstrument
Ki playing the instrument 
 
Rudi playing the instrument 
 

Conclusion 


You interact with simplinstrument by letting it help you make music, hear the music you make, and show to people. It does not directly echo with my definition of interaction (giving and receiving attention). It is not emotional or artistic; just a tool for artistic expression. 
 
If there was more time, we would like to make everything wearable and wireless. 
 
It feels amazing when your flute respond to your breath. We started out wanting to make the experience of playing the flute more accessible. I think the result is satisfying. If we can enable more people to express more in music, it’s worth it. 
 

Make your Simplinstrument 


Buy these: 

Arduino Uno 
MPU6050 
BMP085 
 

Make these: 

A box to enclose BMP085. Leave two holes for air to come in and go out. 
 
A ring to fix MPU6050 on. Preferably Velcro, for different finger sizes. 
Design of the ring 
 

Download these 

Arduino, Processing, and Python
Ableton Live, Spitfire Audio LABS: Strings. 
 

Wiring 

Connect BMP 085 to Arduino: VIN/VCC – 5V; GND – GND; SCL – A5; SDA – A4 
 
Connect MPU6050 to Arduino: VIN/VCC – 5V; GND – GND; SCL – A5; SDA – A4; AD0 – GND; INT – 2 
 

Code 

Download code from my Github. All code is in the “final_project” folder. 
 
You may need to change the TRUSTED_IP list in py/network.py 
 
py/ is the project Python code. 
ardu/ is the project Arduino code. 
proc/ is the project Processing code. 
MPU6050_calibrate/ is for calibrating the gyroscope. It outputs the offset. 
 
The above is all you need. The below is not important. 
 
BMP085test/ is for testing the air pressure sensor. 
gyro_math/ is my attempt of tracking motion. 
MPU6050_full_rotation/ is nonsense. 
MPU6050_test/ is for testing the gyroscope. 
QuaternionConjugateTest/ is the code I used to see if “conjugate” meant what I imagined. 
STLs/MouthPieceAdaptor.stl is a 3d-printable mouthpiece. 
 

Get Help 

Contact Daniel Chin at nq285@nyu.edu 
 

And… 


Tristan and I would like to appreciate all who supported. 
 
Thanks to Rudi for lending us the MPU6050. 
 
Thanks to all user testers and all feedbacks. 
 
Thanks to Nick, Tristan, and Leon for the suggestions. 
 
Thanks to Marcela for the project guidance and all the lectures. 
 
All gifs are hosted on Giphy. Those with people’s faces are set as private CORS. 

Recitation 9: Final Project Process, by Daniel Chin

Instructor: Marcele 
 
This is a write up for Interaction Lab SP18 Recitation on Final Project Process on Apr 26, 2019. 
 

My groupmates’ projects 


Plastic recycling game 

This is a game about recycling plastic bottle lids. The Earth will be depicted in Processing. A physical model of the Earth will be manufactured and connected to a motor. The player score by aiming plastic lids and throw them into three rings. As the player scores, the Earth rotates. The player wins when one full rotation is achieved. 
 
One of the suggestions we gave was to make the full rotation easier to achieve. Initially the creator decided he was going to have three rings of 1 point, 2 points, and 5 points, and the full rotation be 360 points. That was at least 72 throws. Too many. We recommended to make it 30 points total. He agreed. 
 
It shows that interactive experience has the potential to change people’s habits. If this installation is generalized, then more people would develop the habit of recycling. It is interesting because in this sense interactive physical computing can be deployed for public goods. 
 

Guess this picture 

This game involves three players. As the image displayed on a screen gets more and more clear, the players compete to see who will be the first to guess the content of the picture. The content could be a person, an object, or anything physical or abstract. 
 
I think it is a good game for ice-breaking and bonding. If it is on End of Semester Show, it will be popular. As you compete with other players, you can gain an understanding of what they are familiar with. The technologies this project requires are also interesting. Mastering visual computing is essential for the creators to make the guessing process fun and dynamic. 
 

Multi modal musical experience 

Inspired by other artists, this creator wants to combine music and light to manifest an immersive musical experience for the user. The sound and the graphics will be dynamically generated, so every try will yield a different experience. 
 
We reminded the designer to focus on the overall aesthetic of the project. I think it will be an enjoyable project that makes people reflect on what real-time artistic computing is like. 
 

Interaction 


We did not specifically discuss what interaction was, but basing on our project designs, it was clear that we understood interaction in different ways. Although the general ideas apply, but we focused on different aspects. Some wanted to make a fun game, and others wanted artistic expression or experience. 
 

Feedbacks I got 


I got feedbacks from the group and Rudi. 
 
First, the sound quality has to be good. This is true. I will look for a good sound library and learn to synthesize sounds dynamically. 
 
Second, originally I was thinking about providing ethanol wipers for the users to clean the mouthpiece before they use it. However, an apparently better idea was proposed by them: use disposable changeable plastic mouthpieces! They are 1 kuai each on Taobao, so I gladly adopted this idea. 
 
Finally, Rudi referred me to Aven and Sam’s interactive GuQin project. I will discuss my project with Sam for feedback and advice. 
 
These are high-quality, practical feedbacks that will influence my project. I exchanged feedback with Tristan after the event. 

Recitation 10: Media Controller, by Daniel Chin

Instructor: Marcele 
 
This is a write up for Interaction Lab SP18 Recitation on Nick’s Birthday on Apr 28, 2019. 
 

Heat-sensitive webcam 


 
The webcam image turns red when heated up, and turns blue when cooled down. 
 

Source code 


Arduino code and Processing code on my Github. 
 
You can see I wrote a signal-smoothing feature in loop(). The mode of 20 sensor values is sent to Processing every 0.1 second. 
 

Reflection 


The interaction this time is very basic. I am most impressed by my laptop tinting every frame from the webcam in real time. 
 
Inspired by Computer Vision for Artist and Designers, I think using pre-built frameworks to analyze video would be something interesting to do. 

Final Essay, by Daniel

Simplinstrument 简单乐器 
 
Regardless of language and culture, music is many people’s dearest form of art. We use music to express, understand, and remember. 
 
Unfortunately, the experience of expressing yourself with music is locked away for most people. Learning to play an instrument is hard. Many refuse to try. More give up before yielding any results. How can we let more people taste the feelings of musical expression? 
 
Simplinstrument will be a solution that Tristan and I present. Simplinstrument has to be easy to control: A kid with no musical training should find it intuitive to play with. It should also be expressive: the player should have robust control over the pitch, velocity, and modulation. 
 
Our goals are: 

  1. Simplinstrument will be easy to learn;
  2. Simplinstrument will be fun to practice;
  3. With enough practice, you can produce quality music with Simplinstrument.

 
 
The monotonic instrument, Simplinstrument, will consist of a mouthpiece, a pitch glove, and a modulation glove. The mouthpiece will have an airflow pressure sensor to control the velocity. The pitch glove will have a gyroscope for pitch input. The modulation glove will have an accelerometer who readings will be Fourier Transformed into modulation parameters. The audio synth will mainly take place in Python, which will connect to Processing with localhost sockets. 
We will first try to make the mouthpiece, because I think the most risky implementation in this project is the airflow pressure sensor. This should be done before May 3rd. 
Everything else is not too much work. 
 
My preparatory research gave me a list of ideas for the final project, and Simplinstrument is only one of them. Being expressive in nature, Simplinstrument promotes interaction between multiple humans by unlocking their musical ability to express themselves and understand others. 
 
Simplinstrument is actually one of my dream instruments. (My first dream instrument is brainwave2audio.) It will be valuable to whoever find it fit to their musical expression. Simplinstrument is inspired by the Theremin and the REMI. The design of the airflow pressure sensor is 
taken from REMI by M.J. Bauer. We want to make everything simpler.