I’m a bit confused (aren’t we all!).
When I use this approach I use Serial.print for everything. The function then mirrors all of the serial monitor output to the terminal as well. That way, if your device is connected to your PC by serial connection you get the output in the serial monitor, plus it appears in the Blynk terminal screen anyway.
I don’t get any duplication of output.
My version of Sent_serial()
uses Blynk.virtualWrite
instead of terminal.print(content)
and terminal.flush()
Here’s my version, including a switch to disable the terminal output if desired:
void Send_Serial()
{
// Sends serial data to Blynk as well as the serial monitor
//(handy for setups where the MCU isn't connected to serial because OTA is being used)
// Note that a jumper is needed between Tx and Rx, which needs to be removed
// if doing a serial flash upload (but this is not necessary for OTA flash upload)
if (terminal_output_enabled)
{
String content = "";
char character;
while(Serial.available())
{
character = Serial.read();
content.concat(character);
}
if (content != "")
{
Blynk.virtualWrite (Widget_Terminal, content);
}
}
} //end of void Send_Serial
I found it necessary to add this line immediately after Serial.begin, to give a larger serial buffer to avoid lost characters:
Serial.setRxBufferSize(1024); // Increase the serial buffer size
After that, everything is done as a Serial.print and appears in as normal in the serial monitor and in the terminal widget (with a slight lag, as I tend to run my timer every 1000 millis rather than 500), provided the terminal_output_enabled
boolean variable is set to true.
Pete.