Saturday, 6 December 2014

Improvements and Fixing Issues

Improvements

The next step to upgrading from my Prototype, was to get the LED's to turn off after the key was released. Basically to understand note off signals. This has been a real struggle however and after hours of trying I still can't find a way to get the Arduino to register this. My idea seems ok enough and should work.

My idea is to use Max, to understand that when the note is released, it send a signal of 0 to the Arduino. In the code, the Arduino should register 0 and as a result of he 'else' function, all LEDs should turn off. However, getting Max to send a 0 has proved difficult. This is my next step and will continue working on it. Below is a screenshot of the Max patch in working progress, on the left is where I test the Max patch, and the right is where I build the tests before testing them.


Fixing Issues

A real issue I had with my Prototype was that one of the LEDs was always dimmer than the other two. I had a few theories to why this could be. First I thought it was the LED itself, but after switching LEDs around, it wasn't that. I always tried switching cables, resistors, even outputs from the Arduino. This became an issue I figured I would fix at a later date.

However, today I was reading back over my Arduino code, and I noticed something was missing. Below is the area I noticed the issue.

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // initialize the LED pin as an output:
  pinMode(ledPin7, OUTPUT);
  pinMode(ledPin6, OUTPUT);
}

I realised that I never setup ledPin5 to be an Output! As a result, Arduino never considered the 3rd LED to be an Output signal, which meant a dim LED. All I had to do was change the code to this:

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // initialize the LED pin as an output:
  pinMode(ledPin7, OUTPUT);
  pinMode(ledPin6, OUTPUT);
  pinMode(ledPin5, OUTPUT);
}

The Arduino now registers ledPin5 as an Output so now the LED receives the High voltage when triggered by the MIDI keyboard.

Thursday, 4 December 2014

Prototype

Here is the finished Prototype. This blog post is to present evidence of that. Below you will find:

  1. A video showing the Prototype functioning 
  2. A photo of the Prototype Arduino
  3. A copy of the Arduino code text
  4. A copy of the Max Patch code
  5. A Fritz diagram of the Arduino and breadboard layout
1. Video



2. Photo of prototype


3. Arduino Code


//Arduino Code, copy from here

const int ledPin7 = 7; // the pin that the LED is attached to
int ledPin6 = 6;
int ledPin5 = 5;



int incomingByte;      // a variable to read incoming serial data into

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // initialize the LED pin as an output:
  pinMode(ledPin7, OUTPUT);
  pinMode(ledPin6, OUTPUT);
}

void loop() {
  // see if there's incoming serial data:
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = Serial.read();
    // if it's a 48 (Middle C), turn on the LED:
    if (incomingByte == 48) {
      digitalWrite(ledPin7, HIGH);
    } 
    // if it's anything else, turn off the LED:
    else {
      digitalWrite(ledPin7, LOW);
    }
    if (incomingByte == 50) {
      digitalWrite(ledPin6, HIGH);
    }
    else {
      digitalWrite(ledPin6, LOW);
    }
    if (incomingByte == 52) {
      digitalWrite(ledPin5, HIGH);
    }
    else {
      digitalWrite(ledPin5, LOW);
    }
  }
}

// to here

-----------------------------------------------------------------------------------------------------------------------

4. Max Patch

<pre><code>
----------begin_max5_patcher----------
681.3oc4WkraaCCD8rCP9GDzYWCtnM1a86nnHPxl0gA1TBTzotMn+6kKRVLI
PKznRtA8hnmgKZdu4wQie496VEVTdlVGF74fuFrZ0KJOqL9zdV05XU3w7yaO
jWaVXHm9ixhmBW2LmjdVZ7WSEr7CAaCHI.vko+dIWxyORMK4K5UbYJ9oikmj
GnRy4hZcWkK29Hiu+AAcqzFZXvFv5.TbrdHkXLTtB9V6dX6LmuJt9Dp6caOc
4Oqn1iIjwkgqCBC61nJFX71P.5Fz0reY1FDsAXb+66uSOpFVOYt5HstNeO88
jUVl+LDb.FhXXHHwvPwVirdXHXR+LTeTCZ4nlnz+tTC1GpI5eApo3jTVxudn
ZAIBL38DHpenVjy226kjkGVDefEXogUu0CkBVEuTRmiZgPfUNmNHYjMZoP8v
hoqUGeAULGzQh4IdXoQWckpbg58JohGn77hClH.LFUMn54CAWkFOYtJ9+ctB
hltvB+ghr5obktREi6OIhmv2izOiRFtt8jJUMbEqoRV1sGdfweWuuFPnm3MT
Xc4Iw11.pozZ.rKN1QqkLdtjo9.W2hzcZ4tpGY61Q4uRTbjsqpTgol.IMcSr
t+DKwo3uVKmWEqVKsLT2.x.uPBXTjD4KRvDSris8rCtXbqAB50qZx.AYzuNF
yKPFWaA7EHMZKaFgPVfLhQ0LZJAAttTBBi0CNFyHRPS9Vx0HtRgNhKswLhDv
jPRhuHg3hDxhfjo.jrqKiDE67kKmea+qH10P.yM5fSAcdUUNF2gnTza+MDXF
ZJTnMtwYuzqK6gcpUiSt4YoXeQgaVJKpUONun.MFJv9hhjDmaRHhevnoGs7p
pmoh5lHwh.U+rOUJz1Iqs1Lt011.Xnf9LqcKYVW4BUuoRUiomD1VZOmDEplw
7BUO9C.X.g4F
-----------end_max5_patcher-----------
</code></pre>

