Greetings!
I’m a beginner in Blynk programming and in my first project (garden rover) I encountered a problem displaying float values in a mobile phone widget (in Blynk app v.1.14.2)
I program in Arduino IDE 2.2.1, controller Blue Pill - STM32F103C8T6 (128 kB), wifi via ESP01 4MB, everything works (DC PWM motors, stepper motors, servos, I/O inputs, etc.), just the display of float/double values is not . It’s about the fact that I need to display the values of Li Ion batteries in volts (“batvolt1” variable) measured by the voltage module, but I can’t do it in the form of a float. I tried the commands as per the manual:
BLYNK_WRITE(V7) {
// float batvolt1 = param.asFloat()
or
// double batvolt1 = param.asDouble();
}
same with Timer:
Blynk.virtualWrite(V7, batvolt1);
If the value is an integer, everything works, if it’s a float or double, it doesn’t. The measured values range from 3.2V to 8.4V.
On the Blynk website, I set the Temlate/Datastreams for the V7 virtual pin to type double, I gave the correct range (0-100), but no effect - on the mobile it shows the last value I measured when I had the V7 as an integer. In addition to the value, the mobile application also displays the Gauge (converted to % battery voltage, i.e. an integer value) without any problems.
Due to the size of the project, I only selected the code for the battery, which I am testing on my own:
/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "xxxx"
#define BLYNK_TEMPLATE_NAME "xxxx"
#define BLYNK_AUTH_TOKEN "xxxx"
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "SSID";
char pass[] = "password";
#define EspSerial Serial1
#define VSensor PA0 // Voltage sensor pin on BluePill
float vOUT = 0.0;
float vIN = 0.0;
float R1 = 30000.0;
float R2 = 7500.0;
int battery1 = 0; // voltge of battery No. 1 for Gauge
float batvolt1 = 0; // voltge of battery No. 1 for Value display
unsigned long timer1 = 0; // an auxiliary quantity for determining a WIFI outage
unsigned long timer2 = 0; // an auxiliary quantity for determining a WIFI outage
unsigned long error = 0;
bool WiFistatus = LOW; //WIFI connection status 1= ON, 0= OFF
// This function creates the timer object. It's part of Blynk library
BlynkTimer timer;
/*BLYNK_WRITE(V7) {
float batvolt1 = param.asFloat(); // I have tried this - no effect
}*/
/*BLYNK_READ(V7) { // I have tried this - no effect
Blynk.virtualWrite(V7, batvolt1);
}*/
void myTimer1() { //First timer
Blynk.virtualWrite(V12, battery1); // voltge of battery No. 1 for Gauge
Blynk.virtualWrite(V7, batvolt1); // voltge of battery No. 1 for Value display
}
void myTimer2() { // Second timer
Blynk.virtualWrite(V19, WiFistatus); // WIFI LED status on Widget
}
void setup() {
// Debug console
Serial.begin(115200); // wifi connection
pinMode(VSensor, INPUT); // AC input of Voltage sensor
timer.setInterval(1000L, myTimer1); // Blynk timer
timer.setInterval(500L, myTimer2);
if (Blynk.connected()) { // synchronization of button values in the application with the server
Blynk.syncVirtual(V7);
Blynk.syncVirtual(V12);
Blynk.syncVirtual(V19);
}
}
void loop() {
while (!Blynk.connected()) { // When Blynk is not connected
timer1 = millis(); // it starts counting down the duration of the wifi failure
error = timer1 - timer2; //millis difference from the start of the fault
if (error >= 3000) { // determining the waiting time for a wifi recovery attempt
Blynk.connect();
if (Blynk.connected()) { //synchronization of button values after recovery
Blynk.syncVirtual(V7);
Blynk.syncVirtual(V12);
Blynk.syncVirtual(V19);
}
}
}
WiFistatus = HIGH; // Widget LED of wifi status on - if no signal, after 1 sec. V19 set to OFF
// Analog Voltage sensor calculation:
int value = analogRead(VSensor);
vOUT = (value * 3.3) / 1024.0;
vIN = vOUT / (R2 / (R1 + R2));
int transfer1 = vIN * 1000; // if I don have float value on display, must have miliVolts
batvolt1 = vIN; // this is problematic float value
battery1 = map(transfer1, 6000, 8400, 0, 100); // Gauge(%) of 6000 - 8400 mV for Li Ion Battery
// runs BlynkTimer
timer.run();
}
Thank you for your help. Radoslav