Pages: [1] 2   Go Down
Author Topic: how to interpret the serial data  (Read 1700 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

can u please give me a sample that are receiving a serial data,that f the mcu receive a charater 'a' the corresponding data will store in a buffer and when the character 'b' is detected d corresponding character will store to other buffer..can u please give me a related sample
« Last Edit: March 14, 2013, 04:10:16 am by nehj » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24327
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if (Serial.available ()) {
  int inChar = Serial.read ();
  switch (inChar) {
    case 'a': // do something
    break;
    case 'b': // do something else
    break;
   default: // do something completely else
  }
}
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24327
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code I gave you is just an incomplete example - you need to fill in the blanks, or you could rewrite as, say, a simple state machine.
You original question wasn't specific.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ah...i know that it is incomplete i just want to know if it is applicable to what i want to do?tnx
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46071
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the char 0999999999 will be save to a buffer
Which ONE key did you press to type the character 0999999999?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

one key??i want to store it in a buffer...this character will be send by the computer to the arduino,if ahm..for example the original data is a099999bTYYYYU, IF character 'a' is detected the 099999 will be store to a buffer and if character 'b' is detected the TYYYYU will be store to another buffer....please help me to do this...
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46071
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Proper use of capital letters and punctuation would really be appreciated here. You sound like a little boy whining.

You keep saying you want to store A character, and then you say that the character is 0999999999.

Well, I have news for you. 0999999999 is not a character. It is a string.

If you want to ask about how to read characters, and store them in an array AS A string, then say that. Don't keep referring to 0999999999 as a character.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i'm so sorry for that....im unfamiliar with this,,,
ahm..is it possible to use the switch case function??plz help me
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24327
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've shown you how to wait for and read one character into one particular buffer called "inChar", and make a decision based on the value of that character.
It isn't a great leap of imagination to read in further characters and read them into other buffers.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

how can i do this?any advice?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24327
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some application, a little effort, and maybe work through some of the examples supplied in the IDE.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

plz...give me a specfic examples
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24327
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's been a while since I looked at the IDE supplied examples, but I'm pretty sure there's (at least) one on serial comms, and another on arrays.
I'd start with those.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

please give me the very specific examples in IDE pls???
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24327
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm posting from my tablet, so I'm afraid I can't.
What did you do to help yourself in the fifteen minutes between my last post and yours?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: [1] 2   Go Up
Jump to: