User:Opersing2688/ENES-100/Project 2:

Past Pages
This project is a continuation of the previous project cycle. Those pages can be found here:

Music Project Team Page 1

Connor's Wikiversity Page 1

Rachel's Wikiversity Page 1

Olivia's Wikiversity Page 1

Current Pages
Music Project Team Page 2

Connor's Wikiversity Page 2

Rachel's Wikiversity Page 2

Week1 Narrative
For the first week of this project I was tasked with looking into how to upload custom made images on Fritzing. For the music project, one of the goals is to have an accurate diagram of the beat bearing system and that will only be possible if the correct parts are in the diagram. The Fritzing program does not have the Papilio Platform Papilio One or the Papilio Platform LogicStart Metawing V1.2 in their database.

 File:Papilioplatformpapilioone.JPG| Papilio Platform Papilio One File:Metawing2.JPG| Papilio Platform LogicStart Metawing V1.2 

FPGA/Papilio
FPGA stands for Field Programmable Gate Array. FPGA is a circuit designed to be programmed by a customer or designer after it has been manufactured. A papilio uses FPGA in order to become a digital circuit.

Fritzing
I started off by researching how to upload custom made images on fritzing. I knew it was possible to upload custom images to fritzing based on my research from last week (see here)

Websites I visited:
 * fritzing.org - Fritzing part format
 * fritzing.org - Fritzing graphing standards
 * fritzing.org - Fritzing fonts and templates download
 * fritzing.org - Fritzing sketch file format
 * Pashless - Editding an SVG image for a fritzing part using inksape
 * Fritzing blog - New parts editor
 * wonderhowto.com - Fritzing circut boards
 * Bertrand Le Roy - Buidling a fritzing component
 * YouTube - Parts editor

This was my first impression of all of the information:


 * 1) The part will consist of multiple different drawings (for the different layers in fritzing)
 * 2) It is critical that the drawings are accurate
 * 3) There is lots of code involved
 * 4) File names seem to be super important
 * 5) Apparently there are tons of files involved in building a part and they can get lost quickly
 * 6) There are specific fonts and templates that are used in fritzing
 * 7) Finding a datasheet for the part will make life a ton easier

According to fritzing, a file is made up of a metadata file, and up to four SVG files. There are also multiple image files since there are multiple ways to view an image in fritzing (breadboard, schematic, and pcb). Fritzing uses specific font and templates for their parts which are available for download here. In addition, since there are so many files associated with making one part, many of the websites I visited gave instructions on how to name/organize files to make it easier to find them.

Once all of your files are ready, they are uploaded into fritzing and there you can determine where the pins and connections should be placed.

The Keyboard
During the last project rotation, I mostly worked on trying to program an arduino and MIDI shield to play a keyboard. I never got it working. In class the keyboard was hooked up to another little keyboard with the MIDI cable to see if the keyboards would communicate with each other. The MIDI "in" side of the cable went into the MIDI in port of the main keyboard and the MIDI "out" cable went into the MIDI out port of the little keyboard. When they were both turned on and the volume of the little keyboard was turned down, it could be played and heard through the main keyboard's speakers. This meant that the main keyboard as well as the MIDI cable were functioning properly; thus the problem with programming was with the arduino or MIDI shield. I tried switching the tone on the main keyboard to tone 10 (electric organ 1) and when I played the keys the tone had changed. I then played the keys on the little keyboard and it played the electric organ tone. One thing I noticed was that the lower keys in the little keyboard did not register with the main keyboard (for both tones).

Helpful Links
I found these websites to be very informative and useful.
 * MIDI Tutorial
 * Hex Dec Converter
 * General MIDI sound set
 * MIDI Messages
 * Essentials of the MIDI protocol
 * Guide to MIDI software specs

The Keyboard Problem
I had been having lots of trouble programming the keyboard the past weeks. Ultimately, the problem was with MIDI Shield. Apparently the solder was bridging multiple pins, therefore causing it to not work correctly. I was given a new MIDI shield which worked properly. This MIDI shield does not have the push buttons or potentiometers, but it still functions the same exact way.

The moral of the story: make sure that everything is soldered correctly!

Binary, Decimal, and Hexidecimal
In order for me to code properly, I had to first learn how the code works. I started off learning about binary numbers. In the Mary Had A Little Lamb Code (see here) most of the code is comprised of a set of numbers. Below is an example of a portion of the code. These numbers are referring hex (0x) numbers.

Binary, decimal, and hex (short for hexadecimal) are all ways to write the same thing. I learned from this site that the "0x" indicates that the number is a hexadecimal number. The 90 which follows the 0x refers to the decimal; thus, 0x90 equals 10010000, or 8 bits of information. In MIDI programming, "0x90" is the command to turn a note on. This is the reason why each line of code starts with 0x90. Similarly, "0x80" or 10000000 is the command to turn a note off.

