Go Down

Topic: Read Temperature with Si7021 sensor by using Sonoff TH (Read 187 times) previous topic - next topic

atjackie1985

Hi everyone.

 Please help me to read humidity and temperature from Si7021. I have Sonoff TH and use Si7021 Sensor.

I see example at https://learn.adafruit.com/adafruit-si7021-temperature-plus-humidity-sensor/arduino-code

but it's not work. no show anything. Pls help me...

Code: [Select]

#include "Adafruit_Si7021.h"
Adafruit_Si7021 hum_sensor = Adafruit_Si7021();

void setup() {
  Serial.begin(115200);
  hum_sensor.begin();
}

void loop() {
      // Si7021
    float h = hum_sensor.readTemperature();
    float t = hum_sensor.readHumidity();
    Serial.print("Humidity: "); Serial.print(h); Serial.print(" %\t"); Serial.print("Temperature: ");  Serial.print(t); Serial.println(" *C ");
    delay(2000); //Delay 2 sec.
}

PaulS

Quote
but it's not work. no show anything.
Print something before and after trying to read the temperature, and before and after trying to read the humidity.

Do you still get nothing?
The art of getting good answers lies in asking good questions.

pylon

Check the return value of the begin() method. If it's false you're wiring is wrong.

atjackie1985

Print something before and after trying to read the temperature, and before and after trying to read the humidity.

Do you still get nothing?
Yes. I try to print something that you recommend. Show result as below, I think it's jack and need pin or not?

08:50:10.876 ->  Start print begin
08:50:11.045 -> 0 Start print before
08:50:11.045 -> Humidity: nan % Temperature: nan *C
08:50:11.045 ->  Start print after


But if i use AM2301 it's work by this code below ( No work for Si7021 )

Quote
// Sensor AM2301, AM2302
#include <DHT.h> // Adafruit DHT
#include <Adafruit_Sensor.h> // Adafruit Unified Sensor
#define DHTPIN 14     // what pin we're connected to
#define DHTTYPE DHT22   // DHT22  (AM2302)  DHT11
DHT dht(DHTPIN, DHTTYPE);


void setup()
{
  Serial.begin(115200);
  
  delay(5000);
  dht.begin(); // Humidity and Temperature
  
}

void loop()
{
//       AM2302
    float h = dht.readHumidity();
    float t = dht.readTemperature(); // Read temperature as Celsius
    if (isnan(h) || isnan(t)) {  Serial.println("AM2301 - Failed to read from DHT sensor!"); }
    Serial.print("Humidity: "); Serial.print(h); Serial.print(" %\t"); Serial.print("Temperature: ");  Serial.print(t); Serial.println(" *C ");
    
    delay(2000); //Delay 2 sec.
}

pylon

Quote
Humidity: nan % Temperature: nan *C
Getting an output with nan is not the same as getting nothing!

Quote
But if i use AM2301 it's work by this code below ( No work for Si7021 )
The AM2301 (DHT22) is wired differently, it using kind of a 1-wire bus (not to be confused for a Dallas OneWire bus) but the SI7021 uses I2C. Most probably the wiring is wrong. Post a wiring diagram of your setup (may be hand drawn)!

freaklabs

You might need to make sure the device is powered and the ground is intact. Getting NaN means that you're likely getting garbage from the serial. Perhaps use a hex monitor to see what you're getting? Trashed data could come from bad GND and of course incorrect wiring.
FreakLabs
Wireless Technology for the environment, wildlife, and agriculture
https://freaklabs.org
https://hackerfarm.jp
Twitter: @freaklabs

atjackie1985

#6
Mar 25, 2019, 02:35 am Last Edit: Mar 25, 2019, 02:37 am by atjackie1985
Getting an output with nan is not the same as getting nothing!

The AM2301 (DHT22) is wired differently, it using kind of a 1-wire bus (not to be confused for a Dallas OneWire bus) but the SI7021 uses I2C. Most probably the wiring is wrong. Post a wiring diagram of your setup (may be hand drawn)!
This is our circuit at https://ibb.co/WfH2JhY. I use Sonoff Si7021 and Sonoff model TH.  Actually I have tested with old sonoff code. It's work but I try to flash via using our code. it's not work. I don't understand why is not work. I guess that about pin because all examples no use jack they use i2c as I know. If I misunderstand pls help us. :-)




atjackie1985

Pls help me on this case if someone can read humidity and temperature.

pylon

Quote
This is our circuit at https://ibb.co/WfH2JhY
First: post picture here into the forum system and not to external sites that delete the link after short time frames. Second: Do you really think that this picture allows to see the circuit? Post schematics of the used components! And a wiring diagram (the white color on the connection doesn't allow to see any wiring).


atjackie1985

First: post picture here into the forum system and not to external sites that delete the link after short time frames. Second: Do you really think that this picture allows to see the circuit? Post schematics of the used components! And a wiring diagram (the white color on the connection doesn't allow to see any wiring).
Schematic link: Sonoff TH
https://www.itead.cc/wiki/images/3/39/Sonoff_TH10A%2816A%29_schmatic.pdf

Schematic link: Sensor Si7021 Humidity
https://www.itead.cc/wiki/File:Sonoff_Si7021_Sensor_Schematic.pdf

pylon

The Sonoff sensor contains an Si7021 sensor but it's not directly connected to the Sonoff TH but by some microcontroller that seems to translate the I2C signals to a kind of one wire bus.

There are some indicators on the Itead Wiki that this single wire bus is compatible with DHT11/22 sensors. So try to read the sensor using that protocol but you won't be successful if you request data as if it was a directly connected SI7021.

Go Up