Yes, you can use both SoftSerial for the Nextion and I2C for sensor, but they do have to be on different pins. I’m not sure where the I2C pins on the ESP12 are, so you may have to adjust your softserial pins to other pins if they currently overlap.
I’m not even sure the ESP has hardware I2C to be honest.
Wire library currently supports master mode up to approximately 450KHz. Before using I2C, pins for SDA and SCL need to be set by calling Wire.begin(int sda, int scl), i.e. Wire.begin(0, 2) on ESP-01, else they default to pins 4(SDA) and 5(SCL)
@Jiri_Bam 0 and 2 is just for the ESP01’s that ONLY have 0 and 2.
For all other ESP’s you should use the allocated pins of 4 and 5 (D2 and D1 respectively). Then you can just call Wire.begin().
If you are already using 4 and 5 for the Nextion or whatever try other pins and modify the Wire.begin() call.
0 and 2 would be the last pins I would use as they are special. I assume you have a pinout diagram for your hardware.
So blows up wasnt. But i see something wrong is with SI7021 sensor. If i delete //SI7021 sensor; from sketch so are data show on Nextion. BUt BH1750 show bad data… Thanks.
#define BLYNK_DEBUG
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
#include <BH1750.h>
#include <Wire.h>
#include <SI7021.h>
float temp, hum;
bool SI7021_present = true;
#define I2C_SCL 4 //d2 // Barometric Pressure Sensor (BMP085)
#define I2C_SDA 5 //d1
//SI7021 sensor;
#include <Nextion.h>
#include <SoftwareSerial.h>
BH1750 lightMeter;
#define DHTPIN 2 //D4
#define DHTTYPE DHT22 // DHT 22 Change this if you have a DHT11
DHT dht(DHTPIN, DHTTYPE);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = ""; // Put your Auth Token here. (see Step 3 above)
SoftwareSerial HMISerial(12,14,false,256);//RX-D1 5 , TX-D2 6
Nextion myNextion(HMISerial, 9600);
SimpleTimer timer;
void setup()
{
Wire.begin();
//sensor.begin();
lightMeter.begin();
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth, "", ""); //insert here your SSID and password
myNextion.init();
// Setup a function to be called every second
timer.setInterval(10000L, sendUptime);
}
void sendUptime()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
//Read the Temp and Humidity from DHT
float h = dht.readHumidity();
float t = dht.readTemperature();
Blynk.virtualWrite(2, t); // virtual pin
Blynk.virtualWrite(3, h); // virtual pin
int16_t lux = lightMeter.readLightLevel();
Blynk.virtualWrite(4, lux);
myNextion.setComponentText("t5", String(lux));
myNextion.setComponentText("t1", String(t));
myNextion.setComponentText("t2", String(h));
delay(1000);
String dim = "dim=50"; //pro podsvíceni
myNextion.sendCommand(dim.c_str()); //pro podsvícení
}
void loop()
{
Blynk.run();
timer.run();
}
Do you mean?
But something is wrong with: timer.setInterval(10000L, readCO2,);
THanks.
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
#define DHTPIN 12 //pin gpio 12 in sensor
#define DHTTYPE DHT22 // DHT 22 Change this if you have a DHT11
DHT dht(DHTPIN, DHTTYPE);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = ""; // Put your Auth Token here. (see Step 3 above)
SimpleTimer timer;
#define pwmPin 5 //CO2
#define LedPin 13
int prevVal = LOW; //CO2
long th, tl, h, l, ppm;
void setup()
{
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth, "", ""); //insert here your SSID and password
// Setup a function to be called every second
timer.setInterval(10000L, sendUptime);
timer.setInterval(10000L, readCO2,);
}
void sendUptime()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
//Read the Temp and Humidity from DHT
float h = dht.readHumidity();
float t = dht.readTemperature();
Blynk.virtualWrite(12, t); // virtual pin
Blynk.virtualWrite(13, h); // virtual pin
Blynk.virtualWrite(11, ppm); // virtual pin
myNextion.setComponentText("t0", String(ppm));
}
void readCO2()
{
long tt = millis();
int myVal = digitalRead(pwmPin);
//Если обнаружили изменение
if (myVal == HIGH) {
digitalWrite(LedPin, HIGH);
if (myVal != prevVal) {
h = tt;
tl = h - l;
prevVal = myVal;
}
} else {
digitalWrite(LedPin, LOW);
if (myVal != prevVal) {
l = tt;
th = l - h;
prevVal = myVal;
ppm = 5000 * (th - 2) / (th + tl - 4);
Serial.println("PPM = " + String(ppm));
}
}
}
void loop()
{
Blynk.run();
timer.run();
}
#define BLYNK_DEBUG
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
#include <SoftwareSerial.h>
#include <Nextion.h>
#define DHTPIN 12 //pin gpio 12 in sensor
#define DHTTYPE DHT22 // DHT 22 Change this if you have a DHT11
DHT dht(DHTPIN, DHTTYPE);
SoftwareSerial HMISerial(12,14,false,256);//RX-D1 5 , TX-D2 6
Nextion myNextion(HMISerial, 9600);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = ""; // Put your Auth Token here. (see Step 3 above)
SimpleTimer timer;
#define pwmPin 14 //CO2 //D5
#define LedPin 13
int prevVal = LOW; //CO2
long th, tl, h, l, ppm;
void setup()
{
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth, "", ""); //insert here your SSID and password
// Setup a function to be called every second
timer.setInterval(10000L, sendUptime);
timer.setInterval(10000L, readCO2);
myNextion.init();
}
void sendUptime()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
//Read the Temp and Humidity from DHT
float h = dht.readHumidity();
float t = dht.readTemperature();
Blynk.virtualWrite(12, t); // virtual pin
Blynk.virtualWrite(13, h); // virtual pin
}
void readCO2()
{
long tt = millis();
int myVal = digitalRead(pwmPin);
//Если обнаружили изменение
if (myVal == HIGH) {
digitalWrite(LedPin, HIGH);
if (myVal != prevVal) {
h = tt;
tl = h - l;
prevVal = myVal;
}
} else {
digitalWrite(LedPin, LOW);
if (myVal != prevVal) {
l = tt;
th = l - h;
prevVal = myVal;
ppm = 5000 * (th - 2) / (th + tl - 4);
Serial.println("PPM = " + String(ppm));
Blynk.virtualWrite(11, ppm); // virtual pin
myNextion.setComponentText("t0", String(ppm));
}
}
}
void loop()
{
Blynk.run();
timer.run();
}
You have put them inside the else statement (which it looks like is never triggered).
Move the 3rd last } of the function above these 2 lines and see what this gives you and I will see what bug you have that isn’t triggering the else statement.
Post the full sketch so I can check the pins.
Meanwhile you need to do likewise. Right them all down for all devices and ensure they are no duplicates etc.
#define BLYNK_DEBUG
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <SoftwareSerial.h>
#include <Nextion.h>
SoftwareSerial HMISerial(12,14,false,256);//RX-D1 5 , TX-D2 6
Nextion myNextion(HMISerial, 9600);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = ""; // Put your Auth Token here. (see Step 3 above)
SimpleTimer timer;
#define pwmPin 2 //CO2 //D4
#define LedPin 13
int prevVal = LOW; //CO2
long th, tl, h, l, ppm;
void setup()
{
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth, "", ""); //insert here your SSID and password
// Setup a function to be called every second
timer.setInterval(10000L, sendUptime);
timer.setInterval(10000L, readCO2);
myNextion.init();
}
void sendUptime()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
//Read the Temp and Humidity from DHT
}
void readCO2()
{
long tt = millis();
int myVal = digitalRead(pwmPin);
//Если обнаружили изменение
if (myVal == HIGH) {
digitalWrite(LedPin, HIGH);
if (myVal != prevVal) {
h = tt;
tl = h - l;
prevVal = myVal;
}
} else {
digitalWrite(LedPin, LOW);
if (myVal != prevVal) {
l = tt;
th = l - h;
prevVal = myVal;
ppm = 5000 * (th - 2) / (th + tl - 4);
Serial.println("PPM = " + String(ppm));
}
}
Blynk.virtualWrite(11, ppm); // virtual pin
myNextion.setComponentText("t0", String(ppm));
}
void loop()
{
Blynk.run();
timer.run();
}