Use Terminal Widget as a remote serial monitor?

Hi

I would like to send the same data that goes to serial monitor - to Terminal Widget.
Does anyone know if that is possible, and how it is done if so

Regards Lasse

Hello. Yes this is possible. Just forward all data you are writing to serial monitor to Blynk.virtualWrite

1 Like

Hi thanks for at quick answer, I am using SoftwareSerial to get serial data from another arduino. I can see these data on my serial monitor. How do i forward these data to Blynk.virtualWrite. Do you have an example… :slight_smile:

void loop()
{
// SoftwareSerial communication loop
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
Blynk.run();
}

just use Blynk.virtualWrite(V1, Serial.read() ) to send it to the terminal attached to V1 on your dashboard :slight_smile: Should be quite simple I think. You’re giving me ideas too, lol.

Just tried that, but i’m getting flood error (could be solved with a timer), some data is present but only random numbers, no text - hmmmmm what to do ? Any other thoughts

loop should only have blynk.run & timer.run in it

all else goes under simpleTimer called functions

for example:

/**************************************************************
 * Blynk is a platform with iOS and Android apps to control
 * Arduino, Raspberry Pi and the likes over the Internet.
 * You can easily build graphic interfaces for all your
 * projects by simply dragging and dropping widgets.
 *
 *   Downloads, docs, tutorials: http://www.blynk.cc
 *   Blynk community:            http://community.blynk.cc
 *   Social networks:            http://www.fb.com/blynkapp
 *                               http://twitter.com/blynk_app
 *
 * Blynk library is licensed under MIT license
 * This example code is in public domain.
 *
 **************************************************************
 * Blynk can provide your device with time data, like an RTC.
 * Please note that the accuracy of this method is up to several seconds.
 *
 * App project setup:
 *   RTC widget on V5
 *   Value Display widget on V1
 *   Value Display widget on V2
 *
 * WARNING :
 * For this example you'll need SimpleTimer library:
 *   https://github.com/jfturcot/SimpleTimer
 *
 * And also this Time keeping library:
 *   https://github.com/PaulStoffregen/Time
 *
 * This code is based on an example from the Time library:
 *   https://github.com/PaulStoffregen/Time/blob/master/examples/TimeSerial/TimeSerial.ino
 *
 **************************************************************/

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>
#include <TimeLib.h>
#include <WidgetRTC.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";

SimpleTimer timer;

WidgetRTC rtc;

BLYNK_ATTACH_WIDGET(rtc, V5);

// Utility function for digital clock display: prints preceding colon and leading 0
void printDigits(int digits)
{
  Serial.print(":");
  if (digits < 10) {
    Serial.print('0');
  }
  Serial.print(digits);
}

// Digital clock display of the time
void clockDisplay()
{
  // You can call hour(), minute(), ... at any time
  // Please see Time library examples for details

  String currentTime = String(hour()) + ":" + minute() + ":" + second();
  String currentDate = String(day()) + " " + month() + " " + year();
  Serial.print("Current time: ");
  Serial.print(currentTime);
  Serial.print(" ");
  Serial.print(currentDate);
  Serial.println();

  // Send time to the App
  Blynk.virtualWrite(V1, currentTime);
  // Send date to the App
  Blynk.virtualWrite(V2, currentDate);
}

void setup()
{
  Serial.begin(9600); // See the connection status in Serial Monitor
  Blynk.begin(auth);

  while (Blynk.connect() == false) {
    // Wait until connected
  }

  // Begin synchronizing time
  rtc.begin();

  // Other Time library functions can be used, like:
  //   timeStatus(), setSyncInterval(interval)...
  // Read more: http://www.pjrc.com/teensy/td_libs_Time.html

  // Display digital clock every 10 seconds
  timer.setInterval(10000L, clockDisplay);
}

void loop()
{
  Blynk.run();
  timer.run();
}

I think you should catch the serial data in an array and send that array with SimpleTimer, as Dave indicated, every 500ms or so to the serial monitor. I think the latency will hardly be noticeable.

Thanks guys,
I will look into SimpleTimer and see if it is possible with that. I will post the results…

Hi
This is the code, and it works.
There is a little problem, if there is no activity between my arduino’s and blynk server for a couple of hours, the connection goes dead, and is only coming up if i reset arduino’s.

