Turn your NES controller into a simple 8 key electronic piano with this Instructable.
I was inspired to make this project after completing the Instructables Arduino Class, reading Gordon McComb's excellent book "Arduino Robot Bonanza" (www.robotoid.com), and building joshua.brook's Simple Electronic Piano.
Step 1: Parts and Equipment
- 1 x NES controller - I picked one up from my local pawnbroker / second hand store
- 1 x Arduino UNO or similar - I used a DuinoTECH Classic (UNO)
- 1 x Piezo Transducer - I used a DuinoTECH Arduino Compatible Active Buzzer Module
- 5 x Male-male jumper wires (Black, Red, Orange, Yellow, Green)
- 2 x Male-female jumper wires (Black, Blue)
Step 2: Connect Controller to Arduino
The NES controller plug has 7 pins - Click on the pins in the first picture to find each function
- Connect red wire to +5V (NES pin 7) and 5V pin (Arduino) - Fortunately, male jumper wires fit perfectly into the NES controller plug
- Connect black wire to GND (NES pin 1) and GND (Arduino)
- Connect orange wire to Clock (NES pin 2) and D5
- Connect yellow wire to Latch (NES pin 3) and D6
- Connect green wire to DataIn (NES pin 4) and D7
Step 3: Connect Piezo Transducer Module
- Connect female end of blue wire to S on Piezo Transducer Module and then to D9 (Arduino)
- Connect female end of black wire to - on Piezo Transducer Module and then to GND (Arduino)
Step 4: NES Controller Piano Sketch
- Download the sketch (see attached file)*.
- Add the pitches.h library to a new tab in the sketch
- Upload the sketch to your Arduino
*The sketch is based on Gordon McComb's "Teachbot gamepad controller sketch / TeachbotServo_NES.ino" from his brilliant book Arduino Robot Bonanza published by McGraw-Hill in 2013. Arduino Robot Bonanza is well worth the read and I found it complementary to Instructables' Arduino Class.
<p style="margin-left: 40.0px;">/*<br> * NES Controller Piano * * Created 22 December 2018 by ptevyesaur * * This project turns a NES controller into a simple piezo buzzer piano * ---------------------------------------------------------------- * Requires: * ---------------------------------------------------------------- * - 1 x Arduino Uno * - 1 x Active Piezo Transducer Module * - 5 x Male-Male Jumper Wires * - 2 x Male-Female Jumper Wires * - 1 x NES controller * ----------------------------------------------------------------- * NES Controller Plug ("End On" View) * ----------------------------------------------------------------- * _________ * / 01 |GND * +5V | 70 02 |Clock * ? | 60 03 |Latch * ? | 50 04 |DataIn * __________ * ----------------------------------------------------------------- * Connections: * ----------------------------------------------------------------- * Arduino Uno Pinout NES Controller * (Use Male-Male Jumper Wires) * ----------------------------------------------------------------- * +5V ------------> Pin 7 * D7 ------------> Pin 4 * D5 ------------> Pin 2 * D6 ------------> Pin 3 * GND ------------> Pin 1 *------------------------------------------------------------------ * Arduino UNO Pinout Active Piezo Transducer Module * (Use Male-Female Jumper Wires) * ----------------------------------------------------------------- * D9 ------------> S * GND ------------> GND * ----------------------------------------------------------------- * NES Controller Button Values: * ----------------------------------------------------------------- * Right = 11111110 bit 0 * Left = 11111101 bit 1 * Down = 11111011 bit 2 * Up = 11110111 bit 3 * Start = 11101111 bit 4 * Select = 11011111 bit 5 * B = 10111111 bit 6 * A = 01111111 bit 7 * ----------------------------------------------------------------- * Libraries Required: * ----------------------------------------------------------------- * "pitches.h" library (https://www.arduino.cc/en/Tutorial/toneMelody) * copy and paste to "New Tab" * ----------------------------------------------------------------- * Reference List: * ----------------------------------------------------------------- * "Teachbot gamepad controller sketch" by Gordon McComb Arduino Robot Bonanza McGraw-Hill 2013 */ #include "pitches.h" // include pitches library #define nesClock 5 // label pinout #define nesLatch 6 #define nesDataIn 7 #define buzzer 9 byte nes = 0; // global variable void setup() { // put your setup code here, to run once: Serial.begin (9600); // serial terminal speed pinMode (nesDataIn, INPUT); // set up pins pinMode (nesClock, OUTPUT); pinMode (nesLatch, OUTPUT); pinMode (buzzer, OUTPUT); } void loop() { // put your main code here, to run repeatedly: nes = nesRead (); if (bitRead (nes, 0) == 0){ // If right button NES Controller pressed tone (buzzer, NOTE_F4, 250); // play tone NOTE_F4 Serial.println ("NOTE_F4"); // NOTE_F4 displayed on Serial monitor } if (bitRead (nes, 1) == 0){ tone (buzzer, NOTE_E4, 250); Serial.println ("NOTE_E4"); } if (bitRead (nes, 2) == 0){ tone (buzzer, NOTE_D4, 250); Serial.println ("NOTE_D4"); } if (bitRead (nes, 3) == 0){ tone (buzzer, NOTE_C4, 250); Serial.println ("NOTE_C4"); } if (bitRead (nes, 5) == 0){ tone (buzzer, NOTE_G4, 250); Serial.println ("NOTE_G4"); } if (bitRead (nes, 4) == 0){ tone (buzzer, NOTE_A4, 250); Serial.println ("NOTE_A4"); } if (bitRead (nes, 6) == 0){ tone (buzzer, NOTE_B4, 250); Serial.println ("NOTE_B4"); } if (bitRead (nes, 7) == 0){ tone (buzzer, NOTE_C5, 250); Serial.println ("NOTE_C5"); } if (nes == 255) //Checks to see if no button pressed (255 = 11111111) { noTone; //if no button pressed no tone will be played Serial.println ("NO_TONE"); } delay (180); } byte nesRead (){ // "bit banging" byte value = 0; digitalWrite (nesLatch, HIGH); delayMicroseconds(5); digitalWrite (nesLatch, LOW); for (int i=0; i<8; i++) { digitalWrite (nesClock, LOW); value |= digitalRead (nesDataIn) << (7 - i); digitalWrite (nesClock, HIGH); } return (value); }</p><br>
Step 5: Play
- Open the Serial Monitor to watch the NES Controller communicate with the Arduino
- Play some tunes
- UP = C4
- DOWN = D4
- LEFT = E4
- RIGHT = F4
- SELECT = G4
- START = A4
- B = B4
- A= C5
Step 6: Going Further...
If you enjoyed this quick project try my NES Controller Piano Ultrasonic Theremin Mash-Up or try your own improvements
Discussions