I have a simple Arduino program that parses an int from the serial input and opens a solenoid. It works perfectly with the Arduino Serial Monitor, PuTTY, and HyperTerminal. (Older arduino, diecimila with atmega168)
The goal I have is to send that data to the Arduino from the command prompt. I have already made sure the command prompt com settings are correct by running:
mode com7:9600,n,8,1
However, when I try to send it the integer for it to parse, nothing happens, for example:
ECHO 2 > COM7
I have also tried ECHO '2' > COM7, ECHO "2" > COM7, (ECHO 2) > COM7 and all the other variations I could think of.
Here is my simple sketch:
int incoming;
void setup()
{
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
pinMode(6, OUTPUT);
pinMode(8, OUTPUT);
}
void loop()
{
if (Serial.available() > 0)
{
incoming = Serial.read();
switch(incoming)
{
case '1':
digitalWrite(2, HIGH);
delay(2000);
degitalWrite(2, LOW);
break;
case '2':
digitalWrite(4, HIGH);
delay(2000);
degitalWrite(4, LOW);
break;
case '3':
digitalWrite(6, HIGH);
delay(2000);
degitalWrite(6, LOW);
break;
case '4':
digitalWrite(8, HIGH);
delay(2000);
degitalWrite(8, LOW);
break;
}
}
}
I have tried this sketch with and without the single quotes around the case numbers, I have also tried using the Serial.parseInt() function instead of Serial.read(). Still, in all cases, it works with the above 3 programs but not with the command prompt. I have also tried this on Windows XP and Windows 7 with the same results.
Any help is greatly appreciated!
Thanks in advance,
Legomaniac