hello there. I have a problem using serial with my arduino mega ( normally i explain the context, but with my poor english i do not dare ).
i'm trying to interface my computer ( under archlinux 64bit ) with my new arduino, using usb, and the virtual serial port /dev/ttyACM0. the upload work great with the arduino's ide ( i try out some fonctions and exemples and no problem.) i use the following code to try out the serial initialisation:
int ledPin = 49; // select the pin for the LED
int val = 0; // variable to store the data from the serial port
void setup()
{
pinMode(ledPin,OUTPUT); // declare the LED's pin as output
digitalWrite(ledPin,HIGH);
delay(3000);
digitalWrite(ledPin,LOW);
Serial.begin(9600); // connect to the serial port
}
void loop () {
// val = Serial.read(); // read the serial port
val='8';
// if the stored value is a single-digit number, blink the LED that number
if (val > '0' && val <= '9' ) {
val = val - '0'; // convert from character to number
for(int i=0; i<val; i++) {
// Serial.println("blink!");
digitalWrite(ledPin,HIGH);
delay(150);
digitalWrite(ledPin, LOW);
delay(150);
}
//Serial.println();
}
}
and it dosent work, the L led blink as if it reset permanently ( and nothing else append ). but, when i try to comment out the "Serial.begin(9600);" (and all Serial ligne. ) the led connected on pin 49 light for 3 second and began blinking normaly.
i don't understand what's appening here, if one of you can help me, I would be grateful.
thank for reading.