Ok, I remade it to the things you teached me and put some comments at every line so that you see what I think it does.
char data[27];
int SerialInput;
int index = 0;
void setup()
{
Serial.begin(9600);
Serial2.begin(9600);
Serial.println("power on");
}
void loop()
{
if (Serial2.available() > 0)
{
SerialInput = Serial2.read(); //Give a name to the input characters on RX2
data[index] = SerialInput; //Put the characters into a string each character placed 1 position behind the previous one
index++;
if (SerialInput == '\n') //If the SerialInput has ended his line
{
data[index] = 0; //give the string a 0 on the end so it know it has ended
processData(); // start void processData??
index = 0; // Let the index start from 0 again
}
}
if (index == 27) // if the total string is placed, print the string
{
Serial.println(data);
}
}
As result I only get 2 lines... After that it stops for some reason. If I remove my last If-loop, the data will be printed every time something changes. Therefore I get a lot of lines, but with a lot of wrong characters. They appear random in my strings.
The last character with the program I have right now is wrong, I get a 3 in stead of 8 (What I send him)
Again, thanks for all the help so far! Really nice people.
My questions:
-I am making a string right? Not an array, because I'm getting more confused every minute.
-Is data[index++] the same as data[index] and on the next line index++ Because once I got a different result... But after I uploaded it again this was ok.
-Is saying data[index] = 0 the same as data[index] = '\0' ? Or is the 0 character automatically seen as the carriage return like PaulS told me to use?