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() {

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

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.

  • \$\begingroup\$ Where is Serial3 declared? Have you omitted a #include? And where is the exit condition in your for statement? \$\endgroup\$ – MikeJ-UK Jun 19 '13 at 14:31
  • \$\begingroup\$ 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. \$\endgroup\$ – Ben Jun 19 '13 at 14:34
  • 3
    \$\begingroup\$ 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++) \$\endgroup\$ – MikeJ-UK Jun 19 '13 at 15:07
  • \$\begingroup\$ 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? \$\endgroup\$ – Ben Jun 19 '13 at 15:24
  • \$\begingroup\$ 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. \$\endgroup\$ – 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).

  • \$\begingroup\$ 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... \$\endgroup\$ – Ben Jun 19 '13 at 14:38
  • \$\begingroup\$ @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. \$\endgroup\$ – Angelo Stavrow Jun 19 '13 at 14:50
  • \$\begingroup\$ 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 \$\endgroup\$ – Ben Jun 19 '13 at 15:07
  • \$\begingroup\$ Did you change the Serial declaration everywhere (including the setup() loop)? \$\endgroup\$ – Angelo Stavrow Jun 19 '13 at 15:12
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – 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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.