I have an arduino and a nodeMCU ESP8266 (if that matters). I am sending data from the arduino to the nodeMCU, but the data is shifted i.e. that sending variable1 will be received as variable2. the data is being sent using Serial.write(variable_n); and the data is received like this:
char index_ = 0; // Index into array; where to store the character
char inChar = 'a'; // Where to store the character read
void modtag() {
while (Serial.available() < 1) //Venter på en byte
{
//do nothing
}
char index_ = 0; // Index into array; where to store the character
char inChar = 'a'; // Where to store the character read
while (index_ < 19 && (Serial.available())) // One less than the size of the array
{
inChar = Serial.read(); // Read a character
inData[index_] = inChar; // Store it
index_++; // Increment where to write next
}
inData[index_] = '\0'; // Null terminate
}
modtag();
strcpy(varialbe1, inData);
I use the modtag() method for every variable, which works fine, but the data is just not received/sent right.
They're going to ask you to post your complete sketches!
Serial Input Basics has everything you need.
I just read it through, but there's nothing about data being shifted
Here's how the data is sent:
Serial.print(vindretning);
delay(50);
Serial.print(v1);
delay(50);
Serial.print(v2);
delay(50);
Serial.print(v3);
delay(50);
Serial.print(v4);
delay(50);
Serial.print(v5);
delay(50);
And here it is how it is received:
modtag();
strcpy(vindretning, inData);
modtag();
strcpy(v1, inData);
modtag();
strcpy(v2, inData);
modtag();
strcpy(v3, inData);
modtag();
strcpy(v4, inData);
modtag();
strcpy(v5, inData);
And when trying to display it, it gets it random every time I turn it off and then on. v1 could be received as v4, and vica versa.
Bassusour:
I just read it through, but there's nothing about data being shifted
Of course not. Because if you use that system it won't be shifted. Look at the technique in the third example.
You can send data in a compatible format with code like this
Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker
...R