Adafruit Industries LLC 的 Si7021 Temperature + Humidity Sensor Guide 规格书

5179-21 m e t S V. S Q m n r a m .0“ u r f a d a
Adafruit Si7021 Temperature + Humidity Sensor
Created by lady ada
Last updated on 2018-11-21 06:58:57 PM UTC
2
3
5
5
5
6
6
7
8
10
10
11
12
14
14
14
14
15
15
16
17
18
18
18
18
Guide Contents
Guide Contents
Overview
Pinouts
Power Pins:
I2C Logic pins:
Assembly
Prepare the header strip:
Add the breakout board:
And Solder!
Arduino Code
Install Adafruit_Si7021 library
Load Demo
Library Reference
Python & CircuitPython
CircuitPython Microcontroller Wiring
Python Computer Wiring
CircuitPython Installation of Si7021 Library
Python Installation of Si7021 Library
CircuitPython & Python Usage
Full Example Code
Python Library Docs
Downloads
Files & Datasheets
Schematic
Fabrication Print
© Adafruit Industries https://learn.adafruit.com/adafruit-si7021-temperature-plus-humidity-sensor Page 2 of 19
In, n. n. n n; n. M: M H I! H H H H
Overview
It's summer and you're sweating and your hair's all frizzy and all you really want to know is why the weatherman said
this morning that today's relative humidity would max out at a perfectly reasonable 42% when it feels more like 77%.
Enter the Si7021 Temperature + Humidity Sensor - the best way to prove the weatherman wrong!
This lovely sensor for Silicon labs has ± 3% relative humidity measurements with a range of 0–80% RH, and ±0.4 °C
temperature accuracy at a range of -10 to +85 °C. Great for all of your environmental sensing projects. It uses I2C for
data transfer so it works with a wide range of microcontrollers.
© Adafruit Industries https://learn.adafruit.com/adafruit-si7021-temperature-plus-humidity-sensor Page 3 of 19
0&0 Temp l Humidiw UIN: 3.3-50 Logic: 3. -5V '1 1'
We put this nice sensor on a breakout board with a 3.3V regulator and level shifting so you can use it safely with 3.3V
or 5V power & logic. There's a PTFE filter to keep the sensor clean, that's the white flat thing on top. Also comes with
some pin header. Some light soldering is required to attach the header but it's easy to do.
© Adafruit Industries https://learn.adafruit.com/adafruit-si7021-temperature-plus-humidity-sensor Page 4 of 19
Pinouts
The Si7021 is a I2C sensor. That means it uses the two I2C data/clock wires available on most microcontrollers, and
can share those pins with other sensors as long as they don't have an address collision. For future reference, the I2C
address is 0x40 and you
can't
change it!
Power Pins:
Vin - this is the power pin. Since the chip uses 3 VDC, we have included a voltage regulator on board that will
take 3-5VDC and safely convert it down. To power the board, give it the same power as the logic level of your
microcontroller - e.g. for a 5V micro like Arduino, use 5V
3v3 - this is the 3.3V output from the voltage regulator, you can grab up to 100mA from this if you like
GND - common ground for power and logic
I2C Logic pins:
SCL - I2C clock pin, connect to your microcontrollers I2C clock line.
SDA - I2C data pin, connect to your microcontrollers I2C data line.
© Adafruit Industries https://learn.adafruit.com/adafruit-si7021-temperature-plus-humidity-sensor Page 5 of 19
L92... L93... £5993 .25.?! +1.9: .:.:.u. $5.3; .9223. m . HIS“
Assembly
The photos below show a an HTUD21 sensor rather than the Si7021 but the soldering procedure is identical!
Prepare the header strip:
Cut the strip to length if necessary. It will be easier to
solder if you insert it into a breadboard - long pins down
© Adafruit Industries https://learn.adafruit.com/adafruit-si7021-temperature-plus-humidity-sensor Page 6 of 19
Add the breakout board:
Place the breakout board over the pins so that the short
pins poke through the breakout pads
© Adafruit Industries https://learn.adafruit.com/adafruit-si7021-temperature-plus-humidity-sensor Page 7 of 19
.p nnn‘.
And Solder!
Be sure to solder all pins for reliable electrical contact.
(For tips on soldering, be sure to check out our Guide to
Excellent Soldering
(https://adafru.it/aTk)
).
You're done! Check your solder joints visually and
continue onto the next steps
© Adafruit Industries https://learn.adafruit.com/adafruit-si7021-temperature-plus-humidity-sensor Page 8 of 19
Verify/Comp“: cum Upload cm~u Upload Using ngvamma cwsnmw H Dem Expo-t compiled Binary cm~An.s A Manage Libmis... demo Md .ZIP Libnlym Avduma humus hnclud Show 5mm rolau cum nuclud Mud! “hwy Arauinompcnem hnclud ArduinoSound Md File... Aulfanem midn- ,r/ u: 119m: one plxe] at a an,
Arduino Code
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!
Connect Vin to the power supply, 3-5V is fine. Use
the same voltage that the microcontroller logic is
based off of. For most Arduinos, that is 5V
Connect GND to common power/data ground
Connect the SCL pin to the I2C clock SCL pin on
your Arduino. On an UNO & '328 based Arduino,
this is also known as A5, on a Mega it is also
known as digital 21 and on a Leonardo/Micro,
digital 3
Connect the SDA pin to the I2C data SDA pin on
your Arduino. On an UNO & '328 based Arduino,
this is also known as A4, on a Mega it is also
known as digital 20 and on a Leonardo/Micro,
digital 2
https://adafru.it/rAA
https://adafru.it/rAA
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) (https://adafru.it/rAw). 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
© Adafruit Industries https://learn.adafruit.com/adafruit-si7021-temperature-plus-humidity-sensor Page 9 of 19
e mum, >< m.="" \u="" 4m="" \.="" v="" m.="" mm“...="" by="" ma="" a="" m...,c.m.="_," a...“="" sum”.="" mm)="" mum-4m="" nun—m="" km="" o="" o="" mann/manna="" m,="" a"="" in,”="" m="" manama.="" “mummgm="" “m.="" ,="" n="" m...»="" mumm-qunn="" um.="" s...”="" nun-inna;="" a="" mm="" m7="" ”ammo"="" live!="" w="" :94="" mm="" mum="" mm“;="" mm="" a="" wmjecm="" "—="" mufcshauzc=""> wmpwm > Wmvcmw > Wmljsljmxhpad > Manama-92m > Wmumrwan ray 0°! CWW Mar-mums: > Save CW5 Manny/I121 ; SaveAs.“ mum»: Wmtsonsgw > | Paggsallp ems-um.» “”th ' I , WHALSMSUS b , mm cmw . magnum > : Pvdmcs crummy Wmumsm r l , WIMKTFI'LCD r . Qua cum) Mm‘njlcwnl >
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 (https://adafru.it/aYM)
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.
© Adafruit Industries https://learn.adafruit.com/adafruit-si7021-temperature-plus-humidity-sensor Page 10 of 19
Taper-cure raver-um Inna-cm rapt-mm Inner-cm rape-um Taper-cure raver-um Tenn-lune rapt-mm Inner-cm Twang : rape-um:
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:
There are no pins to set since you must use the I2C bus!
Then initialize the sensor with:
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
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
to read the humidity also as a floating point value between 0 and 100 (this reads % humidity)
Adafruit_Si7021 sensor = Adafruit_Si7021();
sensor.begin();
sensor.readTemperature()
sensor.readHumidity()
© Adafruit Industries https://learn.adafruit.com/adafruit-si7021-temperature-plus-humidity-sensor Page 11 of 19
Cr
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
© Adafruit Industries https://learn.adafruit.com/adafruit-si7021-temperature-plus-humidity-sensor Page 12 of 19
non.
Python & CircuitPython
It's easy to use the Si7021 sensor with Python or CircuitPython and the Adafruit CircuitPython
SI7021 (https://adafru.it/BfV) module. This module allows you to easily write Python code that reads the humidity and
temperature, pressurefrom the sensor.
You can use this sensor with any CircuitPython microcontroller board or with a computer that has GPIO and Python
thanks to Adafruit_Blinka, our CircuitPython-for-Python compatibility library (https://adafru.it/BSN).
CircuitPython Microcontroller Wiring
First wire up a SI7021 to your board exactly as shown on the previous pages for Arduino. Here's an example of wiring a
Feather M0 to the sensor with I2C:
Board 3V to sensor VIN
Board GND to sensor GND
Board SCL to sensor SCL
Board SDA to sensor SDA
Python Computer Wiring
Since there's
dozens
of Linux computers/boards you can use we will show wiring for Raspberry Pi. For other platforms,
please visit the guide for CircuitPython on Linux to see whether your platform is supported (https://adafru.it/BSN).
Here's the Raspberry Pi wired with I2C:
Pi 3V3 to sensor VIN
Pi GND to sensor GND
Pi SCL to sensor SCL
Pi SDA to sensor SDA
CircuitPython Installation of Si7021 Library
You'll need to install the Adafruit CircuitPython SI7021 (https://adafru.it/BfV) library on your CircuitPython board.
First make sure you are running the latest version of Adafruit CircuitPython (https://adafru.it/tBa) for your board.
Next you'll need to install the necessary libraries to use the hardware--carefully follow the steps to find and install these
libraries from Adafruit's CircuitPython library bundle (https://adafru.it/zdx). For example the Circuit Playground Express
guide has a great page on how to install the library bundle (https://adafru.it/Bf2) for both express and non-express
© Adafruit Industries https://learn.adafruit.com/adafruit-si7021-temperature-plus-humidity-sensor Page 13 of 19
boards
boards.
Remember for non-express boards like the Trinket M0, Gemma M0, and Feather/Metro M0 basic you'll need to
manually install the necessary libraries from the bundle:
adafruit_si7021.mpy
adafruit_bus_device
You can also download the adafruit_si7021.mpy from its releases page on Github (https://adafru.it/BfW).
Before continuing make sure your board's lib folder or root filesystem has
the adafruit_si7021.mpy, and adafruit_bus_device files and folders copied over.
Next connect to the board's serial REPL (https://adafru.it/pMf)so you are at the CircuitPython >>> prompt.
Python Installation of Si7021 Library
You'll need to install the Adafruit_Blinka library that provides the CircuitPython support in Python. This may also
require enabling I2C on your platform and verifying you are running Python 3. Since each platform is a little different,
and Linux changes often, please visit the CircuitPython on Linux guide to get your computer
ready (https://adafru.it/BSN)!
Once that's done, from your command line run the following command:
sudo pip3 install adafruit-circuitpython-si7021
If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use
CircuitPython on Python 2.x, it isn't supported!
CircuitPython & Python Usage
To demonstrate the usage of the sensor we'll initialize it and read the temperature and humidity from the board's
Python REPL. First run the following code to import the necessary modules and initialize the I2C bus:
Now you're ready to read values from the sensor using any of these properties:
temperature - The sensor temperature in degrees Celsius.
relative_humidity - The percent humidity as a value from 0 to 100%.
import board
import busio
import adafruit_si7021
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_si7021.SI7021(i2c)
print('Temperature: {} degrees C'.format(sensor.temperature))
print('Humidity: {}%'.format(sensor.relative_humidity))
© Adafruit Industries https://learn.adafruit.com/adafruit-si7021-temperature-plus-humidity-sensor Page 14 of 19
That's all there is to using the Si7021 sensor with CircuitPython!
Full Example Code
import time
import board
import busio
import adafruit_si7021
# Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_si7021.SI7021(i2c)
while True:
print("\nTemperature: %0.1f C" % sensor.temperature)
print("Humidity: %0.1f %%" % sensor.relative_humidity)
time.sleep(2)
© Adafruit Industries https://learn.adafruit.com/adafruit-si7021-temperature-plus-humidity-sensor Page 15 of 19
Python Library Docs
Python Library Docs (https://adafru.it/C3f)
© Adafruit Industries https://learn.adafruit.com/adafruit-si7021-temperature-plus-humidity-sensor Page 16 of 19
Downloads
Files & Datasheets
Fritzing object in Adafruit Fritzing library (https://adafru.it/aP3)
Arduino library on GitHub (https://adafru.it/rAw)
EagleCAD PCB files on GitHub (https://adafru.it/rAB)
Si7021-A20 datasheet (https://adafru.it/rAC)
K&R Smith calibration notes (https://adafru.it/BfU)
Schematic
Fabrication Print
© Adafruit Industries https://learn.adafruit.com/adafruit-si7021-temperature-plus-humidity-sensor Page 17 of 19
© Adafruit Industries https://learn.adafruit.com/adafruit-si7021-temperature-plus-humidity-sensor Page 18 of 19