5. Fritz Diagram


Major Breakthrough in Prototype

Today I managed to finish my Prototype at least in fundamental form. I achieved this by learning how to get the Arduino to receive a signal from Max.

I achieved this by changing and adapting the PhysicalPixel example in the Arduino software. In the example, it was supposed to prove that you could recieve a signal from Max to control and LED. The example gives you the arduino code and a patch to copy and paste into Max. I actually found that this example didn't work for me, and no LED was triggered. However, I didn't give up. First here's the example arduino code with the Max Patch.

/*
  Physical Pixel

 An example of using the Arduino board to receive data from the
 computer.  In this case, the Arduino boards turns on an LED when
 it receives the character 'H', and turns off the LED when it
 receives the character 'L'.

 The data can be sent from the Arduino serial monitor, or another
 program like Processing (see code below), Flash (via a serial-net
 proxy), PD, or Max/MSP.

 The circuit:
 * LED connected from digital pin 13 to ground

 created 2006
 by David A. Mellis
 modified 30 Aug 2011
 by Tom Igoe and Scott Fitzgerald

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/PhysicalPixel
 */

const int ledPin = 13; // the pin that the LED is attached to
int incomingByte;      // a variable to read incoming serial data into

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // see if there's incoming serial data:
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = Serial.read();
    // if it's a capital H (ASCII 72), turn on the LED:
    if (incomingByte == 'H') {
      digitalWrite(ledPin, HIGH);
    }
    // if it's an L (ASCII 76) turn off the LED:
    if (incomingByte == 'L') {
      digitalWrite(ledPin, LOW);
    }
  }
}

/*
Max/MSP version 5 patch to run with this example:

----------begin_max5_patcher----------
1672.3oc2ZszaaiCD9ryuBBebQVCQRYao8xhf1cQCPVfBzh8RRQ.sDsM2HSZ
HQmlzh9eu7gjsjsEk7y0oWjiHoHm4aluYHGlueUmtiDuPy5B9Cv8fNc99Uc5
XZR2Pm726zcF4knDRlYXciDylQ4xtWa6SReQZZ+iSeMiEQR.ej8BM4A9C7OO
kkAlSjQSAYTdbFfvA27o2c6sfO.Doqd6NfXgDHmRUCKkolg4hT06BfbQJGH3
5Qd2e8d.QJIQSow5tzebZ7BFW.FIHow8.2JAQpVIIYByxo9KIMkSjL9D0BRT
sbGHZJIkDoZOSMuQT.8YZ5qpgGI3locF4IpQRzq2nDF+odZMIJkRjpEF44M3
A9nWAum7LKFbSOv+PSRXYOvmIhYiYpg.8A2LOUOxPyH+TjPJA+MS9sIzTRRr
QP9rXF31IBZAHpVHkHrfaPRHLuUCzoj9GSoQRqIB52y6Z.tu8o4EX+fddfuj
+MrXiwPL5+9cXwrOVvkbxLpomazHbQO7EyX7DpzXYgkFdF6algCQpkX4XUlo
hA6oa7GWck9w0Gnmy6RXQOoQeCfWwlzsdnHLTq8n9PCHLv7Cxa6PAN3RCKjh
ISRVZ+sSl704Tqt0kocE9R8J+P+RJOZ4ysp6gN0vppBbOTEN8qp0YCq5bq47
PUwfA5e766z7NbGMuncw7VgNRSyQhbnPMGrDsGaFSvKM5NcWoIVdZn44.eOi
9DTRUT.7jDQzSTiF4UzXLc7tLGh4T9pwaFQkGUGIiOOkpBSJUwGsBd40krHQ
9XEvwq2V6eLIhV6GuzP7uzzXBmzsXPSRYwBtVLp7s5lKVv6UN2VW7xRtYDbx
7s7wRgHYDI8YVFaTBshkP49R3rYpH3RlUhTQmK5jMadJyF3cYaTNQMGSyhRE
IIUlJaOOukdhoOyhnekEKmZlqU3UkLrk7bpPrpztKBVUR1uorLddk6xIOqNt
lBOroR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qxDpMVUMKcOrp
942acPvx2NPocMC1wQZ8glRn3myTykVaEUNLoEeJjVaAevA4EAZnsNgkeyO+
3rEZB7f0DTazDcQTNmdt8aACGi1QOWnMmd+.6YjMHH19OB5gKsMF877x8wsJ
hN97JSnSfLUXGUoj6ujWXd6Pk1SAC+Pkogm.tZ.1lX1qL.pe6PE11DPeMMZ2
.P0K+3peBt3NskC
-----------end_max5_patcher-----------
 */


