Hello,
A new user here…having a blast with Arduino and Blynk…but also not without some noob frustrations. Having some trouble trying to do a simple data push from Andruino Uno to a virtual display on the Blynk App.
Using Blynk 0.4.6.
Arduino Uno R3 with ESP8266-01 (on version 1.1 and set baud rate to 9600)
Her is my code:
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#define BLYNK_DEBUG // Optional, this enables lots of prints
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SimpleTimer.h>
#include <NewPing.h>
//constants to set pin numbers
const int wifiConnectedLED = 8; // the number of LED pin
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "dddddd";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "8675309_ofc";
char pass[] = "pass";
//LED variables
int wifiLEDState = 0; //variable for reading LED pin status
//UltraSonic Sensor Variables
#define TRIGGER_PIN 7 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 400 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
int distance;
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
//Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
SimpleTimer timerCheckConnectionStatus;
SimpleTimer timerDistancePing;
void setup()
{
// Set console baud rate
Serial.begin(9600);
delay(10);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
//init LED pin 8
pinMode(wifiConnectedLED, OUTPUT);
//connect to blynk servers via wifi - easy way
Serial.println("connecting to Blynk...");
Blynk.begin(auth, wifi, ssid, pass);
//set timer interval and function to call for Connection Status LED
Serial.println("Init App LED timer");
timerCheckConnectionStatus.setInterval(3000L, blinkConnectedBoardLed);
Serial.println("App LED timer Initialized");
//set timer interval and function to call for Distance Ping for UltraSonic Sensor
Serial.println("Init Ultra Sonic ping timer");
timerDistancePing.setInterval(3500L, getDistanceTimerFunction);
Serial.println("App Ultra Sonic ping timer Initialized");
}
void loop()
{
Blynk.run();
timerCheckConnectionStatus.run();
timerDistancePing.run();
}
//Check if blynk is connected and set board led accordingly.
void getDistanceTimerFunction()
{
//unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
//distance = uS / US_ROUNDTRIP_IN / 12; // Convert ping time to distance and print result (0 = outside set distance range, no ping echo)
//Serial.print("Ping: ");
//Serial.print(uS / US_ROUNDTRIP_IN / 12);
//Serial.println("FT");
**Blynk.virtualWrite(V3, millis() / 1000);**
}
If I comment out the last line Blynk.virtualWrite(V3, millis() / 1000);
and uncomment all the other lines above it in that function, everything works as expected. But as soon as I uncomment the line Blynk.virtualWrite(V3, millis() / 1000);
, Blynk is reporting Login timeout
errors.
On my app project, I have a Virtual Display. The input is set to V3. The min and max values are 0, 1023 respectively, and the Read Rate is set to PUSH.
Serial Monitor Output:
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
///_, /////_
/__/ v0.4.6 on Arduino Uno
[129] Free RAM: 565
[649] Connecting to 8675309_ofc
[3835] AT version:1.1.0.0(May 11 2016 18:09:56)
SDK version:1.5.4(baaeaebb)
Ai-Thinker Technology Co. Ltd.
Jun 13 2016 11:29:20
OK
[11136]
[11137] Connected to WiFi
[21356] <[02|00|01|00] <auth token here>
[21558] >[00|00|01|00|C8]
[21558] Ready (ping: 24ms).
[21559] <[11|00|01|00]fver[00]0.4.6[00]h-beat[00]10[00]buff-in[00]256[00]dev
[31718] Cmd error
[31763] Login timeout
[47000] <[02|00|01|00] <auth token here>
[47201] >[00|00|01|00|C8]
[47201] Ready (ping: 24ms).
[47202] <[11|00|02|00]fver[00]0.4.6[00]h-beat[00]10[00]buff-in[00]256[00]dev
[57362] Cmd error
[57407] Login timeout
[72647] <[02|00|01|00] <auth token here>
[72858] >[00|00|01|00|C8]
[72858] Ready (ping: 24ms).
[72859] <[11|00|03|00]fver[00]0.4.6[00]h-beat[00]10[00]buff-in[00]256[00]dev
[83020] Cmd error
[83064] Login timeout
this keeps repeating…
Incidentally, a couple of noob questions I could find concrete answers for:
- is the first argument for
virtualWrite
supposed to be an integer (so3
in this case) orV3
?..I’ve seen it both ways in the code examples. - In the app, for the Virtual DIsplay Settings, what are the min and max values (the default is 0 and 1023)…what does that mean, or how do they need to be adjusted?
Thanks in Advance,
Chad