Question / bug regrading integrating Wio Terminal use of TFT and Blynk.
If I test the printing of the ligt & sound values on the screen, everything works. If I add the printing to the bkynk example is not working anymore.
Any clues?
• Hardware model + communication type. Wio TErminal + WIFI
• Smartphone OS (iOS or Android) + version: 1.7.6
• Blynk server or local server: Blynk Cloud
• Blynk Library version 1.2.0
• Code in attach (without tokens)
/*************************************************************
Blynk is a platform with iOS and Android apps to control
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
You can easily build mobile and web interfaces for any
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: https://www.blynk.io
Sketch generator: https://examples.blynk.cc
Blynk community: https://community.blynk.cc
Follow us: https://www.fb.com/blynkapp
https://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This example runs directly on Wio Terminal.
NOTE: This requires Wio Terminal Wi-Fi support package:
https://wiki.seeedstudio.com/Wio-Terminal-Network-Overview/
Please be sure to select the right Wio Terminal module
in the Tools -> Board menu!
Change WiFi ssid, pass, and Blynk auth token to run :)
Feel free to apply it to any other example. It's simple!
*************************************************************/
// import tft library
#include "TFT_eSPI.h"
// create tft object
TFT_eSPI tft;
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
/* Fill in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "id"
#define BLYNK_TEMPLATE_NAME "name"
#define BLYNK_AUTH_TOKEN "token"
#include <rpcWiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleWioTerminal.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "WIFI";
char pass[] = "PASW";
// https://docs.blynk.io/en/blynk.apps/widgets-app/button
BLYNK_WRITE(V1) // this command is listening when something is written to V1
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
if (pinValue == 1) {
// do something when button is pressed;
} else if (pinValue == 0) {
// do something when button is released;
}
Serial.print("V1 button value is: "); // printing value to serial monitor
Serial.println(pinValue);
}
void setup() {
// Debug console
Serial.begin(9600);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
tft.begin();
pinMode(WIO_LIGHT, INPUT);
pinMode(WIO_MIC, INPUT);
tft.setRotation(3);
}
void loop() {
tft.setTextColor(0x0);
tft.setTextSize(4);
tft.fillScreen(0xFFFF);
tft.drawString((String)(analogRead(WIO_LIGHT)), 100, 100);
tft.drawString((String)(analogRead(WIO_MIC)), 100, 160);
Blynk.run();
}
/*************************************************************
Blynk is a platform with iOS and Android apps to control
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
You can easily build mobile and web interfaces for any
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: https://www.blynk.io
Sketch generator: https://examples.blynk.cc
Blynk community: https://community.blynk.cc
Follow us: https://www.fb.com/blynkapp
https://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This example runs directly on Wio Terminal.
NOTE: This requires Wio Terminal Wi-Fi support package:
https://wiki.seeedstudio.com/Wio-Terminal-Network-Overview/
Please be sure to select the right Wio Terminal module
in the Tools -> Board menu!
Change WiFi ssid, pass, and Blynk auth token to run :)
Feel free to apply it to any other example. It's simple!
*************************************************************/
// import tft library
#include "TFT_eSPI.h"
// create tft object
TFT_eSPI tft;
BlynkTimer timer; // Announcing the timer
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
/* Fill in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "templae"
#define BLYNK_TEMPLATE_NAME "name"
#define BLYNK_AUTH_TOKEN "token"
#include <rpcWiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleWioTerminal.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "wifi";
char pass[] = "pasw";
// https://docs.blynk.io/en/blynk.apps/widgets-app/button
BLYNK_WRITE(V1) // this command is listening when something is written to V1
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
if (pinValue == 1) {
// do something when button is pressed;
} else if (pinValue == 0) {
// do something when button is released;
}
Serial.print("V1 button value is: "); // printing value to serial monitor
Serial.println(pinValue);
}
void updateScreen() {
tft.setTextColor(0x0);
tft.setTextSize(4);
tft.fillScreen(0xFFFF);
tft.drawString((String)(analogRead(WIO_LIGHT)), 100, 100);
tft.drawString((String)(analogRead(WIO_MIC)), 100, 160);
}
void setup() {
// Debug console
Serial.begin(9600);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
tft.begin();
pinMode(WIO_LIGHT, INPUT);
pinMode(WIO_MIC, INPUT);
tft.setRotation(3);
timer.setInterval(1000L, updateScreen); //timer will run every sec
}
void loop() {
Blynk.run();
timer.run(); // run timer every second
}
Template ID, name, and auth token must be at the top of your sketch. The first lines.
Moving the BlynkTimer class after the header files should solve the issue.
This is because the header files often contain important definitions that are needed by the classes and functions in your code. When you include the header files at the beginning of your code, the compiler will process those definitions first and use them to validate the code that follows.
If you define a class or function before the necessary headers are included, the compiler may not recognize the types or functions used in your code and throw an error. Moving the BlynkTimer class definition after the header files ensures that the necessary definitions are available before the class is defined, which allows the compiler to validate the code correctly.