Is my code bad, or should i look elsewhere for this problem.

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <UIPEthernet.h>
#include <BlynkSimpleUIPEthernet.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(3, 2); // RX, TX
WidgetTerminal terminal(V1);
WidgetLED LED1(V0);

// You should get Auth Token in the Blynk App.
char auth[] = "your token";

// Input from Alarm Arduino true state for alarm On Off (On = HIGH)
const int AlarmStatRead = 4;

// Variabel
int AlarmLedOnOff = 0;
int Old_AlarmLedOnOff = 0;

// Setup network static IP  
// Mac address should be different for each device in your LAN
byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress server_ip (46, 101, 143, 225);
IPAddress arduino_ip ( 192, 168,   1, 160);
IPAddress dns_ip     (  8,   8,   8,   8);
IPAddress gateway_ip ( 192, 168,   1,   1);
IPAddress subnet_mask(255, 255, 255,   0);

void setup()
{
  // initialize pins as input and output
  pinMode(AlarmStatRead, INPUT);
  Serial.begin(9600);

  // SoftwareSerial communication setup
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);

  Blynk.begin(auth, server_ip, 8442, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
  // You can also specify server.
  // For more options, see BoardsAndShields/Arduino_Ethernet_Manual example
}

void loop()
{
  // read the state of Alarm input to variables
  AlarmLedOnOff = digitalRead(AlarmStatRead);
  
  // Check if Alarm is On or Off - Only run the (if/else(function)) when input changed  
  if  (AlarmLedOnOff != Old_AlarmLedOnOff){ 
     if  (AlarmLedOnOff == HIGH){
          LED1.on();
          Old_AlarmLedOnOff = AlarmLedOnOff;    
     }else{
          LED1.off();
          Old_AlarmLedOnOff = AlarmLedOnOff;    
     }
  }

  // Sent serial data to Blynk terminal - Unlimited string readed
  String content = "";  //null string constant ( an empty string )
  char character;
      while(mySerial.available()) {
         character = mySerial.read();
         content.concat(character);  
      }
      if (content != "") {
         Blynk.virtualWrite (V1, content);
  }
   Blynk.run();
}

@Griffelinos why did you ignore the fix provided by @Lichtsignaal i.e use SimpleTimer?

Honestly i couldn’t get i to work. I tried to use simple.timer, but my connections to Blynk server was very unstable, and output on my Arduino didn’t work. Here is the code i tried with simple.timer. I’m a rookie in programming so it can probably be improved.

#define BLYNK_DEBUG
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <UIPEthernet.h>
#include <BlynkSimpleUIPEthernet.h>
#include <SoftwareSerial.h>
#include <SimpleTimer.h>

SoftwareSerial mySerial(3, 2); // RX, TX
WidgetTerminal terminal(V1);
WidgetLED LED1(V0);

char auth[] = "MY TOKEN";

// Input og output from Alarm Arduino true state for alarm On Off (On = HIGH)
const int AlarmStatRead = 4;
const int Bly_AlarmOnOff = A0;

// Variabel
int AlarmLedOnOff = 0;
int Old_AlarmLedOnOff = 0;

// Setup network static IP  
// Mac address should be different for each device in your LAN
byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress server_ip (46, 101, 143, 225);
IPAddress arduino_ip ( 192, 168,   1, 160);
IPAddress dns_ip     (  8,   8,   8,   8);
IPAddress gateway_ip ( 192, 168,   1,   1);
IPAddress subnet_mask(255, 255, 255,   0);

// the timer objects
SimpleTimer timer1;
SimpleTimer timer2;

