You can easily wire this breakout to any microcontroller, we'll be using an Arduino. For another kind of microcontroller, just make sure it has I2C, then port the code - its pretty simple stuff!
|
The Si7021 has a default I2C address of 0x40 and cannot be changed!
Install Adafruit_Si7021 library
To begin reading sensor data, you will need to install the Adafruit_Si7021 library (code on our github repository). It is available from the Arduino library manager so we recommend using that.
From the IDE open up the library manager...
And type in adafruit si7021 to locate the library. Click Install
Also install the Adafruit Unified Sensor library in the same way:
We also have a great tutorial on Arduino library installation at:
http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use
Load Demo
Open up File->Examples->Adafruit_Si7021->si7021 and upload to your Arduino wired up to the sensor
Thats it! Now open up the serial terminal window at 115200 speed to begin the test.
You can try breathing on the sensor to increase the humidity. The sensor reacts very fast!
Library Reference
The library we have is simple and easy to use
You can create the Adafruit_Si7021 object with:
Adafruit_Si7021 sensor = Adafruit_Si7021();
There are no pins to set since you must use the I2C bus!
Then initialize the sensor with:
sensor.begin();
this function returns True if the sensor was found and responded correctly and False if it was not found
Once initialized, you can query the temperature in °C with
sensor.readTemperature()
Which will return floating point (decimal + fractional) temperature. You can convert to Fahrenheit by multiplying by 1.8 and adding 32 as you have learned in grade school!
Reading the humidity is equally simple. Call
sensor.readHumidity()
to read the humidity also as a floating point value between 0 and 100 (this reads % humidity)
This sensor also has a serial number which you might find handy! Call sensor.readSerialNumber()
to read out the 8 bytes of unique ID. Then you can access them from sensor.sernum_a
and sensor.sernum_b