lowpowerlab / si7021 Goto Github PK
View Code? Open in Web Editor NEWSi7021 temperature & humidity sensor arduino library
License: MIT License
Si7021 temperature & humidity sensor arduino library
License: MIT License
The datasheet for the Si7021 shows that when the serial number is requested via software, it gives the data back in two chunks, the first is 8 bytes long and the second is 6 bytes long. Some of the bytes are used for CRC (cyclic redundancy check).
The total actual bytes of serial number data amounts to 8 particular bytes out of that 14.
The problem is that the getSerialBytes(byte * buf) function only gives back 12 bytes instead of the 14 it should. Unfortunately, the 12 bytes miss one piece of the actual serial number itself. When I hooked up, in succession, the seven Si7021's that I have at the house, two of them reported the same serial number!
For my own use I edited the Si7021 library and added a function that returns just the 8 bytes that are the actual serial number we need. After I added the modified library to my project everything works and the serial numbers are unique.
Here is my function (note that it ignores the CRC bytes):
The datasheet for the Si7021 shows that when the serial number is requested via software, it gives the data back in two chunks, the first is 8 bytes long and the second is 6 bytes long. Some of the bytes are used for CRC (cyclic redundancy check).
The total actual bytes of serial number data amounts to 8 particular bytes out of that 14.
The problem is that the getSerialBytes(byte * buf) function only gives back 12 bytes instead of the 14 it should. Unfortunately, the 12 bytes miss one piece of the actual serial number itself. When I hooked up, in succession, the seven Si7021's that I have at the house, two of them reported the same serial number!
For my own use I edited the Si7021 library and added a function that returns just the 8 bytes that are the actual serial number we need. After I added the modified library to my project everything works and the serial numbers are unique.
Here is my function (note that it ignores the CRC bytes):
int SI7021::get8SerialBytes(byte * buf) {
byte serial[8];
_writeReg(SERIAL1_READ, sizeof SERIAL1_READ);
_readReg(serial, 8);
buf[0] = serial[0]; //These are the bytes
buf[1] = serial[2]; //from the datasheet
buf[2] = serial[4]; //that are the
buf[3] = serial[6]; //actual serial
_writeReg(SERIAL2_READ, sizeof SERIAL2_READ);
_readReg(serial, 6);
buf[4] = serial[0]; //Again these are the
buf[5] = serial[1]; //SN bytes
buf[6] = serial[3]; //
buf[7] = serial[4]; //
return 1;
}
I'm seeing crazy readings when temperature drops below 32 F, looks like overflow. I assumed the library can handle temperatures below 0 C? However, I do see a lot of unsigned int declarations.
Is this known/expected behavior?
Could you clarify the license this library is released under? The source files merely state to contact a Marcus Sorensen for details.
Hi
first of all - thanks for this slim and compact library.
I saw there is a sensorExists
option. I din't found much in the source code, is this option implemented?
At the moment I running into issues if the sensor is not available (...anymore) - or do somebody know other ways to stop a blocking state like this?
thanks in advance
There's no license specified, and SI7021.cpp says "This program is licensed, please check with the copyright holder for terms". It would be awesome if you could declare the license in the repository. Currently using this is basically forbidden.
void SI7021::_command(byte * cmd, byte * buf ) {
_writeReg(cmd, sizeof cmd);
_readReg(buf, sizeof buf);
}
I does not understand the sizeof of buf , it seems that you ask size of a pointer and not buffer length,
is this correct ?
i think that the correct function should be _command(byte * cmd,int cmdlen, byte * buf ,int buflen);
Am I right in saying that setHeater
resets the precision to the default?
https://github.com/LowPowerLab/SI7021/blob/master/SI7021.cpp#L156
Add library.json for platformio then call the platformio lib register
command to register it.
Hi,
I spent some time on your library this weekend. I was using it for some time with my moteinos (and without any problem).
But I saw that it does not seem to work as is on any of my ESP8266 (Wemos, Nodemcu v1.0, bare ESP12) all working at 80MHz. I found out that there was two problems :
The higher delay is strange as the datasheet (page 5) mention a worst case conversion time of 12ms. I've used 85ms everywhere and it worked fine but I guess it can be lowered.
I'll probably do a PR about that, once I'm sure that my sensor is working fine for a full week.
Another modification I made was to add CRC check of RH and Temp (Page 17 of the datasheet). Are you also interested by that (as a PR) ?
Thanks a lot for your work (and also for the moteinos)
I started using the code with MySensors and relaized that the code stops at _getCelsiusPostHumidity:
`void sendTempHumidityMeasurements(bool force) {
DEBUG_PRINTLN("sendTempHumidityMeasurements...");
bool tx = force;
si7021_thc data;// = humiditySensor.getTempAndRH();
data.humidityPercent = humiditySensor.getHumidityPercent();
data.celsiusHundredths = humiditySensor.getCelsiusHundredths();
`
The above already has my workaround as humiditySensor.getTempAndRH(); blocked the whole code forever.
I am using this sensor.
Complete code at github.
Do you know a fix?
~Josef
Hi Felix Rusu,
Realy nice library.
I was trying to use an SI7021 sensor with an esp8266, and it first didn't work. It did not initialize the sensor... I noticed that the reason is that you forgot to pass the SDA,SCL arguments to the Wire.begin function.
An easy work around is to define again the Wire.Begin(SDA,SCL) function in the sketch.
Cheears
DonDan
In the file "SI7021.cpp" in the function "readReg()" a call to Wire.requestFrom() is made and after that while-loop to wait for something. That while loop can be removed, there is nothing to wait for.
When the Wire.requestFrom() returns, the I2C transaction has completely finished and the received data is waiting in a buffer in the Wire library.
When Wire.available() is called directly after Wire.requestFrom(), it returns the number of bytes in that buffer and is the same as the number of requested bytes if the I2C transaction was successful. When there was a I2C bus error, the Wire.avaible() probably returns zero.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.