Is there a more graceful method of sending multiple variables over the serial port besides, the following:
Serial.println(variableName);
Serial.println(delimeter);
Serial.println(variableName);
Serial.println(delimeter);
Serial.println(variableName);
Serial.println(delimeter);
…
etc.
This works fine, but it just seems amateur. I’ve thought about using an array with a loop
to cycle through all of the indexes, however there are different data types involved.
Upon getting this question sorted, I’d also like to move away from string data as I realize
it’s not as efficient.
I dont' know of one, but am not the go-to guy for this.. I will say that I use Serial.print for all but the last one where I use Serial.println.. that way it all ends up on one line.
You'll probably have to do some further research and experimentation. Transmitting structured data (the re-assembling it on the other end) is not an easy process.
More can be found by googling "arduino serial print struct" - just take note about the "ton of gotcha's" that you have to keep in mind as you code and debug. These alone might just make you want to go back to the "normal" way. I would almost say the only time you should consider using structures would be if there were multiple (different) structures to be sent for some reason. Even there, it might be better to build some kind of struct parser that dumps the data out using serial prints, etc.
YellowGTM:
If 30 lines of Serial.print is the answer, then who am I to argue?
if you are writing similar code doing 30 times a similar thing, then most likely the data in your program are not well structured.
If I'd write a program that sends 30 sets of data, the code would possibly read something like:
for (int i=0;i<30;i++) sendData(i);
And "sendData()" would be a function that takes an index as a parameter and then do the right thing, such like perhaps retrieving the data name and data value from an indexed array and send them out.
I know when sending data to my arduino (via C++ on a PC) I discovered that delimiters and/or ID's were redundant (for my project). Upon ditching both and sending what I call 'raw' data I increased the rate of actualdata per unit time by a huge factor.
I also learned there is a small but significant overhead for each individual transfer that can be minimised by sending larger chunks of data per 'send', the drawback of this is increased latency.
Can't see why these factors aren't also relevant in sending from arduino ... is it more restricted in it's serial send methods?