Hello,
I was trying some of the basic Serial sketch examples on my R3 Mega 2560. It seems unable to recognize characters in the buffer (Serial.available(), serialEvent do not work). However, it can print to the serial line (Serial.print() works). I did the loop back test as documented on the forum, and the Mega echoes things fine. Anyone have a clue as to what's going on?
Here's the sketch example (serialEvent) that I was using to test.
/*
Serial Event example
When new serial data arrives, this sketch adds it to a String.
When a newline is received, the loop prints the string and
clears it.
A good test for this is to try it with a GPS receiver
that sends out NMEA 0183 sentences.
Created 9 May 2011
by Tom Igoe
This example code is in the public domain.
*/
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
void setup() {
// initialize serial:
Serial.begin(9600);
inputString.reserve(200);
}
void loop() {
Serial.println("B"); //I can see this
if (stringComplete) {
Serial.println(inputString);
inputString = "";
stringComplete = false;
}
}
void serialEvent() {
Serial.println("A"); //I can't see this
while (Serial.available()) {
char inChar = (char)Serial.read();
inputString += inChar;
if (inChar == '\n') {
stringComplete = true;
}
}
}
Thanks guys EDIT: I have a Mac, if that might have something to do with it. I just found out about the "shift+upload" and got this error: avrdude: usbdev_open(): did not find any USB device "usb" Also, I'm using Arduino 1.01.