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.
3 Answers 3
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– Ben2013年06月19日 14:38:32 +00:00Commented Jun 19, 2013 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– Angelo Stavrow2013年06月19日 14:50:31 +00:00Commented Jun 19, 2013 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– Ben2013年06月19日 15:07:48 +00:00Commented Jun 19, 2013 at 15:07
-
\$\begingroup\$ Did you change the
Serial
declaration everywhere (including thesetup()
loop)? \$\endgroup\$Angelo Stavrow– Angelo Stavrow2013年06月19日 15:12:13 +00:00Commented Jun 19, 2013 at 15:12 -
1\$\begingroup\$ That's the error with that
for
loop as @MikeJ-UK and I mentioned. Afor
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– Angelo Stavrow2013年06月19日 15:30:39 +00:00Commented Jun 19, 2013 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.
for
statement? \$\endgroup\$for (uint8_t i=1; ; i++)
This will terminate after 10 iterations :-for (uint8_t i=1; i<=10; i++)
\$\endgroup\$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\$