Institution: Wii Nunchuck Synthesizer

The World of Wii Music:

I distinct to lastly combine my love of music with the little bit of programming experience I let gained over the past few eld. I birth been interested in creating an instrument of my personal ever since I saw a peach by Tod Machover at my schooling. If you're unfamiliar with his bring give him a Google, as he has been pushing the boundaries of music, technology, as well as their intersect for a number of years instantly (Massachusetts Institute of Technology media labs, Shake Band, Guitar Hero etc. . .).

I have connected my Nunchuck to an Arduino Uno running happening the Mozzi heavy synthesis library attributable the well-documented use of both online. For ease, I am victimization a WiiChuck breadboard adapter which plugs right into the Arduino. This comparatively simple send off plays a series of pitches contingent the Pitch (YZ-Plane) measured from the Nunchuck's accelerometer. The joystick's Y value is mapped to the gain to make the pitch louder or softer. It also changes chords depending on the Z-Button and turns happening a form intonation envelope when the C-Push is ironed. The envelope's relative frequency is then modified with the Roll measured from the Nunchuck (moving-picture show turning a knob).

Resources:

  • 1 x Arduino Uno
  • 1 x Wii Nunchuck
  • 1 x WiiChuck Adapter
  • 1 x breadboard mixable 3.5mm female two-channel jack
  • 1 x 3.5mm audio cable
  • 1 x speaker of some sort (You can plug in a buzzer at first to test it out
  • 4-5 Wires of various colours

Nonmandatory but advisable:

  • 1 x 330 Ohm resistor
  • 1 x .1 uF capacitor

Step 1: Plugging in Your NunChuck

Copy/Spread the WiiChuck class from Arduino Playground. We will need the version with the declaration of Pressurized water reactor and GND pins. Economize it as WiiChuck.h and keep it in the same directory as your see.

Now replicate/spread the pursuing into Arduino IDE and upload it.

<p>#let in "Wire.h"<br>//#include "WiiChuckClass.h" //almost likely its WiiChuck.h for the reside of US. #include "WiiChuck.h" WiiChuck sick = WiiChuck();</p><p>void frame-up() {   //nunchuck_init();   Serial.begin(115200);   chuck.start();   chuck.update();   //sick.calibrateJoy(); }</p><p>void curl() {   delay(20);   chuck.update(); </p><p>  Serial.impress(spue.readPitch());     Serial.print(", ");     Serial.print(chuck.readRoll());     Successive.print(",  ");  </p><p>  Serial.print(chuck.readJoyX());     Serial.print(", ");     Serial.print(chuck.readJoyY());     Successive.print(", ");  </p><p>  if (chuck.buttonZ) {      Asynchronous.print("Z");   } else  {      Ordering.print("-");   }</p><p>    Serial.print(", ");  </p><p>//not a function//  if (chuck.buttonC()) {   if (grub.buttonC) {      Serial.print("C");   } else  {      Serial.print("-");   }</p><p>    Serial.println();</p><p>}</p>

Disconnect your Arduino from power and connect your WiiChuck adapter to Analog Pins 2-5 on your Arduino.

Connect to power once again and ensure that the Nunchuck's values are being sent to your Arduino and being printed to the Serial Varan. If you are not sightedness whatever change in the numbers make sure you're connections are honorable, and you're Nunchuck is functioning. I dog-tired a few days trying to fix software in front realizing my Nunchuck's wire was internally broken!

Next, we will hook everything up to Mozzi . . .

Step 2: Getting to Know Mozzi

First, you testament need to download the latest version of Mozzi. They are fueled past donations so donate if you feel sol inclined and download the program library. You can add it to your libraries easy by choosing Sketch > Libraries > Minimal brain dysfunction .Hurry Library... from Arduino IDE.

Straightaway we will touch base the 3.5mm earpiece jack to the bread board and Arduino so we can easily tie in to it later o (you can unplug the Nunchuck and adaptor for now).

  1. Plug in your Jack to the bottom rightfield nook of the board to hold room for the rest. The jack should be 5 pins wide.
  2. Connect the mid row to ground with a jumper wire.
  3. Connect the top row of the jack to an empty row to a higher place (Row 10 in the picture). This is the telegraph carrying the audio signal.
  4. Colligate Digital Immobilise ~9 to row 10 as well.

  5. Connect Ground on your Arduino to the ground rail on the breadboard.

  6. You don't necessarily postulate to use the resistor and capacitor yet merely you may notice a peaky pitched oink if you fare not. Information technology Acts of the Apostles as a low fleet filter to eradicate frequencies above ~ 15 kHz.

Unconcealed Mozzi's Sinewave vignette in Arduino IDE aside choosing File > Examples > Mozzi > Fundamentals > Sinewave. This is essentially Mozzi's equivalent of "Hullo World".

Upload the sketch and connect a speaker to the bread board. You hindquarters use a buzzer besides if you haven't wired the bread board to the audio jack yet.

If you don't hear a constant A4 (440Hz) coming from your speaker ensure completely your connections are good and try again.

Next, we volition colligate the Nunchuck to the Arduino!

Step 3: Putting It All at once

Now we are passing to use the roll value from the Nunchuck to change the frequence of a Sinewave.

  • From Arduino IDE Choose Indian file > Examples > Mozzi > Sensors > Piezo Frequency

We will need to add u a few lines to this cipher in consecrate to get it to work with the Nunchuck. Add an include to the WiiChuck depository library and instantiate a WiiChuck physical object called spue. You can also comment away the declaration of PIEZO_PIN or merely delete IT as we won't be using it.

#include "WiiChuck.H"  WiiChuck chuck = WiiChuck();  //const int PIEZO_PIN = 3;  // sic the analog input pin for the piezo

Now in apparatus, we will need to tote up the following:

chuck.begin();<br>spew.update();

and finally we will need to change a hardly a things in updateControl():

<p>void updateControl(){</p><p>  chuck.update(); // get latest nunchuck information <br>  // read the piezo   //int piezo_value = mozziAnalogRead(PIEZO_PIN); // valuate is 0-1023   int piezo_value = map(  </p>

Comment out the line that sets piezo_value and add the next underneath:

void updateControl(){<br>  chuck.update(); // get latest nunchuck data    // translate the piezo   //int piezo_value = mozziAnalogRead(PIEZO_PIN); // value is 0-1023   // We get into't need the line higher up but why not map the gyre to the same range?   int piezo_value = map(chuck.readRoll(), -180, 180, 0 1023);            

Upload the code and the frequency should correspond to your Nunchuck's Bun. Try mapping it to dissimilar absolute frequency ranges. If you seaport't detected further below in the sketch the rate from the sensor is multiplied past 3 so we are currently performin tones from 0 Hz to most 3000 Cycle per second.

Step 4: Final Touches

Straight off you are ready to upload the terminal interpretation of the code which I possess pieced together from the previous step and a some more than of Mozzi's examples (Phase_Mod_Envelope, and Control_Gain to make up exact). To make my life easier I also enclosed a file called pitches.h which merely defines absolute frequency values with familiar note names (i.e. NOTE_A4).

I suggest reading the Mozzi documentation as much of the code is straight from the examples except for the inscribe for the Nunchuck.

Here is a link to my Git repository. All large files are enclosed except for the Mozzi library which you should get from their website so information technology's adequate to escort. Download WiiMusic.ino and upload it to your device to hear what it sounds like. I propose you play approximately with the parameters I am changing (change the map ranges, divide/multiply numbers, etc. . .) As that is how I saved the fastidious sound I was looking for.

Reflection

I preceptor't feel like I am quite a finished. That's not to say I'm non contented with the project or the legal IT makes, but I feel like I just dipped my toes into a new world that I want to keep exploring so I will add a new arm from this project as I continue to forg.

Quiet, that being said this was my first true journey into the world of microcontrollers so I am very grateful for the learning experience. The twenty or so hours I spent working on it gave me Christmas ideas for myself and practically every member of my family. I somewhat regret not working on this fancy with someone other as I could have used plenty of advice and guidance along the way. However, I personally learned a great deal through with my trials including three days of pulling my hairsbreadth unstylish trying to debug a software problem that was ne'er on that point (an internal wire in the Nunchuck had broken-field).

Thither are still a enumerate of possibilities moving forward. For example, I would love to apply the Arduino as a type of MIDI interface in 'tween a MIDI controller and the headphone out to change parameters of the MIDI mark as at that place are and then many to choose from (volume, cutoff, envelope frequency, pitch bend, modulation, vibrato, you name it). This would allow for a lot more flexibility including shift parameters with the buttons, and simply playing a chord that isn't hardcoded into a C++ lay out.

Be the First to Share

Recommendations

  • Anything Goes Contest 2022

    Anything Goes Contest 2022