I have a little program that logs temp and rh, My arduino sends out a string of data every 4 seconds consisting of ints and a "]" at the end which i split in processing and assign to variables, I have a few buttons on my app, button 1 resets graph cursor to 0, resetting the graph output on screen, the second button sends a "1" down the serial port, when the arduino receives this it resets the max/min values held on eprom to the current temp/rh/time/date. The 3rd button sends a 2 done the serial port and the arduino reads all the stored historic data from these sensors and sends it to the serial port, on the arduino serial monitor everything seems to be working fine, i type 2 and the arduino stops sending out usual data stream, reads the eprom and sends all the data followed by an "@".
Whats the best way of getting processing recognising the new datastream? Im thinking i need to add start of string markers or something like that and incorporate it into my serialEvent, im a little unsure how to go about that, or can I make another function that handles this new stream by itself?
can I make another function that handles this new stream by itself?
No. One serial port == one serial event. The serial port has no idea what the bits coming down that port might mean.
Whats the best way of getting processing recognising the new datastream?
The "best" way is to stop thinking of it as a new data stream. The stream of data, no matter how intermittent, continues. The difference is what the data in that stream means to the receiving application.
You have each packet being sent use a different end of packet marker. Using the end of packet markers is good. Now, add a start of packet marker, too. Use a different start of packet marker for the two different kinds of packets, and react accordingly.
Personally, I like symmetric markers, like < and > or [ and ] or { and }, rather than asymmetric markers like nothing and ] or nothing and @, but, the choice of markers is up to you.
Your right its not a new datastream to the serial port cos it just reads what I tell it too read depending on the end packet marker, Ok so I have changed my arduino to send out the 4sec data between "[" and "]", i changed the extra data that i will send when the button is press so the start and end marker is "{" and "}" on the serial monitor everything seems to be working fine.
On processing Im a little unsure how to read the start marker, Im using myport.read() and no data is coming through, I also used readChar() still nothing happening, Ill post my serialEvent
In my setup() i forgot to change bufferUntil('*') to ('\n'), I dont really get what your saying?
Im having more success with this serialEvent, at least its graphing out the the selection of '[' but when i press the button on application the program pauses for 5 seconds then carries on, it doesnt get as far as print("Max/Min").
Suppose that this function gets called, and the serial buffer contains "[SomeData]". You read the first character ('['), and determine that it is a open square bracket. So, you read the rest of the data.
Now, suppose that this function gets called with "{SomeData}". You read the first character ('{'), and determine that it is not a open square bracket. Then, you read the next character ('S'), and determine that it is not a open curly brace, so you delete the rest of the data in the serial buffer.
You need to read AND STORE the first character. Then, test whether that character is a [. If it is, do something.
Then, test whether that first character is a {, instead of reading another character.
Hi, Ive been at Uni this week so didnt have much time to work on it, I have put myport.read() through switch() and Im having better success, is it better to store myport.read() in a variable or no difference to just use switch(myport.read()) ?
is it better to store myport.read() in a variable or no difference to just use switch(myport.read()) ?
If you store the value read, you can use it more than once. The switch statement effectively does that. Which to use depends on how many cases there are. One or two, save the value and use if statements. More than a dozen? The switch statement is better. In between? Your call.