#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <Wire.h>
#include <Si7021.h>
SI7021 si7021;
#define I2C_SCL 12 // Barometric Pressure Sensor (BMP085)
#define I2C_SDA 13
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "75a3e91b35eea63e9c1"; // Put your Auth Token here. (see Step 3 above)
SimpleTimer timer;
void setup()
{
Wire.begin(I2C_SDA, I2C_SCL);
delay(10);
si7021.begin();
while(!Serial);
si7021.setHumidityRes(12); // Humidity = 12-bit / Temperature = 14-bit - See more at: http://www.esp8266.com/viewtopic.php?f=13&t=9563#sthash.wOtGMLB0.dpuf
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);
}
void sendUptime()
{
float humin = si7021.readHumidity();
float tempin = si7021.readTempPrev();
Blynk.virtualWrite(3, tempin); // virtual pin
Blynk.virtualWrite(4, humin);
}
void loop()
{
Blynk.run();
timer.run();
}
#include <Wire.h>
#include <Si7021.h>
SI7021 si7021;
// BASIC DEMO
// ----------
// Print humidity and temperature to the serial monitor while toggling the heater on and off
// periodically.
// NOTE ON RESOLUTION:
// -------------------
// Changing the resolution of the temperature will also change the humidity resolution.
// Likewise, changing the resolution of the humidity will also change temperature resolution.
// Two functions are provided to change the resolution, both functions are similar except they have
// different masks to the registers, so setTempRes(14) will change the temp resolution to 14-bit
// but humidity will also be set to 12-bit. Setting the humidity resolution to 8-bit setHumidityRes(8)
// will change the temperature resolution to 12-bit.
// Resolution Table:
// 14-bit Temp <-> 12-bit Humidity
// 13-bit Temp <-> 10-bit Humidity
// 12-bit Temp <-> 8-bit Humidity
// 11-bit Temp <-> 11-bit Humidity
// NOTE ON HEATER:
// ---------------
// The HTRE bit in the user register is what turns the heater on and off. This register
// is stored on non-volatile memory to it will keep its state when power is removed. If
// the heater is enabled and power is removed before the program had chance to turn it off
// then the heater will remain enabled the next time it is powered on. The heater has to
// be explicitly turned off. In the begin() function for this library, a reset procedure
// will take place and reset the user register to default, so the heater will be turned off
// and the resolution will also be set to default, 14-bit temperature and 12-bit humidity.
// Keep this in mind if testing and swapping sensors/libraries.
void setup()
{
Serial.begin(115200);
si7021.begin(); // Runs : Wire.begin() + reset()
while(!Serial); // Wait for serial monitor to open
Serial.println("BASIC DEMO");
Serial.println("------------------------------------------");
si7021.setHumidityRes(12); // Humidity = 12-bit / Temperature = 14-bit
}
void loop()
{
static uint8_t heaterOnOff; // Create static variable for heater control
si7021.setHeater(heaterOnOff); // Turn heater on or off
Serial.print("Heater Status = ");
Serial.println(si7021.getHeater() ? "ON" : "OFF");
for(int i = (heaterOnOff ? 20 : 30); i>0; i--)
{
Serial.print("Humidity : ");
Serial.print(si7021.readHumidity()); // Read humidity and print to serial monitor
Serial.print(" %\t");
Serial.print("Temp : ");
Serial.print(si7021.readTemp()); // Read temperature and print to serial monitor
Serial.print(" C\t");
Serial.println(i); // Print count down for heater change
delay(500);
}
heaterOnOff = !heaterOnOff; // Toggle heater on/off variable
}
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <Wire.h>
#include <SI7021.h>
SI7021 sensor;
#define I2C_SCL 12 //D6 // Barometric Pressure Sensor (BMP085)
#define I2C_SDA 13//D7
// 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;
void setup()
{
Wire.begin(I2C_SDA, I2C_SCL);
delay(10);
SI7021.begin();
while(!Serial);
SI7021.setHumidityRes(12); // Humidity = 12-bit / Temperature = 14-bit - See more at: http://www.esp8266.com/viewtopic.php?f=13&t=9563#sthash.wOtGMLB0.dpuf
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth, "", ""); //insert here your SSID and password
}
void sendUptime()
{
float humin = SI7021.readHumidity();
float tempin = SI7021.readTempPrev();
Blynk.virtualWrite(1, tempin); // virtual pin
Blynk.virtualWrite(2, humin);
}
void loop()
{
Blynk.run();
timer.run();
}
but write wrong:
si7021__blynk.ino: In function 'void setup()':
si7021__blynk:32: error: expected unqualified-id before '.' token
si7021__blynk:34: error: expected unqualified-id before '.' token
si7021__blynk.ino: In function 'void sendUptime()':
si7021__blynk:51: error: expected primary-expression before '.' token
si7021__blynk:52: error: expected primary-expression before '.' token
Multiple libraries were found for "BlynkSimpleEsp8266.h"
Used: C:\Users\boss\Documents\Arduino\libraries\blynk-library-master
Not used: C:\Users\boss\Documents\Arduino\libraries\Blynk
expected unqualified-id before '.' token
Library example -
#include <Wire.h>
#include <SI7021.h>
SI7021 sensor;
int led1 = 3;
int led2 = 4;
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
sensor.begin();
}
void loop() {
// temperature is an integer in hundredths
int temperature = sensor.getCelsiusHundredths();
temperature = temperature / 100;
for (int i = 0; i < temperature; i++) {
pulse(led1);
}
delay(5000);
// humidity is an integer representing percent
int humidity = sensor.getHumidityPercent();
for (int i = 0; i < humidity; i++) {
pulse(led2);
}
delay(5000);
// this driver should work for SI7020 and SI7021, this returns 20 or 21
int deviceid = sensor.getDeviceId();
for (int i = 0; i < deviceid; i++) {
pulse(led1);
}
delay(5000);
// enable internal heater for testing
sensor.setHeater(true);
delay(20000);
sensor.setHeater(false);
// see if heater changed temperature
temperature = sensor.getCelsiusHundredths();
temperature = temperature / 100;
for (int i = 0; i < temperature; i++) {
pulse(led2);
}
//cool down
delay(20000);
// get humidity and temperature in one shot, saves power because sensor takes temperature when doing humidity anyway
si7021_env data = sensor.getHumidityAndTemperature();
for (int i = 0; i < data.celsiusHundredths/100; i++) {
pulse(led1);
}
for (int i = 0; i < data.humidityBasisPoints/100; i++) {
pulse(led2);
}
delay(5000);
}
void pulse(int pin) {
// software pwm, flash light for ~1 second with short duty cycle
for (int i = 0; i < 20; i++) {
digitalWrite(pin, HIGH);
delay(1);
digitalWrite(pin,LOW);
delay(9);
}
digitalWrite(pin,LOW);
delay(300);
}
define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <Wire.h>
#include "Adafruit_Si7021.h"
Adafruit_Si7021 sensor = Adafruit_Si7021();
#define I2C_SCL 12 //D6 // Barometric Pressure Sensor (BMP085)
#define I2C_SDA 13//D7
// 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;
void setup()
{
Wire.begin(I2C_SDA, I2C_SCL);
sensor.begin();
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth, "", ""); //insert here your SSID and password
}
void sendUptime()
{
float humin = Adafruit_Si7021.readHumidity();
float tempin = Adafruit_Si7021.readTempPrev();
Blynk.virtualWrite(1, tempin); // virtual pin
Blynk.virtualWrite(2, humin);
}
void loop()
{
Blynk.run();
timer.run();
}
but write mistake:
si7021__blynk.ino: In function 'void sendUptime()':
si7021__blynk:47: error: expected primary-expression before '.' token
si7021__blynk:48: error: expected primary-expression before '.' token
Multiple libraries were found for "BlynkSimpleEsp8266.h"
Used: C:\Users\boss\Documents\Arduino\libraries\blynk-library-master
Not used: C:\Users\boss\Documents\Arduino\libraries\Blynk
expected primary-expression before '.' token
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <Wire.h>
#include <Adafruit_Si7021.h>
Adafruit_Si7021 sensor = Adafruit_Si7021();
#define I2C_SCL 12 //D6 // Barometric Pressure Sensor (BMP085)
#define I2C_SDA 13//D7
// 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;
float tempin, humin;
void setup()
{
Wire.begin(I2C_SDA, I2C_SCL);
sensor.begin();
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth, "", ""); //insert here your SSID and password
}
void sendUptime()
{
float humin = Adafruit_Si7021.readHumidity();
float tempin = Adafruit_Si7021.readTempPrev();
Blynk.virtualWrite(1, tempin); // virtual pin
Blynk.virtualWrite(2, humin);
}
void loop()
{
Blynk.run();
timer.run();
}
But now is wrong:
si7021__blynk.ino: In function 'void sendUptime()':
si7021__blynk:49: error: expected primary-expression before '.' token
si7021__blynk:50: error: expected primary-expression before '.' token
Multiple libraries were found for "BlynkSimpleEsp8266.h"
Used: C:\Users\boss\Documents\Arduino\libraries\blynk-library-master
Not used: C:\Users\boss\Documents\Arduino\libraries\Blynk
expected primary-expression before '.' token
Multiple libraries were found for "BlynkSimpleEsp8266.h" Used: C:\Users\boss\Documents\Arduino\libraries\blynk-library-master Not used: C:\Users\boss\Documents\Arduino\libraries\Blynk
How about you delete ALL blynk libary folders and re-install the library so you only have 1 copy.
The structure should look like this, along with your saved sketches:
Hi. I was try si7021 sensors connect to arduino if is sensor good. And is sensor is ok. But on ESP with same library no working…
#include <Wire.h>
#include <Artekit_SI7021.h>
Artekit_SI7021 si7021;
static void sensorRead()
{
float temperature;
float humidity;
/* Read relative humidity and temperature */
humidity = si7021.ReadHumidity();
/* By setting true in the next function, we read the
* temperature from the previous RH measurement.
* Otherwise it will perform a new temperature measurement.
*/
temperature = si7021.ReadTemperature(true);
Serial.print("RH: ");
Serial.print(humidity);
Serial.print("%\tTemperature: ");
Serial.println(temperature);
}
void setup()
{
/* Start I2C */
Wire.begin();
/* Start serial */
Serial.begin(9600);
}
void loop()
{
static int counter = 0;
static bool heater = false;
/* Read sensor data each second */
sensorRead();
/* Turn on and off the heater every 30 seconds,
* just to see the change in the temperature readings.
*/
if (heater == false)
{
counter++;
if (counter == 30)
{
Serial.println("Heater ON");
si7021.EnableHeater();
heater = true;
}
} else {
counter--;
if (counter == 0)
{
Serial.println("Heater OFF");
si7021.DisableHeater();
heater = false;
}
}
delay(1000);
}
}