Hi first of all sorry for my english, but I’m using google translator.I am an electrical engineer but with a passion to program.Premessed that I come to my problem.I would need to read data from the serial of arduino on the terminal blynk.Sto using arduino mega and Arduino ESP8266 Wifi Shield version 1.0 by Wang Tongzi ". On mega I entered the following scheck
const int buttonPin = 11; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
int buttonState = 0;
void setup() {
// initialize both serial ports:
// Serial.begin(9600);
Serial2.begin(9600);
Serial.begin(115200);
Serial1.begin(115200);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop() {
//------------------
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
//Serial.print("led on");
Serial2.print("led on");
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
if(Serial.available()) {
char a = Serial.read();
delay(10);
Serial1.write(a);
while(!Serial.available())
{ }
char b = Serial1.read();
Serial.print("Arduino UNO ha risposto ");
Serial.println(b);
char c = Serial2.read();
Serial.print("Arduino UNO ha risposto ");
Serial.println(b);
delay(100);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
//Serial.print("led on");
Serial2.print("led on");
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
}
while on blynk
BLYNK_WRITE(V1)
{
// if you type "Marco" into Terminal Widget - it will respond: "Polo:"
if (String("Marco") == param.asStr()) {
terminal.println("You said: 'Marco'") ;
terminal.print(EspSerial.read());
terminal.println("I said: 'Polo'") ;
} else {
// Send it back
terminal.print("You said:");
terminal.write(param.getBuffer(), param.getLength());
terminal.println();
}
I have also done other tests but I can not read the data I send from the Arduino. How can I resolve, where I am wrong? I hope he did not mess up when posting the schecks.
I also hope I did not mess up in the presentation
If I am interpreting your needs correctly… there have been a few topics on similar attempts… tricky it is Search this forum for keywords like Serial Terminal, Debug, etc.
I managed to follow in a developers footprints and send debug serial (Blynk Debug) to LCD & OLED displays… that same technique can be used to send the data to the App’s terminal… but not any good for troubleshooting since if the device is not connected in the first place, then… well… no terminal action
BTW, I needed to fix your topic as the correct way to format posted code is like this…
And your sketch is not what we call “Blynk Friendly”…
You would need to put your if (Serial.available()) into fast running timed functions else you risk Blynk disconnections while waiting for Serial data. yes this could mean loss of incoming Serial data, but there are limits to what an Arduino can do.
Using an Arduino Mega with ESP-01 as WiFi shield. Entering my serial text via the IDE Serial Monitor on the primary Serial port and sending it to the Terminal on V0 via a Blynk.virtualWrite() command on a timed function.
In pre-setup…
String content = "";
char character;
in void setup() after the Blynk connection is made
timer.setInterval(10L, SerialInput); // Run every 10ms
Blynk.virtualWrite(V0, "clr"); // Clear the terminal from past info.
Then in it’s own function…
void SerialInput() {
if (Serial.available()) { // Watch for Serial data
character = Serial.read(); // Read Serial character
content.concat(character); // Add character to holding String
if (character == '\n'){ // If last character is new line...
Blynk.virtualWrite(V0, content); // ...send string to terminal
content = ""; // Clear holding String
}
}
}
First of all thank you for answering me. Then I think I entered the code in the tags as I had to do. I did as you told me, or rather I think I followed your instructions but I do not want to re-issue my blynk side code.But it does not go
pressing V0 does not cancel the terminal but adds 01
#define BLYNK_PRINT Serial
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
SoftwareSerial SwSerial(4, 5); // RX, TX// in Blynk app writes values to the Virtual Pin 1
#define BLYNK_PRINT SwSerial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
WidgetTerminal terminal(V1);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Diego4";//
char pass[] = "xxxxxxxx";
//----------
// This function will be called every time Slider Widget
//.........................
String content = "";
char character;
BlynkTimer timer;
//................
void setup()
{
// Debug console
Serial.begin(115200);
SwSerial.begin(115200);
EspSerial.begin(115200);
Blynk.begin(auth, ssid, pass);
// ----------------------------
timer.setInterval(10L, SerialInput); // Run every 10ms
Blynk.virtualWrite(V0, "clr"); // Clear the terminal from past info.
//----------------------------------
// timer.setInterval(500, Sent_serial);//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}
void SerialInput() {
if (Serial.available()) { // Watch for Serial data
character = Serial.read(); // Read Serial character
content.concat(character); // Add character to holding String
if (character == '\n'){ // If last character is new line...
Blynk.virtualWrite(V0, content); // ...send string to terminal
content = ""; // Clear holding String
terminal.print(Serial.read());
}
}
}
void loop()
{
Blynk.run();
timer.run();
}
I correct now I do not know how it seems to work almost as I say.
Another question how do I clean up the terminal? When I press V0 it does not clean up anything
But I was using the standard Blynk.virtualWrite() commands to send all the data to the terminal, just like any other display type widget, not the terminal.___() commands, which seem to sometimes contribute to duplication issues?? Basically I never use them
Thus in my example V0 was the Terminal Widget and I cleared it at device boot by sending the string “clr” to it
Hi I have inserted the comandoterminal clear in the app but does not delete anything keeps writing the status of the pin V0.Only closing and reopening the app delete but not to the pressure of V0
if (Serial.available()) { // Watch for Serial data
character = Serial.read(); // Read Serial character
content.concat(character); // Add character to holding String
if (character == '\n'){ // If last character is new line...
Blynk.virtualWrite(V0, content); // ...send string to terminal
content = ""; // Clear holding String
terminal.print(Serial.read());
Blynk.virtualWrite(V0, "clear");
}
My example did NOT use the terminal.print() commands… Instead it used the Blynk.virtualWrite(V0) command for ALL terminal prints… assuming the terminal is actually set to V0, if not then adjust accordingly.
And it is “clr”, NOT “clear” when using this method.
Hi I solved with the cancellation of the terminal thanks to your tips.Now I have a new domamda to get you, I’m sorry if I take advantage of Blynk but are completely unaware, I’ll explain what I would like to achieve.I would like when I turn on a led on arduino he send the answer on blynk maybe turning on a virtual led. Can you do? What are the commands to use? Thanks
{
int pinValue = param.asInt();
if (pinValue==HIGH){
Blynk.virtualWrite(V0, "clr");//ripulisce il terminale
}
}
You would use the same basic Blynk.virtualWrite() command, only this time to the vPin of your LED. Also, the virtual LED Widget emulates a PWM controlled LED, so 0 = OFF & 1 through 255 = varying intensities of ON.
Thus with a LED widget set to V1 you would use this command to fully “light up” the LED
Blynk.virtualWrite(V1, 255);
As for doing such when you turn on a physical LED… that depends on how you are activating said physical LED.
You would use the same basic Blynk.virtualWrite() command, only this time to the vPin of your LED. Also, the virtual LED Widget emulates a PWM controlled LED, so 0 = OFF & 1 through 255 = varying intensities of ON.
Thuis with a widget set to V1 you would use this command to fully "light up the LED
Blynk.virtualWrite(,V1, 255);
As for doing such when you turn on a physical LED… that depends on how you are activating said physical LED.
Why my code works in the middle? I explain, I send the data on the serial VI changes status and turns on, but when non I send more data is always on I debbo it off manually. Where am I wrong?
void SerialInput() {
//.................
//.....................
if (Serial.available()) { // Guarda i dati seriali se cìè qualcosa in arrivo
character = Serial.read(); // Leggi il carattere seriale
content.concat(character); // Aggiungi carattere a stringere String
if (character == '\n') { // Se l'ultimo carattere è una nuova riga
Blynk.virtualWrite(V0, content); // invia una stringa al terminale
content = ""; // Clear holding String
//________________
if (content != "Cucina")
{
Blynk.virtualWrite(V1, HIGH);
led1.on();
}
else{
led1.off();
}
Well… since like with the terminal before, you insist on using the widget specific method of control instead of my recommended Blynk.virtualWrite() method… did you at least register the led1() & led2() reference to the vPin as required for that method??
As per them pesky documentations we keep referring to people…
Nothing I rewrote following your instructions, at least I think, but nothing.
Regarding the widgetled I’m following the examples because I do not know how to use the command Blynk.virtualWrite () I tried to insert led1.on but it gives me error. Blynk.virtualWrite (V1, led1.on ())
The comparison of the string is as if it did not happen, because it does not go anything after the if
//.........................
String content = "";
char character;
BlynkTimer timer;
//...............
//................
BLYNK_WRITE(V2)
{
int pinValue = param.asInt();
if (pinValue == HIGH) {
Blynk.virtualWrite(V0, "clr");
Blynk.virtualWrite(V1, LOW);
led1.off();
led2.off();
}
}
//............
void setup()
{
// Debug console
Serial.begin(9600);
//SwSerial.begin(115200);
//EspSerial.begin(115200);
Blynk.begin(auth, ssid, pass);
// ----------------------------
timer.setInterval(10L, SerialInput); // Run every 100ms
Blynk.virtualWrite(V0, "clr"); // Clear the terminal from past info.
//----------------------------------
// timer.setInterval(500, Sent_serial);//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}
void SerialInput() {
//.................
//.....................
if (Serial.available()) { // Guarda sulla seriali se ci sono dati in arrivo
character = Serial.read(); // Leggi il carattere seriale
content.concat(character); // Aggiungi carattere a stringere String
if (character == '\n') { // Carattere speciale che indica fine riga
Blynk.virtualWrite(V0, content); // invia una stringa al terminale
// content = ""; // Clear holding String
Serial.print(content);
//________________
if (content == "Cucina")
{
Serial.print(content);
Blynk.virtualWrite(V1, 255);
led1.on();
}
else{
led1.off();
}
//----------------------
if (content == "Luci1")
{
Serial.print(content);
Blynk.virtualWrite(V1,255);
led2.on();
}
else{
led2.off();
}
//----------------------
content = ""; // Clear holding String
}
}
Serial.flush();//svuoto il buffer
}
void loop()
{
Blynk.run();
timer.run();
}