char incomingByte; // for incoming serial data
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte);
}
}
going by your various posting, all your problems are caused by the simple fact that you don't know how to program in C or C++. The Arduino isn't to blame at all for your frustration.
To reduce that frustration I advise you to work through some basic "How to Program in C" text (there are many available on the net) to learn the basics like variables, data types, looping up to pointers and arrays. That course doesn't even need to have any relation with the Arduino, any course will do as long as you like it. Once you have that, many of the strange things you encounter in the Arduino environment will become clear and you can go on and concentrate on the specific challenges presented by programming microcontrollers like the Arduino. I think, that will give you a better way to progress than the way you try to learn at present.
going by your various posting, all your problems are caused by the simple fact that you don't know how to program in C or C++. The Arduino isn't to blame at all for your frustration.
To reduce that frustration I advise you to work through some basic "How to Program in C" text (there are many available on the net) to learn the basics like variables, data types, looping up to pointers and arrays. That course doesn't even need to have any relation with the Arduino, any course will do as long as you like it. Once you have that, many of the strange things you encounter in the Arduino environment will become clear and you can go on and concentrate on the specific challenges presented by programming microcontrollers like the Arduino. I think, that will give you a better way to progress than the way you try to learn at present.
Korman
My dear Korman,
You may be right. However, I did not program the code the I copied and pasted from this website. The very code that gave the results I posted. I'm assuming the author of the example that I copied does know how to program C/C++. Perhaps you can point out his/hers lack of knowledge.
Oh, and the data type for incomingByte was int in the author's original code - the result was the same...I had changed it to char to see what the result would be and didn't change it back prior to copying it for this post. Korman, I didn't mean to come across as a smart a$$...I just want this to work so much....
The program you posted did exactly that what the original author wanted it to do. At least I assume that much as it tests quite well that the serial communication is working properly and provides good debugging data. The problem arises only because you imagine that the program does something else and then wonder, why you don't get the results you expect.
The ASCII value ! Why is it not 1? When I change DEC to BYTE, I get 1!
You could have answered yourself the the question why isn't it 1 in 30 seconds by taking a look at the documentation of the Serial.println function, realise on line 2 of the description that you need to click on the link to Serial.print function where in the second paragraph of the description exatly this problem is explained. They just used the letter N instead of 1.
WTH
This is a good question, why didn't you bother to look in the obvious place?
Thanks zoomkat, your code worked perfectly. (I was looking at your code when I posted my last, hence the confusion with the char and int typing for incomingByte). But something weird happened...I ran zoomkats code - good to go as stated - but I then changed the char to int, uploaded it, and ran it again. It worked! I then added the =0 so I had int incomingByte = 0 instead of int incomingByte. I got the 49 result again. I've printed out a lot of material on C/C++ types...I'll get to the bottom of this.