Thursday, December 17, 2015

Teensy USB Wii Classic Controller




I'm a fan of the Wii Classic Controller, but I've never cared for having to keep wireless controllers charged up for an occasional bout of nostalgia.  Wouldn't it be great if I could use my Wii Classic Controller over USB?  This is how I made it.

I opened up my controller with a tri-wing screwdriver and saw that the accessory port mechanism takes up a lot of interior space.  Once removed, the space looked about right to fit a Teensy LC.



I used an old Samsung phone USB cable like this one that is appropriately white to match the controller.  I split open the micro-B side with an x-acto blade.  After removing the outer plastic casing, the metal shield, and the connector parts, I carefully stripped away a tiny amount of insulation from each of the four wires.  The remaining end of the cable fits nicely through the hole left by the accessory port button.  The rectangular block at the end conveniently keeps the cable from pulling on the soldered wire connections.



Next I removed the controller cable.  The five wires shown below (red, yellow, green, white and black) are connected in a plastic jumper casing.  I unscrewed the circuit board from the controller case and flipped it over to desolder all five wires, removing the whole jumper and leaving just the bare circuit board to connect new wires to.


I connected the Teensy to the Wii controller according to the schematic below.  (The white wires are shown as grey.)  The USB cable has four wires:  black, green, white, and red.  Only four of the five wires from the Wii controller are necessary:  white, red, yellow, and green.  (The black wire is left open.)  As recommended I used 4.7K pull-up resistors for the I2C pins.

I threaded the USB cable thru the top of the controller case (thru the accessory port button hole).  I soldered the four USB wires to the side of the Teensy not seen in the picture below.  I soldered the resistors flush to the Teensy board and connected carefully measured wires to reach from the Wii controller port to the designated Teensy pins.

Note that I used a black wire instead of a white wire for the ground connection, but it connects to the Wii controller circuit board where I detached the white wire from.  If I were to do it again I would use thinner wires and/or remove some of the plastic between the analog joysticks to run the wires so that they could be more easily placed out of the way of the right trigger mechanism.  It's a tight squeeze, but I got it to work as shown.


When fully reassembled the edge of the Teensy board sits on the outside of the analog joystick board.  Here you can see the Teensy thru the accessory port slots.



The code can be downloaded here.  It simply reads in the controller status over I2C using a Wire library and maps the status to send out over USB using the Teensy Joystick support.

I found the following sources particularly helpful for this project.


Happy classic gaming!

Thursday, December 10, 2015

Arduino Code for Microtonal MIDI

See previous posts about my microtonal MIDI converter here, here, here, here, and here.

Here is the Arduino code.  Notes are below.

Seven Segment library:

As outlined in this earlier post I wrote a seven segment library with fast writing to digital pins.  It needs to be fast, or else it slows the MIDI processing down noticeably.

Microtonal MIDI library:

I also wrote a microtonal MIDI library that handles the input of MIDI note events and the output of n-TET microtonal note events.  To keep the code fast, this library filters out, i.e., does nothing with, MIDI commands or data that are not related to note events.

The code uses all 16 MIDI channels successively and cyclically to send pitchbend and notes.  This is because pitchbend affects a whole channel, and each microtonal note often requires a different pitchbend value.  It can be adjusted to use less channels, but the number of channels would be the number of available notes of polyphony.
 

I implemented a monophonic mode that retriggers the previous note when necessary.  When dealing with microtonal scales with more than 12 notes, in some cases the same MIDI note is used for adjacent microtonal notes with different pitchbend values.  If both notes are held on and then one released, when a note off command is sent for one of the microtonal notes on a monophonic synthesizer then both notes are turned off.  When monophonic mode is active the code retriggers the remaining microtonal note and pitchbend value, which is what you would expect when playing a monosynth.  The illuminated button toggles between retrigger being on for a monosynth and being off for a polyphonic synth.
 
I also implemented Pythagorean tuning in the code--mapped to the "00" steps per octave setting, but it is commented out because the required if statements caused noticeable latency.  Perhaps there is more optimization to do, or perhaps a faster microcontroller like on a Teensy would allow my code to work well enough.  Or, maybe stick with 53-TET for a good enough approximation of 5-limit just intonation. :)

Main code:

The main code includes interrupt handling for the rotary encoder and button.  I found this page and this page helpful for writing the interrupt code. 

The ISR handles all the rotary encoder and illuminated button functionality.  When an encoder is turned, the motion is mapped to a change in the steps per octave or base MIDI note, and those values are updated for the seven segment display.  When the button is pressed, monophonic mode is toggled on or off and the internal LED is toggled on or off to match. 

The main loop consists of essentially a call to handle one byte of incoming MIDI data and then a single flash of the appropriate LEDs in the seven segment display.

Wednesday, December 2, 2015

My Arduino Based Microtonal MIDI Converter


 It's alive!  See earlier posts for more details.
 

The 12 is the number of steps per octave, and the 60 is the base MIDI note number.  The lit up button means that it is in monophonic mode, which basically means it will retrigger the last note when necessary.  Pushing the button toggles the light off and sets it in 16-voice polyphonic mode and does not retrigger the last note.  More details about retriggering are to come when I post about the code.
 

Here you can see inside a little better without flash, but the LEDs wash out.  The parts list is below.  I used some LEGO bricks to wedge the main boards in place.
 

Another angle shows the MIDI out port.  The MIDI in port is on the left side.  I turned the encoder knobs to set it to 10 steps per octave and 62 as the base MIDI note number.  I hope to post video soon to show it in action.

Here is a parts list: