Arduino MIDI interface - Serial was not declared in this scope

I'm very new to arduino, I've been trying to follow this tutorial to get the arduino to interface with the Whammy pedal using a MIDI cable. I've managed to sort out the cable, solder it, and identify which cable is which. However on uploading the test sketch on the tutorial i.e.:

void setup() {
Serial3.begin(31250);

for (uint8_t i=1; i++) {
delay(50);
Serial3.write((uint8_t)0xC0); //TYPE: program change
Serial3.write((uint8_t)i);
}
}

void loop() {
}


I get the following compile errors:

sketch_jun19a.ino: In function 'void setup()':
sketch_jun19a:2: error: 'Serial3' was not declared in this scope
sketch_jun19a:4: error: expected ;' before ')' token


What's going wrong?

I should add I'm using an Uno.

• Where is Serial3 declared? Have you omitted a #include? And where is the exit condition in your for statement? – MikeJ-UK Jun 19 '13 at 14:31
• This isn't my code, it's the code found on the tutorial linked in the question. I was perhaps naively hoping that I could get it up and running and then learn the ins and outs of it from there and start tinkering. – Ben Jun 19 '13 at 14:34
• This for statement will run forever (note the extra semicolon) :- for (uint8_t i=1; ; i++) This will terminate after 10 iterations :- for (uint8_t i=1; i<=10; i++) – MikeJ-UK Jun 19 '13 at 15:07
• I've added that loop (the indefinite one) and changed from Serial3 to Serial as suggested below, I now get no compile errors however the Whammy pedal doesn't cycle as it should, Any ideas? – Ben Jun 19 '13 at 15:24
• I'm not familiar with the Arduino, but if the argument to delay is in milliseconds (which I suspect), try increasing it to 1000 (ie 1 second). Also, I don't see where the serial port is configured for parity, stop bits etc. – MikeJ-UK Jun 19 '13 at 15:33

What kind of Arduino are you using? Only the Arduino Mega and Due can access Serial3 (reference link). Try replacing it with just plain-old Serial if you're not using one of these.

Also, your for loop is missing the condition argument (that's what the third line in your compile error list is whining about).

• I'm using an Uno, which probably solves the Serial 3 issue. I'm a bit unclear on the code side of things, as I was hoping to deconstruct the code I got from the tutorial for my understanding... – Ben Jun 19 '13 at 14:38
• @Ben Try running it with just the change to the Serial class. I looked at the tutorial you linked and I feel like maybe the code isn't fully tested... or maybe I'm missing something. – Angelo Stavrow Jun 19 '13 at 14:50
• Running it with Serial instead of Serial 3 gives the following errors sketch_jun19a.ino: In function 'void setup()': sketch_jun19a:4: error: expected ;' before ')' token sketch_jun19a:6: error: 'Serial3' was not declared in this scope – Ben Jun 19 '13 at 15:07
• Did you change the Serial declaration everywhere (including the setup() loop)? – Angelo Stavrow Jun 19 '13 at 15:12
• That's the error with that for loop as @MikeJ-UK and I mentioned. A for loop requires three arguments (reference): an initialization (uint8_t i=1;), a condition (missing from your code), and an incrementer (i++). The first tells the loop where to start, the second when to stop, and the last what to do to the index (i) after each iteration of the loop. Without all three arguments there, the compiler will error out. – Angelo Stavrow Jun 19 '13 at 15:30

"Not declared in this scope" generally means that your compiler doesn't know what you mean by "Serial3." I don't know if you're at all familiar with Object Oriented concepts or classes / abstract data types, but that error means that the compiler doesn't have a definition for "Serial3." You may know Serial3 reads and writes Serial Data from a serial port, but as far as the compiler is concerned, you could have written "WetBlanket" or "Basketball" and things would have been the same.

So, for your solution, change all instances of Serial3 to Serial, as well as make sure you include the necessary files using #include. Believe it should be #include "Arduino.h", but its been a while since I've done any Arduino work.

The other error is simply another error caused by your compiler getting confused by the Serial3 data type.

I'm pretty late to the party but if you didn't solve this yet i suggest you to use a MIDI breakout board. It's only \$15 and have the standard connectors and it will protect your arduino inputs besides try the MIDI library it will give you a more straightforward approach in your programming.