For reasons I can't explain, it didn't work. However, it got me thinking back to my Prototype project which is about controlling 3 LED's with a MIDI keyboard. I figured "why not adapt this code to work in my favour?"

I started by connecting up 3 LED's to the Arduino using ports 5, 6, and 7. Then in the Arduino code, I changed the:

int ledPin = 13;

to:

int ledPin7 = 7;
int ledPin6 = 6;
int ledPin5 = 5;

This meant that I could use it integer to control each LED. I then chose which notes each LED would be assigned to, in this case I chose C, D, and E which is MIDI signal 48, 50, and 52 respectively.
All I needed to change in the code was that the incomingByte was going to 48 for ledPin7, 50 for ledPin6, and 52 for ledPin5. I also added an 'else' function for each one so that if the incomingByte was anything but it's corresponding MIDI number, it would recieve 0V, turning the LED off.

For Max, I used the Max patch I wrote earlier in another blog post (see blog post "Prototype Work" posted on the 01/12/2014). All I needed to change in the Max patch was that 'serial' object should be 'serial c 9600'. I used that object because it was an object we had used to control the Arduino in a previous University lecture.

Once I tidied up the code to be more presentable and added some comments of my own. I uploaded the code to the Arduino and ran the Max patch. It worked! I was now able to control 3 LED's using a MIDI keyboard. What was also good was that the LEDs turned off if another key was pressed that wasn't just the MIDI notes I wanted to use.

This is a major breakthrough in my development as I have not only achieved my first step in my proposal, but also the beginning of my second step. Below are photos of the Arduino and Breadboard, as well as screenshots of the Arduino code and Max Patch.



Arduino Code





Max Patch

Wednesday, 3 December 2014

Development of Prototype with Arduino

I had booked out an Arduino and made progress in understanding the Arduino and it's language.

I started by going through the learning section of the Arduino website. I went through every step of the Basics section. What this achieved, was a much greater understanding of using the Arduino and the code itself. I was also constantly referring to the Reference page as this had a key to explain terms such as:

setup () {
}

loop () {
}

Before going through this, the terms above meant nothing to me, I now understand that 'setup' is a function that organises code before running the 'loop' function which is basically the main program which loops. 


Once I began to understand the code a little more, I began asking questions to what I could change to actually make the Arduino do more than the example code. The first example that was successful was the DelayBlink example, which I got to blink multiple times at different times. Here's the code for that:


After achieving that, I began doing other things like getting it to light up connected LED's and changing which specific one to flash. For example, if I had an LED connected to port 6, I just changed the setep() to say:

void setup() {
   pinMode(6, OUTPUT);
{

This was an important to my development I believe as this broke the boundary between reading code to creating code and understanding what I was doing.

I did achieve other changes in code, unfortunately I did not save these changes or document them because of my excitement.

Links used for learning and research:

http://arduino.cc/en/Tutorial/HomePage

Monday, 1 December 2014

Prototype Work

I have been working towards my Prototype today. My Prototype product is a MIDI controller that can control at least 3 LED's with an Arduino. I will be gaining access to an Arduino soon, for now I am doing what I can without one. This includes doing research. A good source for code is the Learning section of the Arduino website, I will definitely be referring to that when I finally get my hands on an Arduino.

http://playground.arduino.cc/interfacing/MaxMSP


Other work is developing a patch with Max. It is patch that I hope will send numbers to the Arduino. I will be able to alter it when I get to use an Arduino. Currently all it can do is filter MIDI note information so that it triggers a message bang. I hope that this will be the fundamental to what will be needed to send note information to the Arduino to trigger an LED.