So if I understand it correctly it didn't want to work because thoose variables were not available in the printing function, only in the receiving one?
No, here is what I think is happening. Your code is processing the serial data from the buffer faster than it all arrives, and you fall out of the while() loop. The code renters recveive() and sets index to 0, and the terinating '\0' is appended to incomingbyte[index] and make it a null string.
You can leave index as byte (not static byte) and add a delay(50) to the receive() and the code works properly as well as all the serial data has time to arrive.
cattledog your thinking is right but the solution of a delay is something I would always hesitate on doing but yes the option is there. I prefer your original thought of static.
UKHeliBob, a nice alternative example but I was giving a "Simple take" in the hope VTI_16V would understand the use of static. Reference by address in memory might come later in the learning curve.
sumguy:
It had nothing to do with the printing function
Simple take on "static"
index and endmarker are only used in the "receive" function.
The Arduino loop is so fast that it will go in and out of the receive function several times before it finally reads all of your data.
In the original code each time it loops in and out of receive then index and endmarker are initialized to zero, in other words they are not counting.
By making index and endmarker static they are initialized only once and that is on the first loop through the receive function.
Now that they are static and have been initialized the values will persist, in other words they will now count.
These two static values have nothing to do with the printing function, static values can only be used ,initialized and modified within the function they were created/declared.
VTI_16V:
Well i really dont know... that what i wrote is whole data that i get printed to monitor...
If you mean printed to the monitor by the Arduino then that is exactly what I did not want - because we don't know if the Arduino is interpreting the data correctly. There may be important non-printing characters in the datastream.
What is the data coming from? Do you not have a written description of the style of data that it produces? Can you post a link to the datasheet or user manual for the device that produces the data?
Robin2:
If you mean printed to the monitor by the Arduino then that is exactly what I did not want - because we don't know if the Arduino is interpreting the data correctly. There may be important non-printing characters in the datastream.
What is the data coming from? Do you not have a written description of the style of data that it produces? Can you post a link to the datasheet or user manual for the device that produces the data?
...R
The data is coming from nextion display and if you want you can google for the datasheet (i don't have link)... I sincererly don't understand half of data sheet because i am a noob but what i understand is that you have a program called nextion editor with debugging mode which spits out the messages that nextion is going to send by serial when you for example press the button... And that message for the example that i have given is 65 00 01 01 FF FF FF in hex which stands for 101 0 1 1 255 255 255 in decimal which i have posted before and which I have on the serial monitor when i upload the code using string from instructables which i also posted... So if something is missing in that message i really don't know but i haven't seen anywhere that anybody mention some kind of "hidden" data that is relevant except this one which is visible... And belive me that i have read a lot of tutorials on nextion... So if some relevant data is hidden i don't know nothing about that, and i think it doesn't matter because nobody ever mention that in any tutorial or in nextion forum....But i am noob and maybe mistaken? If simulator showed me some data which corresponds to data that i see on serial monitor it is enough for me, i can conclude that sketch with strings is working fine... And that was confusing me when you asked for data being sent to arduino because i still don't know what else could i post to you... We can go on like this for decades but i don't see any purpose, you helped me a lot and your tutorial on serial input basics is great... If you want the picture from nextion editor you have the link to picture below... King regards
Sorry. I don't know anything about Nextion devices and have no wish to learn. I had assumed you would have found an item in the data sheet that describes the style in which data is sent.
Robin2:
Sorry. I don't know anything about Nextion devices and have no wish to learn. I had assumed you would have found an item in the data sheet that describes the style in which data is sent.
...R
Understood... Thanks again for your effort and sorry for misunderstanding