PHYS 2P32 Project: MIDI for Arduino/ 8 Note Keyboard University April 13, 2016
About Arduino: The Board Variety of models of Arduino Board (I am using Arduino Uno) Microcontroller constructd similarly to ATmega 328P chip (shown in figure)
The Board Cont d Parts:16 MHz crystal, 14 input/output pins, 6 analog inputs, reset button, USB port, power jack Can be powered by USB connection, AC-to-DC adapter or battery can function with external supply of 6-20 volts (less= unstable, more= overheating)
The Board Cont d 32 KB of flash memory (for storing code), 2 KB or SRAM (static random access memory) and 1 KB of EEPROM (electrically erasable programmable read-only memory) Schematic of Arduino Uno Board:
About Arduino: The Software Arduino 1.6.8 is the open source (IDE) software used for this board Software runs on Mac, Windows and Linux Software connects to Arduino board to communicate and upload programs There is a verify button for checking codes for any errors and an upload button to upload the code to the board Option to open a serial monitor that displays serial data sent from board
About Arduino: Coding on Arduino Main Functions: Setup(): used at beginning of code, can be used to initialize variables, pin modes, etc. and will only run once loop(): straight forward function, allows program to respond and loop/ repeat a code // used to comment out sections, useful for explaining sections of a code
Part 1: Keyboard With 8 Keys Parts: Arduino Uno board 8 buttons (for each key) 8 resistors (220 ohms used for the buttons to connect to positive voltage) jumper wires and a bread board Piezo: an electrical device that detects vibrations and creates noise (frequency produced are typically 2000 to 4000 Hz)
Keyboard With 8 Keys Cont d The Circuit: One end of each button connected to positive end of breadboard Other end of each button connected (through 220 hms resistor) to negative end of breadboard, as well as connected to output 2 through 9 on digital end of arduino board Positive end of piezo connected to output 13 on Arduino board Negative end of piezo connected to negative end of breadboard Ground output on Arduino connected to negative on breadboard 5V on Arduino connected to positive on breadboard
Keyboard With 8 Keys Cont d
Keyboard With 8 Keys Cont d
Keyboard With 8 Keys Cont d The Code: Code I developed was rather straight forward in its commands 1. Declared each button and outputs from arduino circuit 2. Assigned each button certain tone frequency 3. Created if statement to detect if button is pressed and send signal to piezo to sound specific frequency
Keyboard With 8 Keys Cont d Block Diagram: Start Label Each Button Assign Tone Frequencies If: Button Pressed Yes Signal Piezo to Play Frequency No Piezo Remain Soundless
Keyboard With 8 Keys Cont d Modifications Encountered number of challenged for which had to adapt and accommodate for: 1. Capacitive sensing: had to dowlnoad new software, learn coading techniques, develop code to activate arduino 2. Setting each not to play a specific frequency: some buttons/ keys did not preform as desired (could be because of the limited range of the piezo)
Part 2: MIDI for the Arduino About MIDI: MIDI: abbreviation for Musical Instrument Digital Interface Come in many shapes and sizes Allows one to explore musical world in many different ways Not a sound or audio, but rather a system that allows computers and electronic musical instruments to send instructions and communicate with each other Devices communicate through instructions and signals, and are connected through MIDI cables
MIDI for the Arduino Cont d Parts: Arduino Uno Board Breadboard and jumper wires 5-pin MIDI jack four resistors (three 220 ohms, one 4.6 k ohms) 6n138 Optocoupler:contains light-emitting and light-sensitive components used to couple isolated circuits (i.e. interconnects 2 separate electrical circuits through a light sensitive optical interface)
MIDI for the Arduino Cont d 6n138 Optocoupler datasheet:
MIDI for the Arduino Cont d The Circuit: Ground output on Arduino connected to negative on breadboard 5V on Arduino connected to positive on breadboard Placed 6n138 Optocoupler chip on breadboard Connected pin 8 on optocoupler to positive end of breadboard, and pin 5 to negative part 4.7 k ohms resistor from pin 7 to negative on breadboard
MIDI for the Arduino Cont d 220 ohms resistor between pin 2 and 8 on optocoupler Diode with negative end on pin 2 and postive on pin 3 Pin 4 on MIDI jack connected to pin 3 on optocoupler (through 220 oms resistor) Pin 5 on MIDI jack connected to pin 3 optocoupler RX pin on Arduino to pin 6 on optocoupler
MIDI for the Arduino Cont d Circuit:
MIDI for the Arduino Cont d Circuit:
MIDI for the Arduino Cont d The Code: 1. Download MIDI library onto Arduino software and declare in code to ensure Arduino can read MIDI outputs 2. Define LED on arduino to be connected to pin 13 3. Set up () part, set Arduino pin 13 to output and then initialized MIDI library for board to respond when a note is played 4. sethandlenoteon function added to instruct MIDI librarywhich function to call when note is played
MIDI for the Arduino Cont d 1. sethandlenoteoff comman added after this to then instruct library to turn off when note is not played 2. In Looped part of code: added MIDI.read to constantly check if any notes played (i.e. any MIDI data received) 3. Instructed LED on Arduino to turn on when detects note being played and off when no note played
MIDI for the Arduino Cont d Code with explanation:
MIDI for the Arduino Cont d Block Diagram: Start Call MIDI Library Define Pin 13 to turn on LED If: Note played Yes Turn on LED No Turn of LED
Conclusion Through this project, I acquired valuable skills and knowledge in circuits and coding Became acquainted with Arduino Uno and structure/ purpose of it Learned components of the board that will help me in future as I further my exploration into the board/ its properties Challenges faced helped me gain insight into developing functional circuit and how to code certain functions
Conclusion Codding for Arduino generally stright forward, however took a while to become comfortable with schematics and specific function properties Gained understandign of MIDI s and functionality of them Project allowed me to gain deeper understanding of course content and experience content hands on