Sending a string via serial communication Leonardo

Hello, guys, I have an Arduino Leonardo Board.

Today I've been playing with different data format sent and received via serial USB communication.

Based on PhysicalPixel example, I have succesefully sent data: bytes and chars.

But I cannot make use of char array. This is my code: gist:5084117 · GitHub
After asking on mIRC, a fellow give me this and tried with nada results: http://pastebin.com/Q51VzU9J
It is funny, because i'ts looking correct, but it doesnt work. I have tried sending the "Ican2" from a c# GUI and from Serial Monitor. The ratebaud is the same everywhere: 9600. The RX led from the board is liting like is suppose to when receiving data.

Help?

btw, I've just tested integers. The same as char arrays.

http://pastebin.com/Q51VzU9J

Unknown paste ID.
In other words, bad link.

This is the correct link, I do not see why it isn't working: gist:5084117 · GitHub
This is the code, anyways:

const int ledPin = 13; // the pin that the LED is attached to
char incomingString[10];    
 
void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
}
 
void loop() {
  // see if there's incoming serial data:
  int i = 0;
  while (Serial.available() > 0) {
      incomingString[i++] = (char)Serial.read();
      delay(10);
  }
  
    // turn on the LED:
    if (incomingString == "Ican2") {
      digitalWrite(ledPin, HIGH);
    } 
    // turn off the LED:
    if (incomingString == "Ican22") {
      digitalWrite(ledPin, LOW);
    }
  
}

I just can't make this work. I am sending the Ican2 or Ican22 string, RX led is liting, but the led is not get put on HIGH or LOW.

Are you also including a NULL character "/0" ? More importantly how are you sending the data? Try Putty.

You can clearly see from the code that I am comparing the 'ican2' with no \0 character. With serial monitor i have been sending with and without the end vharacter but no results. Please help I do not have any succes with this, the same with integers.

I wonder what you would get if you echo out what you put in?

while (Serial.available() > 0) {
      incomingString[i++] = (char)Serial.read();
      Serial.print(incomingString[i]);
      delay(10);
  }

Maybe your if statements dont like double quotes, try single quotes.

fulminator:

    // turn on the LED:

if (incomingString == "Ican2") {
     digitalWrite(ledPin, HIGH);
   }
   // turn off the LED:
   if (incomingString == "Ican22") {
     digitalWrite(ledPin, LOW);
   }

You cannot compare two char arrays using ==, use strcmp (or strncmp to include the length of the string and avoid issues due to the lack of \0).

HazardsMind:
I wonder what you would get if you echo out what you put in?

while (Serial.available() > 0) {

incomingString[i++] = (char)Serial.read();
      Serial.print(incomingString[i]);
      delay(10);
  }




Maybe your if statements dont like double quotes, try single quotes.

squares. I get simple squares.

Can somebody please show me a clear example of SENDING and RECEIVING CHAR ARRAYS please? I got stuck at this problem and I can't go forward. Thanks!

That code looks wrong to me. It will put the new character into incomingstrong* and then increment i to the next array*
position, which has nothing in it yet !

where are those italics coming from ?

You also need to check you are not exceeding the array size.

Can somebody please show me a clear example of SENDING and RECEIVING CHAR ARRAYS please? I got stuck at this problem and I can't go forward.

You've gotten a bunch of suggestions. Which ones have you implemented? Where is your revised code? What problems are you still having?

Sending strings is trivial. But, notice something about all the strings on this page. They contain delimiters. We know that a collection of letters forms a word because there is a space after the collection, before a new collection starts.

Noticehowmuchmoredifficultitistoreadsomethingwhenthosespacesareomitted.

Collections of words that form a sentence are separated from other collections of words by punctuation marks, like periods, question marks, and exclamation points.

Again, without those, its much harder to read text One has no idea where a thought ends Or, where another thought begins.

Finally, sentences are collected into paragraphs, with separators between paragraphs. When we read collections of letters, we read data and store it until each of the various kinds of delimiters appear. Spaces that delimit words are visual cues, but the delimiters that limit sentences and paragraphs have more than visual impact.

So, what delimiters are you using (or are you going to use) to tell the Arduino when it has read enough, and it is time to deal with what has been read and stored?