void setup() {
  // initialize pins as input and output
  pinMode(AlarmStatRead, INPUT);
  pinMode(Bly_AlarmOnOff, OUTPUT);
  digitalWrite(Bly_AlarmOnOff, HIGH); // pull up A0 - also alarm on when reboot
  Serial.begin(9600);
  
  // SoftwareSerial communication setup
  while (!Serial) {
  ; // wait for serial port to connect. Needed for native USB port only
  }

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);

  Blynk.begin(auth, server_ip, 8442, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
  
  timer1.setInterval(500, Alarm_On_Off);
  timer2.setInterval(500, Sent_serial);
}

  // Subrutine alarm on off ( timer1 )
  void Alarm_On_Off() {
         // read the state of Alarm input to variables
         AlarmLedOnOff = digitalRead(AlarmStatRead);
         // Check if Alarm is On or Off - Only run the (if/else(function)) when input changed  
         if  (AlarmLedOnOff != Old_AlarmLedOnOff){ 
            if  (AlarmLedOnOff == HIGH){
                 LED1.on();
              Old_AlarmLedOnOff = AlarmLedOnOff;    
           }else{   
                 LED1.off();
              Old_AlarmLedOnOff = AlarmLedOnOff;    
           }
         }
  }
  
  // Subrutine sent serial data to blynk terminal widget (timer2 )
  void Sent_serial() {
         // Sent serial data to Blynk terminal - Unlimited string readed
         String content = "";  //null string constant ( an empty string )
         char character;
         while(mySerial.available()) {
              character = mySerial.read();
              content.concat(character);  
         }
         if (content != "") {
              Blynk.virtualWrite (V1, content);
         }  
  }

void loop() {
  Blynk.run();
  timer1.run();
  timer2.run();
}

You just need timer.run not 2 instances of SimpleTimer. With each instance you can have 10 timers.

Hi Costas

Didn’t understand the timer part at first, but got it working. Here is the code… Thanks for the advise

#define BLYNK_DEBUG
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <UIPEthernet.h>
#include <BlynkSimpleUIPEthernet.h>
#include <SoftwareSerial.h>
#include <SimpleTimer.h>

SoftwareSerial mySerial(3, 2); // RX, TX
WidgetTerminal terminal(V1);
WidgetLED LED1(V0);

char auth[] = "Your Token";

// Input og output from Alarm Arduino true state for alarm On Off (On = HIGH)
const int AlarmStatRead = 4;
const int Bly_AlarmOnOff = A0;

// Variabel
int AlarmLedOnOff = 0;
int Old_AlarmLedOnOff = 0;

// Setup network static IP  
// Mac address should be different for each device in your LAN
byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress server_ip (46, 101, 143, 225);
IPAddress arduino_ip ( 192, 168,   1, 160);
IPAddress dns_ip     (  8,   8,   8,   8);
IPAddress gateway_ip ( 192, 168,   1,   1);
IPAddress subnet_mask(255, 255, 255,   0);

// the timer objects
SimpleTimer timer;

void setup() {
  // initialize pins as input and output
  pinMode(AlarmStatRead, INPUT);
  pinMode(Bly_AlarmOnOff, OUTPUT);
  digitalWrite(Bly_AlarmOnOff, HIGH); // pull up A0 - also alarm on when reboot
  Serial.begin(9600);
  
  // SoftwareSerial communication setup
  while (!Serial) {
  ; // wait for serial port to connect. Needed for native USB port only
  }

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);

  Blynk.begin(auth, server_ip, 8442, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
  
  timer.setInterval(1000, Alarm_On_Off);
  timer.setInterval(500, Sent_serial);
}

  // Subrutine ( Alarm_On_Off )
  void Alarm_On_Off() {
         // read the state of Alarm input to variables
         AlarmLedOnOff = digitalRead(AlarmStatRead);
         // Check if Alarm is On or Off - Only run the (if/else(function)) when input changed  
         if  (AlarmLedOnOff != Old_AlarmLedOnOff){ 
            if  (AlarmLedOnOff == HIGH){
                 LED1.on();
              Old_AlarmLedOnOff = AlarmLedOnOff;    
           }else{   
                 LED1.off();
              Old_AlarmLedOnOff = AlarmLedOnOff;    
           }
         }
  }
  
  // Subrutine ( Sent_serial ) data to blynk terminal widget
  void Sent_serial() {
         // Sent serial data to Blynk terminal - Unlimited string readed
         String content = "";  //null string constant ( an empty string )
         char character;
         while(mySerial.available()) {
              character = mySerial.read();
              content.concat(character);
              Serial.println();  
         }
         if (content != "") {
              Blynk.virtualWrite (V1, content);
         }  
  }

void loop() {
  Blynk.run();
  timer.run();
}
3 Likes

