How is your datastream for V10 configured, and what widget do you have attached to that datastream?
Pete.
How is your datastream for V10 configured, and what widget do you have attached to that datastream?
Pete.
my configuration
and I use a LABEL.
my value does not change it remains at zero on application on my screen and on the serial monitor
Making that clear in your first post would have been useful.
You don’t appear to be calling the calhum() function, so readings aren’t being taken. Adding a simple serial print statement into the function would have made that clear.
Also, you’re making a few basic mistakes, such as calling two functions at exactly the same time…
and using delays…
Pete.
I grouped all the humidity part in the same function. The value is displayed on the application, on the screen.
#include <SPI.h>
#define BLYNK_TEMPLATE_ID "xxxxx"
#define BLYNK_DEVICE_NAME "xxxxx"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
// Uncomment your board, or configure a custom board in Settings.h
//#define USE_WROVER_BOARD
#include "BlynkEdgent.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#include <FastLED.h>
#define NUM_LEDS 4
#define DATA_PIN 13
CRGB leds[NUM_LEDS];
const int relais1 = 14;
const int btn1 = 26;
const int relais2 = 32;
const int btn2 = 27;
const int relais3 = 15;
const int btn3 = 25;
const int relais4 = 12;
const int btn4 = 19;
// one wire temperature
#define ONE_WIRE_BUS 23
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int deviceCount = 3;
float tempC;
int relais1Sate = LOW;
int btn1State = HIGH;
int relais2Sate = LOW;
int btn2State = HIGH;
int relais3Sate = LOW;
int btn3State = HIGH;
int relais4Sate = LOW;
int btn4State = HIGH;
int brightness = 50;
int lcd_position[] = {16, 30, 44}; // position temperature sur l'écran
BLYNK_WRITE(V1) {
relais1Sate = param.asInt();
Serial.print("Widget Button V1 changed. Writing ");
Serial.print(relais1Sate);
Serial.print(" to Relay 1 and LED V1, and ");
Serial.print(!relais1Sate);
Serial.println(" to LED R1 ...");
digitalWrite(relais1, !relais1Sate);
if (!relais1Sate) {
leds[0] = CRGB::Red;
}
if (relais1Sate) {
leds[0] = CRGB::Green ;
}
FastLED.show();
}
BLYNK_WRITE(V2) {
relais2Sate = param.asInt();
digitalWrite(relais2, !relais2Sate);
if (!relais2Sate) {
leds[1] = CRGB::Red;
}
if (relais2Sate) {
leds[1] = CRGB::Green ;
}
FastLED.show();
}
BLYNK_WRITE(V3) {
relais3Sate = param.asInt();
digitalWrite(relais3, !relais3Sate);
if (!relais3Sate) {
leds[2] = CRGB::Red;
}
if (relais3Sate) {
leds[2] = CRGB::Green ;
}
FastLED.show();
}
BLYNK_WRITE(V4) {
relais4Sate = param.asInt();
digitalWrite(relais4, !relais4Sate);
if (!relais4Sate) {
leds[3] = CRGB::Red;
}
if (relais4Sate) {
leds[3] = CRGB::Green ;
}
FastLED.show();
}
const int dry = 3540; // value for dry sensor // Moisture Sensor
const int wet = 1246; // value for wet sensor // Moisture Sensor
int percentageHumididy; // Moisture Sensor
void humidite() // Moisture Sensor
{
int sensorVal = analogRead(33); // Moisture Sensor
int percentageHumididy = map(sensorVal, wet, dry, 100, 0); // Moisture Sensor
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.clearDisplay();
display.setCursor(0, 0);
display.println("---------------------");
display.setCursor(0, 6);
display.print("| Humidite du sol |");
display.setCursor(0, 12);
display.println("---------------------");
display.display();
display.setTextSize(4);
display.setCursor(16, 20); //Moisture Sensor
display.print(percentageHumididy); //Moisture Sensor
display.println("%"); //Moisture Sensor
display.display(); //Moisture Sensor
Serial.print(percentageHumididy); //Moisture Sensor
Serial.println("%"); //Moisture Sensor
Blynk.virtualWrite(V10, percentageHumididy); //Moisture Sensor
}
void temperature()
{
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0, 0);
display.println("---------------------");
display.setCursor(0, 6);
display.print("| Temperature |");
display.setCursor(0, 12);
display.println("---------------------");
display.setCursor(0, 16); // position 0
display.println(" Interieur |");
display.print("---------------------");
display.display();
display.setCursor(0, 30); // position 1
display.println(" Exterrieur |");
display.print("---------------------");
display.display();
display.setCursor(0, 44); // position 2
display.println(" Eau |");
display.print("---------------------");
display.display();
// Send command to all the sensors for temperature conversion
sensors.requestTemperatures();
// Display temperature from each sensor
for (int i = 0; i < deviceCount; i++)
{
tempC = sensors.getTempCByIndex(i);
Blynk.virtualWrite(i + 21, tempC);
display.setCursor(80, lcd_position[i]);
display.print(tempC);
display.display();
}
}
void checkPhysicalButton1()
{
if (digitalRead(btn1) == LOW)
{
Serial.print("Location A, btn1 = ");
Serial.print(digitalRead(btn1));
Serial.print(" btn1State = ");
Serial.println(btn1State);
// btnState is used to avoid sequential toggles
if (btn1State != LOW)
{
Serial.print("Location B, btn1 = ");
Serial.print(btn1);
Serial.print(", btn1State = ");
Serial.println(btn1State);
// Toggle LED state
relais1Sate = !relais1Sate;
Serial.print("Location C, writing ");
Serial.print(relais1Sate);
Serial.println(" to Relay 1 ...");
digitalWrite(relais1, !relais1Sate);
if (!relais1Sate) {
leds[0] = CRGB::Red;
}
if (relais1Sate) {
leds[0] = CRGB::Green ;
}
FastLED.show();
Serial.print("Location D, writing ");
Serial.print(!relais1Sate);
Serial.print(" to LED V1 and ");
Serial.print(relais1Sate);
Serial.println(" to LED R1 ...");
// Update Button Widget
Serial.print("Location E, writing ");
Serial.print(relais1Sate);
Serial.println(" to Button Widget on pin V1 ...");
Blynk.virtualWrite(V1, relais1Sate);
btn1State = LOW;
}
}
else
{
btn1State = HIGH;
}
if (digitalRead(btn2) == LOW)
{
// btnState is used to avoid sequential toggles
if (btn2State != LOW)
{
// Toggle LED state
relais2Sate = !relais2Sate;
digitalWrite(relais2, !relais2Sate);
if (!relais2Sate) {
leds[1] = CRGB::Red;
}
if (relais2Sate) {
leds[1] = CRGB::Green ;
}
FastLED.show();
// Update Button Widget
Blynk.virtualWrite(V2, relais2Sate);
btn2State = LOW;
}
}
else
{
btn2State = HIGH;
}
if (digitalRead(btn3) == LOW)
{
// btnState is used to avoid sequential toggles
if (btn3State != LOW)
{
// Toggle LED state
relais3Sate = !relais3Sate;
digitalWrite(relais3, !relais3Sate);
if (!relais3Sate) {
leds[2] = CRGB::Red;
}
if (relais3Sate) {
leds[2] = CRGB::Green ;
}
FastLED.show();
// Update Button Widget
Blynk.virtualWrite(V3, relais3Sate);
btn3State = LOW;
}
}
else
{
btn3State = HIGH;
}
if (digitalRead(btn4) == LOW)
{
// btnState is used to avoid sequential toggles
if (btn4State != LOW)
{
// Toggle LED state
relais4Sate = !relais4Sate;
digitalWrite(relais4, !relais4Sate);
if (!relais4Sate) {
leds[3] = CRGB::Red;
}
if (relais4Sate) {
leds[3] = CRGB::Green ;
}
FastLED.show();
// Update Button Widget
Blynk.virtualWrite(V4, relais4Sate);
btn4State = LOW;
}
}
else
{
btn4State = HIGH;
}
}
BLYNK_CONNECTED()
{
Blynk.syncVirtual(V1);
Blynk.syncVirtual(V2);
Blynk.syncVirtual(V3);
Blynk.syncVirtual(V4);
}
void checkPhysicalButton1();
void humidite();
void temperature();
void setup()
{
Serial.begin(115200);
delay(100);
BlynkEdgent.begin();
sensors.begin(); // debut de la librairie capteur de température
// Debug console
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
leds[0] = CRGB(0, 0, 255);
leds[1] = CRGB(0, 0, 255);
leds[2] = CRGB(0, 0, 255);
leds[3] = CRGB(0, 0, 255);
FastLED.show();
pinMode(relais1, OUTPUT);
pinMode(btn1, INPUT_PULLUP);
digitalWrite(relais1, relais1Sate);
pinMode(relais2, OUTPUT);
pinMode(btn2, INPUT_PULLUP);
digitalWrite(relais2, relais2Sate);
pinMode(relais3, OUTPUT);
pinMode(btn3, INPUT_PULLUP);
digitalWrite(relais3, relais3Sate);
pinMode(relais4, OUTPUT);
pinMode(btn4, INPUT_PULLUP);
digitalWrite(relais4, relais4Sate);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
// Clear the buffer
display.clearDisplay();
display.display();
timer.setInterval(100L, checkPhysicalButton1);
timer.setInterval(10000L, temperature);
timer.setInterval(15200L, humidite);
}
void loop() {
BlynkEdgent.run();
timer.run();
}
I am having a display problem on my screen. The display duration is random. (as shown in the video)
To be able to read the values, I would like to display the temperature 5 seconds and the humidity 5 seconds. is this possible without using a delay?
I’m guessing that you’re using version 1.0.0 of the Blynk library, and the original version of the Edgent_ESP32 example sketch.
You aren’t declaring a timer object in the code you’ve posted, so I think the example you are using already has a timer object declared, which may be causing your problem.
The best solution would be to install library version 1.0.1 and start again with the new version of the Edgent_ESP32 example.
Alternatively, you could try declaring a BlynklTimer object called mytimer
and change your references of timer
to mytimer
Also, as this is the Blynk forum, saying things like:
are likely to be interpreted as meaning that nothing is displaying in the Blynk app.
You would be better to refer to your OLED screen as “OLED” or “OLED Display” to avoid any confusion.
Pete.
I managed to update my library. Unfortunately I don’t understand how it works BlynkTimer
I read the documentation and did several tests but nothing worked
As you say I have changed my timer
→ mytimer
How to declare blynkTimer ?
#include <SPI.h>
#define BLYNK_TEMPLATE_ID "xxxxxxxxx"
#define BLYNK_DEVICE_NAME "xxxxxxxx"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
// Uncomment your board, or configure a custom board in Settings.h
//#define USE_WROVER_BOARD
#include "BlynkEdgent.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#include <FastLED.h>
#define NUM_LEDS 4
#define DATA_PIN 13
CRGB leds[NUM_LEDS];
const int relais1 = 14;
const int btn1 = 26;
const int relais2 = 32;
const int btn2 = 27;
const int relais3 = 15;
const int btn3 = 25;
const int relais4 = 12;
const int btn4 = 19;
// one wire temperature
#define ONE_WIRE_BUS 23
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int deviceCount = 3;
float tempC;
int relais1Sate = LOW;
int btn1State = HIGH;
int relais2Sate = LOW;
int btn2State = HIGH;
int relais3Sate = LOW;
int btn3State = HIGH;
int relais4Sate = LOW;
int btn4State = HIGH;
int brightness = 50;
int lcd_position[] = {16, 30, 44}; // position temperature sur l'écran
BLYNK_WRITE(V1) {
relais1Sate = param.asInt();
Serial.print("Widget Button V1 changed. Writing ");
Serial.print(relais1Sate);
Serial.print(" to Relay 1 and LED V1, and ");
Serial.print(!relais1Sate);
Serial.println(" to LED R1 ...");
digitalWrite(relais1, !relais1Sate);
if (!relais1Sate) {
leds[0] = CRGB::Red;
}
if (relais1Sate) {
leds[0] = CRGB::Green ;
}
FastLED.show();
}
BLYNK_WRITE(V2) {
relais2Sate = param.asInt();
digitalWrite(relais2, !relais2Sate);
if (!relais2Sate) {
leds[1] = CRGB::Red;
}
if (relais2Sate) {
leds[1] = CRGB::Green ;
}
FastLED.show();
}
BLYNK_WRITE(V3) {
relais3Sate = param.asInt();
digitalWrite(relais3, !relais3Sate);
if (!relais3Sate) {
leds[2] = CRGB::Red;
}
if (relais3Sate) {
leds[2] = CRGB::Green ;
}
FastLED.show();
}
BLYNK_WRITE(V4) {
relais4Sate = param.asInt();
digitalWrite(relais4, !relais4Sate);
if (!relais4Sate) {
leds[3] = CRGB::Red;
}
if (relais4Sate) {
leds[3] = CRGB::Green ;
}
FastLED.show();
}
const int dry = 3540; // value for dry sensor // Moisture Sensor
const int wet = 1246; // value for wet sensor // Moisture Sensor
int percentageHumididy; // Moisture Sensor
void humidite() // Moisture Sensor
{
int sensorVal = analogRead(33); // Moisture Sensor
int percentageHumididy = map(sensorVal, wet, dry, 100, 0); // Moisture Sensor
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.clearDisplay();
display.setCursor(0, 0);
display.println("---------------------");
display.setCursor(0, 6);
display.print("| Humidite du sol |");
display.setCursor(0, 12);
display.println("---------------------");
display.display();
display.setTextSize(4);
display.setCursor(16, 20); //Moisture Sensor
display.print(percentageHumididy); //Moisture Sensor
display.println("%"); //Moisture Sensor
display.display(); //Moisture Sensor
Serial.print(percentageHumididy); //Moisture Sensor
Serial.println("%"); //Moisture Sensor
Blynk.virtualWrite(V10, percentageHumididy); //Moisture Sensor
}
void temperature()
{
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0, 0);
display.println("---------------------");
display.setCursor(0, 6);
display.print("| Temperature |");
display.setCursor(0, 12);
display.println("---------------------");
display.setCursor(0, 16); // position 0
display.println(" Interieur |");
display.print("---------------------");
display.display();
display.setCursor(0, 30); // position 1
display.println(" Exterrieur |");
display.print("---------------------");
display.display();
display.setCursor(0, 44); // position 2
display.println(" Eau |");
display.print("---------------------");
display.display();
// Send command to all the sensors for temperature conversion
sensors.requestTemperatures();
// Display temperature from each sensor
for (int i = 0; i < deviceCount; i++)
{
tempC = sensors.getTempCByIndex(i);
Blynk.virtualWrite(i + 21, tempC);
display.setCursor(80, lcd_position[i]);
display.print(tempC);
display.display();
}
}
void checkPhysicalButton1()
{
if (digitalRead(btn1) == LOW)
{
Serial.print("Location A, btn1 = ");
Serial.print(digitalRead(btn1));
Serial.print(" btn1State = ");
Serial.println(btn1State);
// btnState is used to avoid sequential toggles
if (btn1State != LOW)
{
Serial.print("Location B, btn1 = ");
Serial.print(btn1);
Serial.print(", btn1State = ");
Serial.println(btn1State);
// Toggle LED state
relais1Sate = !relais1Sate;
Serial.print("Location C, writing ");
Serial.print(relais1Sate);
Serial.println(" to Relay 1 ...");
digitalWrite(relais1, !relais1Sate);
if (!relais1Sate) {
leds[0] = CRGB::Red;
}
if (relais1Sate) {
leds[0] = CRGB::Green ;
}
FastLED.show();
Serial.print("Location D, writing ");
Serial.print(!relais1Sate);
Serial.print(" to LED V1 and ");
Serial.print(relais1Sate);
Serial.println(" to LED R1 ...");
// Update Button Widget
Serial.print("Location E, writing ");
Serial.print(relais1Sate);
Serial.println(" to Button Widget on pin V1 ...");
Blynk.virtualWrite(V1, relais1Sate);
btn1State = LOW;
}
}
else
{
btn1State = HIGH;
}
if (digitalRead(btn2) == LOW)
{
// btnState is used to avoid sequential toggles
if (btn2State != LOW)
{
// Toggle LED state
relais2Sate = !relais2Sate;
digitalWrite(relais2, !relais2Sate);
if (!relais2Sate) {
leds[1] = CRGB::Red;
}
if (relais2Sate) {
leds[1] = CRGB::Green ;
}
FastLED.show();
// Update Button Widget
Blynk.virtualWrite(V2, relais2Sate);
btn2State = LOW;
}
}
else
{
btn2State = HIGH;
}
if (digitalRead(btn3) == LOW)
{
// btnState is used to avoid sequential toggles
if (btn3State != LOW)
{
// Toggle LED state
relais3Sate = !relais3Sate;
digitalWrite(relais3, !relais3Sate);
if (!relais3Sate) {
leds[2] = CRGB::Red;
}
if (relais3Sate) {
leds[2] = CRGB::Green ;
}
FastLED.show();
// Update Button Widget
Blynk.virtualWrite(V3, relais3Sate);
btn3State = LOW;
}
}
else
{
btn3State = HIGH;
}
if (digitalRead(btn4) == LOW)
{
// btnState is used to avoid sequential toggles
if (btn4State != LOW)
{
// Toggle LED state
relais4Sate = !relais4Sate;
digitalWrite(relais4, !relais4Sate);
if (!relais4Sate) {
leds[3] = CRGB::Red;
}
if (relais4Sate) {
leds[3] = CRGB::Green ;
}
FastLED.show();
// Update Button Widget
Blynk.virtualWrite(V4, relais4Sate);
btn4State = LOW;
}
}
else
{
btn4State = HIGH;
}
}
BLYNK_CONNECTED()
{
Blynk.syncVirtual(V1);
Blynk.syncVirtual(V2);
Blynk.syncVirtual(V3);
Blynk.syncVirtual(V4);
}
void checkPhysicalButton1();
void humidite();
void temperature();
void setup()
{
Serial.begin(115200);
delay(100);
BlynkEdgent.begin();
sensors.begin(); // debut de la librairie capteur de température
// Debug console
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
leds[0] = CRGB(0, 0, 255);
leds[1] = CRGB(0, 0, 255);
leds[2] = CRGB(0, 0, 255);
leds[3] = CRGB(0, 0, 255);
FastLED.show();
pinMode(relais1, OUTPUT);
pinMode(btn1, INPUT_PULLUP);
digitalWrite(relais1, relais1Sate);
pinMode(relais2, OUTPUT);
pinMode(btn2, INPUT_PULLUP);
digitalWrite(relais2, relais2Sate);
pinMode(relais3, OUTPUT);
pinMode(btn3, INPUT_PULLUP);
digitalWrite(relais3, relais3Sate);
pinMode(relais4, OUTPUT);
pinMode(btn4, INPUT_PULLUP);
digitalWrite(relais4, relais4Sate);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
// Clear the buffer
display.clearDisplay();
display.display();
mytimer.setInterval(100L, checkPhysicalButton1);
mytimer.setInterval(10000L, temperature);
mytimer.setInterval(15200L, humidite);
}
void loop() {
BlynkEdgent.run();
mytimer.run();
}
Pete.
I tried again.
why when I add BlynkTimer timer; mytimerobject.run();
#include "BlynkEdgent.h"
BlynkTimer timer;
mytimerobject.run();
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
I have all these errors
nouveau_blynk:17:12: error: redefinition of 'BlynkTimer timer'
BlynkTimer timer;
^
In file included from C:\Users\Gille\Documents\Arduino\nouveau_blynk\nouveau_blynk.ino:15:0:
C:\Users\Gille\Documents\Arduino\nouveau_blynk\BlynkEdgent.h:111:12: note: 'BlynkTimer timer' previously declared here
BlynkTimer timer;
^
nouveau_blynk:18:2: error: 'mytimerobject' does not name a type
mytimerobject.run();
^
In file included from C:\Users\Gille\Documents\Arduino\nouveau_blynk\nouveau_blynk.ino:36:0:
C:\Users\Gille\Documents\Arduino\libraries\FastLED\src/FastLED.h:14:21: note: #pragma message: FastLED version 3.004.000
# pragma message "FastLED version 3.004.000"
^
In file included from C:\Users\Gille\Documents\Arduino\libraries\FastLED\src/FastLED.h:65:0,
from C:\Users\Gille\Documents\Arduino\nouveau_blynk\nouveau_blynk.ino:36:
C:\Users\Gille\Documents\Arduino\libraries\FastLED\src/fastspi.h:135:23: note: #pragma message: No hardware SPI pins defined. All SPI access will default to bitbanged output
# pragma message "No hardware SPI pins defined. All SPI access will default to bitbanged output"
^
C:\Users\Gille\Documents\Arduino\nouveau_blynk\nouveau_blynk.ino: In function 'void setup()':
nouveau_blynk:478:3: error: 'mytimer' was not declared in this scope
mytimer.setInterval(100L, checkPhysicalButton1);
^
C:\Users\Gille\Documents\Arduino\nouveau_blynk\nouveau_blynk.ino: In function 'void loop()':
nouveau_blynk:493:13: error: expected unqualified-id before '.' token
BlynkTimer.run();
^
Multiple libraries were found for "WiFi.h"
Used: C:\Users\Gille\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\WiFi
Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
Not used: C:\Users\Gille\Documents\Arduino\libraries\WiFiNINA
exit status 1
redefinition of 'BlynkTimer timer'
So, instead of declaring a BlynkTimer object called mytimer’, you declared a BlynkTimer object called
timer’ instead….
Because you’re using an old version of the Blynk library, and an old version of the Edgent example, you are getting this error…
which is causing the re-declaration error message, which is why I suggested using a BlynkTimer object name of mytimer
rather than timer
As you don’t have a BlynkTimer object called mytimerobject
then this will cause a compilation error…
and you would never put my timer.run();
at that location in your code anyway, as that command belongs in the void loop
Pete.
So did you start your sketch over again with the Edgent example from the 1.0.1 library?
Pete.
I managed to correct all the errors.
Now how do I go about controlling the display of my OLED Display, I would like the temperature to display for 5 seconds, and the humidity for 5 seconds?
#include <SPI.h>
#define BLYNK_TEMPLATE_ID "xxxxxx"
#define BLYNK_DEVICE_NAME "xxxxx"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
// Uncomment your board, or configure a custom board in Settings.h
//#define USE_WROVER_BOARD
#include "BlynkEdgent.h"
BlynkTimer timer;
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#include <FastLED.h>
#define NUM_LEDS 4
#define DATA_PIN 13
CRGB leds[NUM_LEDS];
const int relais1 = 14;
const int btn1 = 26;
const int relais2 = 32;
const int btn2 = 27;
const int relais3 = 15;
const int btn3 = 25;
const int relais4 = 12;
const int btn4 = 19;
// one wire temperature
#define ONE_WIRE_BUS 23
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int deviceCount = 3;
float tempC;
int relais1Sate = LOW;
int btn1State = HIGH;
int relais2Sate = LOW;
int btn2State = HIGH;
int relais3Sate = LOW;
int btn3State = HIGH;
int relais4Sate = LOW;
int btn4State = HIGH;
int brightness = 50;
int lcd_position[] = {16, 30, 44}; // position temperature sur l'écran
BLYNK_WRITE(V1) {
relais1Sate = param.asInt();
Serial.print("Widget Button V1 changed. Writing ");
Serial.print(relais1Sate);
Serial.print(" to Relay 1 and LED V1, and ");
Serial.print(!relais1Sate);
Serial.println(" to LED R1 ...");
digitalWrite(relais1, !relais1Sate);
if (!relais1Sate) {
leds[0] = CRGB::Red;
}
if (relais1Sate) {
leds[0] = CRGB::Green ;
}
FastLED.show();
}
BLYNK_WRITE(V2) {
relais2Sate = param.asInt();
digitalWrite(relais2, !relais2Sate);
if (!relais2Sate) {
leds[1] = CRGB::Red;
}
if (relais2Sate) {
leds[1] = CRGB::Green ;
}
FastLED.show();
}
BLYNK_WRITE(V3) {
relais3Sate = param.asInt();
digitalWrite(relais3, !relais3Sate);
if (!relais3Sate) {
leds[2] = CRGB::Red;
}
if (relais3Sate) {
leds[2] = CRGB::Green ;
}
FastLED.show();
}
BLYNK_WRITE(V4) {
relais4Sate = param.asInt();
digitalWrite(relais4, !relais4Sate);
if (!relais4Sate) {
leds[3] = CRGB::Red;
}
if (relais4Sate) {
leds[3] = CRGB::Green ;
}
FastLED.show();
}
const int dry = 3540; // value for dry sensor // Moisture Sensor
const int wet = 1246; // value for wet sensor // Moisture Sensor
int percentageHumididy; // Moisture Sensor
void humidite() // Moisture Sensor
{
int sensorVal = analogRead(33); // Moisture Sensor
int percentageHumididy = map(sensorVal, wet, dry, 100, 0); // Moisture Sensor
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.clearDisplay();
display.setCursor(0, 0);
display.println("---------------------");
display.setCursor(0, 6);
display.print("| Humidite du sol |");
display.setCursor(0, 12);
display.println("---------------------");
display.display();
display.setTextSize(4);
display.setCursor(16, 20); //Moisture Sensor
display.print(percentageHumididy); //Moisture Sensor
display.println("%"); //Moisture Sensor
display.display(); //Moisture Sensor
Serial.print(percentageHumididy); //Moisture Sensor
Serial.println("%"); //Moisture Sensor
Blynk.virtualWrite(V10, percentageHumididy); //Moisture Sensor
}
void temperature()
{
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0, 0);
display.println("---------------------");
display.setCursor(0, 6);
display.print("| Temperature |");
display.setCursor(0, 12);
display.println("---------------------");
display.setCursor(0, 16); // position 0
display.println(" Interieur |");
display.print("---------------------");
display.display();
display.setCursor(0, 30); // position 1
display.println(" Exterrieur |");
display.print("---------------------");
display.display();
display.setCursor(0, 44); // position 2
display.println(" Eau |");
display.print("---------------------");
display.display();
// Send command to all the sensors for temperature conversion
sensors.requestTemperatures();
// Display temperature from each sensor
for (int i = 0; i < deviceCount; i++)
{
tempC = sensors.getTempCByIndex(i);
Blynk.virtualWrite(i + 21, tempC);
display.setCursor(80, lcd_position[i]);
display.print(tempC);
display.display();
}
}
void checkPhysicalButton1()
{
if (digitalRead(btn1) == LOW)
{
Serial.print("Location A, btn1 = ");
Serial.print(digitalRead(btn1));
Serial.print(" btn1State = ");
Serial.println(btn1State);
// btnState is used to avoid sequential toggles
if (btn1State != LOW)
{
Serial.print("Location B, btn1 = ");
Serial.print(btn1);
Serial.print(", btn1State = ");
Serial.println(btn1State);
// Toggle LED state
relais1Sate = !relais1Sate;
Serial.print("Location C, writing ");
Serial.print(relais1Sate);
Serial.println(" to Relay 1 ...");
digitalWrite(relais1, !relais1Sate);
if (!relais1Sate) {
leds[0] = CRGB::Red;
}
if (relais1Sate) {
leds[0] = CRGB::Green ;
}
FastLED.show();
Serial.print("Location D, writing ");
Serial.print(!relais1Sate);
Serial.print(" to LED V1 and ");
Serial.print(relais1Sate);
Serial.println(" to LED R1 ...");
// Update Button Widget
Serial.print("Location E, writing ");
Serial.print(relais1Sate);
Serial.println(" to Button Widget on pin V1 ...");
Blynk.virtualWrite(V1, relais1Sate);
btn1State = LOW;
}
}
else
{
btn1State = HIGH;
}
if (digitalRead(btn2) == LOW)
{
// btnState is used to avoid sequential toggles
if (btn2State != LOW)
{
// Toggle LED state
relais2Sate = !relais2Sate;
digitalWrite(relais2, !relais2Sate);
if (!relais2Sate) {
leds[1] = CRGB::Red;
}
if (relais2Sate) {
leds[1] = CRGB::Green ;
}
FastLED.show();
// Update Button Widget
Blynk.virtualWrite(V2, relais2Sate);
btn2State = LOW;
}
}
else
{
btn2State = HIGH;
}
if (digitalRead(btn3) == LOW)
{
// btnState is used to avoid sequential toggles
if (btn3State != LOW)
{
// Toggle LED state
relais3Sate = !relais3Sate;
digitalWrite(relais3, !relais3Sate);
if (!relais3Sate) {
leds[2] = CRGB::Red;
}
if (relais3Sate) {
leds[2] = CRGB::Green ;
}
FastLED.show();
// Update Button Widget
Blynk.virtualWrite(V3, relais3Sate);
btn3State = LOW;
}
}
else
{
btn3State = HIGH;
}
if (digitalRead(btn4) == LOW)
{
// btnState is used to avoid sequential toggles
if (btn4State != LOW)
{
// Toggle LED state
relais4Sate = !relais4Sate;
digitalWrite(relais4, !relais4Sate);
if (!relais4Sate) {
leds[3] = CRGB::Red;
}
if (relais4Sate) {
leds[3] = CRGB::Green ;
}
FastLED.show();
// Update Button Widget
Blynk.virtualWrite(V4, relais4Sate);
btn4State = LOW;
}
}
else
{
btn4State = HIGH;
}
}
BLYNK_CONNECTED()
{
Blynk.syncVirtual(V1);
Blynk.syncVirtual(V2);
Blynk.syncVirtual(V3);
Blynk.syncVirtual(V4);
}
void checkPhysicalButton1();
void humidite();
void temperature();
void setup()
{
Serial.begin(115200);
delay(100);
BlynkEdgent.begin();
sensors.begin(); // debut de la librairie capteur de température
// Debug console
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
leds[0] = CRGB(0, 0, 255);
leds[1] = CRGB(0, 0, 255);
leds[2] = CRGB(0, 0, 255);
leds[3] = CRGB(0, 0, 255);
FastLED.show();
pinMode(relais1, OUTPUT);
pinMode(btn1, INPUT_PULLUP);
digitalWrite(relais1, relais1Sate);
pinMode(relais2, OUTPUT);
pinMode(btn2, INPUT_PULLUP);
digitalWrite(relais2, relais2Sate);
pinMode(relais3, OUTPUT);
pinMode(btn3, INPUT_PULLUP);
digitalWrite(relais3, relais3Sate);
pinMode(relais4, OUTPUT);
pinMode(btn4, INPUT_PULLUP);
digitalWrite(relais4, relais4Sate);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
// Clear the buffer
display.clearDisplay();
display.display();
timer.setInterval(100L, checkPhysicalButton1);
timer.setInterval(10000L, temperature);
timer.setInterval(15200L, humidite);
}
void loop() {
BlynkEdgent.run();
timer.run();
}
So what EXACTLY have you done, because you are now using a BlynkTimer object called timer
Also, what results are you seeing?
Pete.
is it better like that
#define BLYNK_TEMPLATE_ID "xxxxx"
#define BLYNK_DEVICE_NAME "xxxxx"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
// Uncomment your board, or configure a custom board in Settings.h
//#define USE_WROVER_BOARD
#include "BlynkEdgent.h"
BlynkTimer mytimer;
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#include <FastLED.h>
#define NUM_LEDS 4
#define DATA_PIN 13
CRGB leds[NUM_LEDS];
const int relais1 = 14;
const int btn1 = 26;
const int relais2 = 32;
const int btn2 = 27;
const int relais3 = 15;
const int btn3 = 25;
const int relais4 = 12;
const int btn4 = 19;
// one wire temperature
#define ONE_WIRE_BUS 23
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int deviceCount = 3;
float tempC;
int relais1Sate = LOW;
int btn1State = HIGH;
int relais2Sate = LOW;
int btn2State = HIGH;
int relais3Sate = LOW;
int btn3State = HIGH;
int relais4Sate = LOW;
int btn4State = HIGH;
int brightness = 50;
int lcd_position[] = {16, 30, 44}; // position temperature sur l'écran
BLYNK_WRITE(V1) {
relais1Sate = param.asInt();
Serial.print("Widget Button V1 changed. Writing ");
Serial.print(relais1Sate);
Serial.print(" to Relay 1 and LED V1, and ");
Serial.print(!relais1Sate);
Serial.println(" to LED R1 ...");
digitalWrite(relais1, !relais1Sate);
if (!relais1Sate) {
leds[0] = CRGB::Red;
}
if (relais1Sate) {
leds[0] = CRGB::Green ;
}
FastLED.show();
}
BLYNK_WRITE(V2) {
relais2Sate = param.asInt();
digitalWrite(relais2, !relais2Sate);
if (!relais2Sate) {
leds[1] = CRGB::Red;
}
if (relais2Sate) {
leds[1] = CRGB::Green ;
}
FastLED.show();
}
BLYNK_WRITE(V3) {
relais3Sate = param.asInt();
digitalWrite(relais3, !relais3Sate);
if (!relais3Sate) {
leds[2] = CRGB::Red;
}
if (relais3Sate) {
leds[2] = CRGB::Green ;
}
FastLED.show();
}
BLYNK_WRITE(V4) {
relais4Sate = param.asInt();
digitalWrite(relais4, !relais4Sate);
if (!relais4Sate) {
leds[3] = CRGB::Red;
}
if (relais4Sate) {
leds[3] = CRGB::Green ;
}
FastLED.show();
}
const int dry = 3540; // value for dry sensor // Moisture Sensor
const int wet = 1246; // value for wet sensor // Moisture Sensor
int percentageHumididy; // Moisture Sensor
void humidite() // Moisture Sensor
{
int sensorVal = analogRead(33); // Moisture Sensor
int percentageHumididy = map(sensorVal, wet, dry, 100, 0); // Moisture Sensor
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.clearDisplay();
display.setCursor(0, 0);
display.println("---------------------");
display.setCursor(0, 6);
display.print("| Humidite du sol |");
display.setCursor(0, 12);
display.println("---------------------");
display.display();
display.setTextSize(4);
display.setCursor(16, 20); //Moisture Sensor
display.print(percentageHumididy); //Moisture Sensor
display.println("%"); //Moisture Sensor
display.display(); //Moisture Sensor
Serial.print(percentageHumididy); //Moisture Sensor
Serial.println("%"); //Moisture Sensor
Blynk.virtualWrite(V10, percentageHumididy); //Moisture Sensor
}
void temperature()
{
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0, 0);
display.println("---------------------");
display.setCursor(0, 6);
display.print("| Temperature |");
display.setCursor(0, 12);
display.println("---------------------");
display.setCursor(0, 16); // position 0
display.println(" Interieur |");
display.print("---------------------");
display.display();
display.setCursor(0, 30); // position 1
display.println(" Exterrieur |");
display.print("---------------------");
display.display();
display.setCursor(0, 44); // position 2
display.println(" Eau |");
display.print("---------------------");
display.display();
// Send command to all the sensors for temperature conversion
sensors.requestTemperatures();
// Display temperature from each sensor
for (int i = 0; i < deviceCount; i++)
{
tempC = sensors.getTempCByIndex(i);
Blynk.virtualWrite(i + 21, tempC);
display.setCursor(80, lcd_position[i]);
display.print(tempC);
display.display();
}
}
void checkPhysicalButton1()
{
if (digitalRead(btn1) == LOW)
{
Serial.print("Location A, btn1 = ");
Serial.print(digitalRead(btn1));
Serial.print(" btn1State = ");
Serial.println(btn1State);
// btnState is used to avoid sequential toggles
if (btn1State != LOW)
{
Serial.print("Location B, btn1 = ");
Serial.print(btn1);
Serial.print(", btn1State = ");
Serial.println(btn1State);
// Toggle LED state
relais1Sate = !relais1Sate;
Serial.print("Location C, writing ");
Serial.print(relais1Sate);
Serial.println(" to Relay 1 ...");
digitalWrite(relais1, !relais1Sate);
if (!relais1Sate) {
leds[0] = CRGB::Red;
}
if (relais1Sate) {
leds[0] = CRGB::Green ;
}
FastLED.show();
Serial.print("Location D, writing ");
Serial.print(!relais1Sate);
Serial.print(" to LED V1 and ");
Serial.print(relais1Sate);
Serial.println(" to LED R1 ...");
// Update Button Widget
Serial.print("Location E, writing ");
Serial.print(relais1Sate);
Serial.println(" to Button Widget on pin V1 ...");
Blynk.virtualWrite(V1, relais1Sate);
btn1State = LOW;
}
}
else
{
btn1State = HIGH;
}
if (digitalRead(btn2) == LOW)
{
// btnState is used to avoid sequential toggles
if (btn2State != LOW)
{
// Toggle LED state
relais2Sate = !relais2Sate;
digitalWrite(relais2, !relais2Sate);
if (!relais2Sate) {
leds[1] = CRGB::Red;
}
if (relais2Sate) {
leds[1] = CRGB::Green ;
}
FastLED.show();
// Update Button Widget
Blynk.virtualWrite(V2, relais2Sate);
btn2State = LOW;
}
}
else
{
btn2State = HIGH;
}
if (digitalRead(btn3) == LOW)
{
// btnState is used to avoid sequential toggles
if (btn3State != LOW)
{
// Toggle LED state
relais3Sate = !relais3Sate;
digitalWrite(relais3, !relais3Sate);
if (!relais3Sate) {
leds[2] = CRGB::Red;
}
if (relais3Sate) {
leds[2] = CRGB::Green ;
}
FastLED.show();
// Update Button Widget
Blynk.virtualWrite(V3, relais3Sate);
btn3State = LOW;
}
}
else
{
btn3State = HIGH;
}
if (digitalRead(btn4) == LOW)
{
// btnState is used to avoid sequential toggles
if (btn4State != LOW)
{
// Toggle LED state
relais4Sate = !relais4Sate;
digitalWrite(relais4, !relais4Sate);
if (!relais4Sate) {
leds[3] = CRGB::Red;
}
if (relais4Sate) {
leds[3] = CRGB::Green ;
}
FastLED.show();
// Update Button Widget
Blynk.virtualWrite(V4, relais4Sate);
btn4State = LOW;
}
}
else
{
btn4State = HIGH;
}
}
BLYNK_CONNECTED()
{
Blynk.syncVirtual(V1);
Blynk.syncVirtual(V2);
Blynk.syncVirtual(V3);
Blynk.syncVirtual(V4);
}
void checkPhysicalButton1();
void humidite();
void temperature();
void setup()
{
Serial.begin(115200);
delay(100);
BlynkEdgent.begin();
sensors.begin(); // debut de la librairie capteur de température
// Debug console
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
leds[0] = CRGB(0, 0, 255);
leds[1] = CRGB(0, 0, 255);
leds[2] = CRGB(0, 0, 255);
leds[3] = CRGB(0, 0, 255);
FastLED.show();
pinMode(relais1, OUTPUT);
pinMode(btn1, INPUT_PULLUP);
digitalWrite(relais1, relais1Sate);
pinMode(relais2, OUTPUT);
pinMode(btn2, INPUT_PULLUP);
digitalWrite(relais2, relais2Sate);
pinMode(relais3, OUTPUT);
pinMode(btn3, INPUT_PULLUP);
digitalWrite(relais3, relais3Sate);
pinMode(relais4, OUTPUT);
pinMode(btn4, INPUT_PULLUP);
digitalWrite(relais4, relais4Sate);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
// Clear the buffer
display.clearDisplay();
display.display();
mytimer.setInterval(100L, checkPhysicalButton1);
mytimer.setInterval(10000L, temperature);
mytimer.setInterval(15200L, humidite);
}
void loop() {
BlynkEdgent.run();
mytimer.run();
}
Currently, the temperature and my humidity are displayed on my OLDED display randomly.
I would like that I could read the temperature for 5 seconds and read the humidity for 5 seconds
Pete.
This is what i did :
I updated my Blynk library
I opened a new example of Blynk.edegent and I copy / paste my code
I added BlynkTimer mytimer; at the start of the code
In void setup() I changed timer.setInterval(100L, checkPhysicalButton1); by mytimer.setInterval(100L, checkPhysicalButton1);
In void loop(); I changed timer.run(); by mytimer.run();
As you’ve not uncommented the #define USE_WROVER_BOARD
line, what changes have you made to the Settings.h
file from the Edgent example?
Pete.
I did not make any changes
What type of ESP32 board are you using?
Pete.
i use esp 32 wroom-32U