I am somewhat new to this Arduino (Pro Mini) world, but I am very thrilled about it.
I use the serial monitor a lot to troubleshoot for programming errors.
Is there a way to limit the messages so that the board only sends information to the PC (serial monitor) when there is a change in the monitored values ?
I can see that it can be done when com is from PC to Arduino by using the Serial.available command.
You are using Serial.print to send debug messages from your Pro Mini to the serial console running on your PC ?
In that case, you have full control over when you issue a Serial.print.
Hint. Detecting a change in something, requires remembering what state it was previously in.
In my program I send let's say 5 registers using "serial.print" (the last one using "serial.println")
This way I see all the values on one line followed by a println command for a new line.
But the lines are sent even though there is no change within the 5 registers.
I would like to condition the "serial.print" commands to only get sent if there is a change in at least one of them.
As far as I understand, the command "serial.available() >0" can in some cases be used to condition program routines to only react when data is being present at the serial Rx port.
I just wondered if there was any command to be used when com going in the opposite direction - from Arduino to the PC that is.
texasflood_dk:
In my program I send let's say 5 registers using "serial.print" (the last one using "serial.println")
This way I see all the values on one line followed by a println command for a new line.
But the lines are sent even though there is no change within the 5 registers.
I would like to condition the "serial.print" commands to only get sent if there is a change in at least one of them.
As far as I understand, the command "serial.available() >0" can in some cases be used to condition program routines to only react when data is being present at the serial Rx port.
I just wondered if there was any command to be used when com going in the opposite direction - from Arduino to the PC that is.
There is. It's called the if statement.
Pseudocode:
if saved value not equal to value
{
send value
set saved value to value
}
I know the "if" statement. and I have in mind to actually do it like you describe.
But I would like not to do this with each and every single register I send using the "serial_print" command.
Please excuse me for having a hard time describing this properly..
Let us say I was sending 16 boolean values using the "serial.print" command.
After sending these 16 bits using the "serial.print" command, I could save the bit pattern in a word.
(like "set saved value to value" in your pseudocode)
I could then condition the next "serial.print" command to only be issued if the saved word was different with the present word value (of the 16 bits).
This way I could condition all the "serial.print" commands by only one "if" statement.
But can something similar be done when sending other datas than boolean data ?
texasflood_dk:
I am somewhat new to this Arduino (Pro Mini) world, but I am very thrilled about it.
I use the serial monitor a lot to troubleshoot for programming errors.
Is there a way to limit the messages so that the board only sends information to the PC (serial monitor) when there is a change in the monitored values ?
Of course you are free to send values only if they are different from apreviously sent value.
Pseudo programming logic:
if (currentvalue!= oldvalue)
{
Serial.print (currentvalue); // send this value
oldvalue=currentvalue; // remember that we have sent this value
}
texasflood_dk:
I know the "if" statement. and I have in mind to actually do it like you describe.
But I would like not to do this with each and every single register I send using the "serial_print" command.
. . .
The point is that you do not have to do it for each individual register value. You build up in a variable your output string consisting of all the register values interspersed with comments punctuation etc. Just before you print out the string, you compare it with the last copy actually sent. If it is the same, simply don't print it.
6v6gt:
The point is that you do not have to do it for each individual register value. You build up in a variable your output string consisting of all the register values interspersed with comments punctuation etc. Just before you print out the string, you compare it with the last copy actually sent. If it is the same, simply don't print it.
See C++ string class
This was what I was looking for :0)
Now I just have to see if I can manage to build up such a string...
If someone knows of any examples of this, please post.
But many thanks 6v6gt
(a nice tube btw - I have 6L6's in my guitar amp...)