Arduino Code
Binary plays a major part in arduino codes. Below is a table with common commands and their meanings.

MIDI Code
I learned from a MIDI tutorial that there are 16 MIDI channels, meaning up to 16 instruments can be played at once.

The velocity value determines how loud the note is played.

In order to play two notes at once, simply have two "noteOn" lines in a row (see below).

The middle column of numbers in the code (0x4B, 0x50) correlate with a note on the keyboard. Their binary numbers are 01001011 and 01010000 respectively. Using different combinations of numbers are used to play different notes. Note values range from 0-127 (middle C = 60, C# = 61, D = 62, etc.).

According to the MIDI tutorial, the sounds use a "program change" message to indicate that a different instrument is being played. A program change contains one status byte and one data byte. A status byte is 1100 CCCC and one data byte is 0XXX XXXX. The MIDI channel (0-15) is XXXXXXX. It is important to note that once you determine the note you want to be played, you must convert it to a hex number. I used this site to convert to hex.

I used a General MIDI Level 1 Patch Map in order to determine what tone is used (piano, violin, space pad, etc.). For example, if I wanted to use xylophone tone I would look at the chart, determine the number (in this case, 14), and then convert it to hex (0E). I could then insert it into the code.

Sample Code
I used this code for reference. Below is a portion of the code and comments explaining what it means.

Programming the Keyboard
The first thing I did with the keyboard was upload the Mary Had A Little Lamb code onto the arduino. The MIDI shield was attached as well as the MIDI cable and USB cable. The song played (see video). I then uploaded the sample code which also played without any problem.

I wanted to program part of a song that was relatively simple but had a variety of instruments so I chose Sail by AWOLNATION. I decided to use tone "synth strings" which is number 51 on the patch map. The song is in E flat minor which means for the beginning notes I want an E flat and A flat. I also raised it up an octave. E flat was number 75 on the keyboard and its hex number is 4B. A flat was number 80, hex number is 50.

Sail Code 1
When I uploaded it to the arduino and then plugged in the MIDI cable, the piano started playing, but it was really soft and scratchy. The tempo was also faster than what I wanted. See video here. I split each second into two (each "t =" only had 4 noteOn's instead of 8) and re-uploaded. It still sounded very faint. I tried switching to tone map G (I was previously on tone map N) and it started playing normally. See here.

I then raised the note velocity to 60 so it would be louder. I tried going higher than 60 but the notes would just go silent. I also found that I programmed an incorrect note and reprogrammed the correct note. I also added the bass note (E flat). The E bass flat is number 39 with a hex number of 27. I also added more of the song into the code. When I tried to upload, there was an error message "invalid digit '9' in octal constant". After playing around with the code and searching through it, I found that an "x" was missing is some of the "0x90" commands. I fixed that and it worked. The code is below. It represents 8 measures of the song.

Sail Code 2
I still couldn't figure out why the it played so quietly. I eventually figured out it was because the volume was down on the keyboard itself. Video is here.

I also played the song in the normal piano tone. This created a much louder noise, even when the volume was down. Next I hope to add drums as well as other sounds to the song. Video is here.

Tips

 * Make sure the right hex number is selected. It's very easy to get the hex and decimal numbers confused.
 * Double check EVERYTHING. This will save so much time in the long run.
 * Labeling helps (but only if the labels are correct)
 * Understanding how the code works helps greatly

Fritzing
Since programming the keyboard took so much time, I decided to put the Fritzing aspect of the project on hold. Last week's research is a good starting point for uploading custom made images which can be used in the future.

Block Diagram
Last week I made a block diagram showing a rough sketch of how the beat bearing system will connected. The music team decided that having a computer connect to the flat-screen monitor would be easier than having a meta-wing and VGA output. I then made a new diagram on Google Drawings.

Block Diagram
I had to make some revisions to the block diagram. I removed the arrows pointing at different items to avoid confusion and I also added arrows to correctly depict the flow of information to and from the different components of the system.

Programming the Keyboard
Instead of programming notes, this time I programmed drum beats. MIDI channel 9 is reserved for drums; therefore, the cmd column of the code always starts with 0x99. I also played around with changing the delay which changes the rhythm.

Drum Code 1
To see the video, click here.

Serial Library
The next step in programming the keyboard for the beat bearing project is learning about serial library which allows the arduino to send information back to the computer.

Tutorial on serial libraries

Arrays
In addition to serial libraries, I also started researching on how to add an array to the code. I learned from a YouTube tutorial that an array is a list in which each item in the list has a number. The video's example of an array was a stack of papers and each paper has a number. If you want to select one paper, you would select the number it is assigned in the array. More information on arrays can be found here Below is a sample code taken from an tutorial which explains how an array works.

Code Two had an array to play a scale. Below is the section of the code with the array.