But how to read terminals data @Costas

@SlaveDuino extract from one of our sketches that demonstrates string to integer conversion from Terminal, String equal to and String starts with.

 BLYNK_WRITE(V1)  // Terminal
{
  String TerminalString = param.asStr();
  int isitnumerical = TerminalString.toInt();
  if((isitnumerical > 0) && (isitnumerical <1000)){  // check if a number was entered in the terminal and if it was set all 4 timers to use this RF device
    mytimers[0] = isitnumerical;
    mytimers[1] = isitnumerical;
    mytimers[2] = isitnumerical;
    mytimers[3] = isitnumerical;
    EEPROM.write(1, isitnumerical);
    EEPROM.commit();
  }
  if ((String("?") == param.asStr()) || (String("HELP") == param.asStr()) || (String("Help") == param.asStr()) || (String("help") == param.asStr()) ) {
    terminal.println();
    terminal.println();
    terminal.println("Enter the Make & Model of your RF device below.");
    terminal.flush();
  }
  else if((String("L1") == param.asStr())  || (String("l1") == param.asStr()) ) { // turn onboard LED ON
    terminal.println();     
    digitalWrite(LED_PIN, LOW);  // HIGH if using normal active HIGH pins 
    Serial.println(" LED ON");
    terminal.println("LED ON");
    terminal.flush();                 
  }  
  else if((String("L0") == param.asStr())  || (String("l0") == param.asStr()) ) { // turn onboard LED OFF
    terminal.println();
    digitalWrite(LED_PIN, HIGH);  // HIGH if using normal active HIGH pins
    Serial.println(" LED OFF");
    terminal.println("LED OFF");
    terminal.flush();        
  } 
  else if ((TerminalString.startsWith("SET")) || (TerminalString.startsWith("set")) || (TerminalString.startsWith("Set")) ) {
    int lenSET = (TerminalString.length());
    if(lenSET != 8){
      Serial.println("Try again in 24 hour format e.g. 03:20 for 3:20 in the morning and 15:20 for 3:20 in the afternoon.");
      terminal.println();
      terminal.println("Try again in 24 hour format e.g. 03:20 for 3:20 in the morning and 15:20 for 3:20 in the afternoon.");
      terminal.flush();  
    }
    if(lenSET == 8){
      // next line is create new String from 4th position to end of terminal input string
      String Timeadj = TerminalString.substring(3); // 3 is for "SET" removal i.e. posn 1, 2 + 3 removed
      //Serial.println(Timeadj);
      String HouradjStr = TerminalString.substring(3, 5); // 3, 5 is for the hour i.e. posn 4 to 5
      int Houradj = HouradjStr.toInt(); // toInt
      //Serial.println(Houradj);    
      String MinadjStr = TerminalString.substring(6); // 3 is for "SETXX:" removal i.e. posn 1 to 6 removed
      int Minadj = MinadjStr.toInt(); // toInt
      //Serial.println(Minadj);
      int timenow = (Houradj * 60 * 60) + (Minadj * 60);
      setTime(timenow);
      Serial.print("Time now is ");  // just show current time, no updates
      SerialClockDisplay(); 
      clockDisplay();  // update currenttime for terminal
      terminal.println(); 
      terminal.print("Time now is ");
      terminal.println(currenttime);
      terminal.flush(); 
    }
  }
  terminal.flush();
}

Is this what you were looking for?

2 Likes

no i want input for my riddle project for answers… @Costas

Input is done by typing into the terminal.

The answers would need to be stored somewhere, even on the internet, and then sent as output to the terminal or LCD etc.

If users are not going to type in Terminal how do you plan for them to answer the questions? It can be done but just wondering what your plan is.

a single word but how to read terminal there’s no terminal.read program
@Costas

Blynk use the word WRITE where lay people use the word READ :slight_smile:

WRITE in this sense is that the app WRITE’s to your sketch. You then check the answer string against the database of answers to questions to see if it is correct.

This is not specific to Terminal it applies to all (WRITE) transfers from app to sketch.

So the sketch extract for BLYNK_WRITE that I posted above is what you want.

1 Like

Para mostrar el serial (9600) de arduino en la terminal de blynk.
como seria Âż?