Mysensors si7021 sketch
-
Dear All!
Has anybody a sketch for this temperature and humidity sensor? I would like to use it with mini pro combined easypcb board.
Thank you in advance!
-
@Tommas - some resources i found.
https://forum.mysensors.org/topic/2432/si7021-multisensor-first-try
https://github.com/mysensors/MySensorsArduinoExamples/tree/master/libraries/SI7021
https://forum.mysensors.org/topic/6434/solved-problems-with-an-si7021-temp-humidity-sensor/3
-
Dear @sundberg84
Thanks for the suggestions!
Another, which pin should i connect to the si7021? I cant find this info...Thanks,
-
@Tommas the si7021 uses i2c so you can use the wiring described at https://www.mysensors.org/build/light-bh1750 which also is an i2c device.
-
Dear @mfalkvidd !
Thank you, and to everyone for the help!
I got it work!
If the sketch will be completed i will upload that!
-
What is the problem with my sketch? It is in developement phase, but the reading stops at this line, but sometimes it works for 3-4 loop...
" DEBUG_PRINTLN("Send TEMP and HUM started"); "
/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * REVISION HISTORY * Version 1.0: Henrik EKblad * Version 1.1 - 2016-07-20: Converted to MySensors v2.0 and added various improvements - Torben Woltjen (mozzbozz) * * DESCRIPTION * This sketch provides an example of how to implement a humidity/temperature * sensor using a DHT11/DHT-22. * * For more information, please visit: * http://www.mysensors.org/build/humidity * */ #define MY_NODE_ID 4 // Enable debug prints #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 //#define MY_RS485 /* Sketch with Si7021 and battery monitoring. by m26872, 20151109 */ #include <MySensors.h> #include <Wire.h> #include <SI7021.h> #include <SPI.h> #include <RunningAverage.h> #define DEBUG #ifdef DEBUG #define DEBUG_SERIAL(x) Serial.begin(x) #define DEBUG_PRINT(x) Serial.print(x) #define DEBUG_PRINTLN(x) Serial.println(x) #else #define DEBUG_SERIAL(x) #define DEBUG_PRINT(x) #define DEBUG_PRINTLN(x) #endif #define NODE_ID 4 // <<<<<<<<<<<<<<<<<<<<<<<<<<< Enter Node_ID #define CHILD_ID_TEMP 0 #define CHILD_ID_HUM 1 //#define SLEEP_TIME 15000 // 15s for DEBUG #define SLEEP_TIME 10000 // 5 min //#define FORCE_TRANSMIT_CYCLE 36 // 5min*12=1/hour, 5min*36=1/3hour #define FORCE_TRANSMIT_CYCLE 1 // 5min*12=1/hour, 5min*36=1/3hour //#define BATTERY_REPORT_CYCLE 2880 // Once per 5min => 12*24*7 = 2016 (one report/week) //#define VMIN 1900 //#define VMAX 3300 #define HUMI_TRANSMIT_THRESHOLD 3.0 // THRESHOLD tells how much the value should have changed since last time it was transmitted. #define TEMP_TRANSMIT_THRESHOLD 0.5 #define AVERAGES 2 //int batteryReportCounter = BATTERY_REPORT_CYCLE - 1; // to make it report the first time. int measureCount = 0; float lastTemperature = -100; int lastHumidity = -100; RunningAverage raHum(AVERAGES); SI7021 humiditySensor; //MySensor gw; MyMessage msgTemp(CHILD_ID_TEMP,V_TEMP); // Initialize temperature message MyMessage msgHum(CHILD_ID_HUM,V_HUM); void presentation(){ sendSketchInfo("Node 4, Temp,Hum sensor", "1.1"); present(CHILD_ID_TEMP, S_TEMP); // Present sensor to controller present(CHILD_ID_HUM, S_HUM); } void setup() { DEBUG_SERIAL(115200); DEBUG_PRINTLN("Serial started"); //DEBUG_PRINT("Voltage: "); //DEBUG_PRINT(readVcc()); //DEBUG_PRINTLN(" mV"); /* delay(500); DEBUG_PRINT("Internal temp: "); DEBUG_PRINT(GetInternalTemp()); // Probably not calibrated. Just to print something. DEBUG_PRINTLN(" *C"); */ delay(500); // Allow time for radio if power useed as reset //begin(NULL,NODE_ID); //DEBUG_PRINT("Node and "); DEBUG_PRINTLN("2 children presented."); raHum.clear(); } void loop() { DEBUG_PRINTLN("Loop started"); measureCount ++; bool forceTransmit = true; //if (measureCount > FORCE_TRANSMIT_CYCLE) { //forceTransmit = true; //} sleep(SLEEP_TIME); sendTempHumidityMeasurements(forceTransmit); DEBUG_PRINTLN("Loop ended"); } /********************************************* * * Sends temperature and humidity from Si7021 sensor * Parameters * - force : Forces transmission of a value (even if it's the same as previous measurement) *********************************************/ void sendTempHumidityMeasurements(bool force) { bool tx = force; DEBUG_PRINTLN("Send TEMP and HUM started"); si7021_env data = humiditySensor.getHumidityAndTemperature(); float temperature = data.celsiusHundredths / 100.0; DEBUG_PRINT("T: ");DEBUG_PRINTLN(temperature); float diffTemp = abs(lastTemperature - temperature); DEBUG_PRINT(F("TempDiff :"));DEBUG_PRINTLN(diffTemp); //if (diffTemp > TEMP_TRANSMIT_THRESHOLD || tx) { send(msgTemp.set(temperature, 1)); //lastTemperature = temperature; //measureCount = 0; DEBUG_PRINTLN("T sent!"); //} int humidity = data.humidityPercent; DEBUG_PRINT("H: ");DEBUG_PRINTLN(humidity); raHum.addValue(humidity); humidity = raHum.getAverage(); // MA sample imply reasonable fast sample frequency float diffHum = abs(lastHumidity - humidity); DEBUG_PRINT(F("HumDiff :"));DEBUG_PRINTLN(diffHum); //if (diffHum > HUMI_TRANSMIT_THRESHOLD || tx) { send(msgHum.set(humidity, 1)); //lastHumidity = humidity; //measureCount = 0; DEBUG_PRINTLN("H sent!"); //} }
-
@Tommas - sorry, im not the code expert...
If it stops without any indication why it can be a power issue as well.
-
There arent any indication. Sometimes it works.... i tried another si7021 and same. Voltage is Ok. A connected the sda - A4 scl - A5 on easypcb board
Any idea?
-
@Tommas do you have pullups (around 10k) at sda & scl lines?
-
Dear @Yveaux
I think that yes. The si7021 module has an smd 103 part on it. Maybe it is at the sda and scl but im not sure.
https://www.ebay.com/i/401364416322
Thanks
-
Hello,
you are missing the sensor.begin() to initialize the sensor. Return value will tell you if initialization succeeded or not.
if (!sensor.begin()) { #ifdef MY_DEBUG Serial.println("FAILED TO INIT SENSOR !!!!"); #endif ... }