Sensirion’s SHTxx is a digitally interfaced humidity and temperature sensor. accurate humidity measurements normally require careful analog design, but the SHTxx moves all that complicated stuff into a single chip. Through-hole (SHT7x) and surface mount (SHT1x) versions are available, we used the surface mount SHT11 with +/-3% accuracy. We’ll show you how to use the SHTxx below.
Sensirion SHT1x/SHT7x precision humidity and temperature sensor (Octopart search, starting at $25).
This isn’t a low-cost sensor. Octopart lists a few places to get it. several smaller hobby electronics stores carry it; hobby engineering has it for $29 (#H01509-01C). We found compatible PCB footprints in sht10_11_15.lbr and sht11.lbr on the Cadsoft library download page. Pin connections for the different package types are in the datasheet: SHT1x (PDF), SHT7x (PDF).
The SHTxx has a two-wire serial interface that requires pull-up resistors (R1,2), values between 2K and 10K must work. Sensirion recommends a decoupling capacitor (C1) only if the sensor is powered over a length of wire, but we think it’s always a good idea to include one.
We’ll demonstrate the SHTxx using the Bus Pirate universal serial interface in raw2wire mode with Hi-Z outputs. The SHTxx is powered from the Bus Pirate’s 3.3volt supply. The Bus Pirate’s on-board pull-up resistors hold the bus high, eliminating the need for external resistors R1 and R2.
Schnittstelle
The SHTxx communicates over two wires using a basic serial protocol. The protocol isn’t compatible with I2C, but a single SHTxx can exist on a bus with I2C peripherals.
Befehl
Code
Measure Temperature
00000011
Measure relative Humidity
00000101
Read status Register
00000111
Write status Register
00000110
Soft-Reset
00011110
Five commands control the SHTxx, these are detailed in the table. The first 3 bits are the address (always 000), the remaining 5 bits are a special command code.
Zurücksetzen
Start a transaction by clearing any partial commands or data from a previous use. A minimum of nine clock ticks while data is high will clear the SHTxx interface. The Bus Pirate syntax to for this is -^:9; data high (-), 9 clock ticks (^:9).
Commands to the SHT11 begin with a special start condition. like an I2C start condition, this is the only time when the data signal changes with the clock signal high. This illegal condition causes the chip to prepare for a new command. The SHTxx start condition is different than I2C, allowing both types of devices to exist on the same bus.
The Bus Pirate code to generate an SHTxx style start condition is -/_\/-\ ; data starts high (-), clock up (/), data goes low (_), clock low (\), clock high (/), data goes high (-), and a final clock low transition (\) ends the Reihenfolge.
A soft reset is a good idea because it puts the chip in a default state. prior to the first temperature or humidity conversion, we send the soft reset command.
RAW2WIRE>-^:9 -/_\/-\ 0b00011110 !<–command 4xx RAW2WIRE data OUTPUT, 1 <–clear interface 4xx RAW2WIRE 0x09 CLOCK TICKS 4xx RAW2WIRE data OUTPUT, 1 <–start condition 4xx RAW2WIRE CLOCK, 1 4xx RAW2WIRE data OUTPUT, 0 4xx RAW2WIRE CLOCK, 0 4xx RAW2WIRE CLOCK, 1 4xx RAW2WIRE data OUTPUT, 1 4xx RAW2WIRE CLOCK, 0 420 RAW2WIRE WRITE: 0x1E <–soft reset code 4xx RAW2WIRE read BIT: 0 <–acknowledge bit, OK RAW2WIRE>
First, we clear the interface (-^:9), then send the start condition (-/_\/-\). The reset command (0b00011110=0x1E) follows. The SHTxx acknowledges (acks) commands by pulling the data line low for one bit after a command is transmitted. We read one bit (!) to get the acknowledgment status; 0 is success, 1 signals an error.
Temperatur
Now we can read the temperature. This happens in two steps, with a delay for the temperature conversion.
RAW2WIRE>-^:9 -/_\/-\ 0b00000011 !
4xx RAW2WIRE data OUTPUT, 1 <–clear interface
4xx RAW2WIRE 0x09 CLOCK TICKS
4xx RAW2WIRE data OUTPUT, 1 <–start condition
...
4xx RAW2WIRE CLOCK, 0
420 RAW2WIRE WRITE: 0x03 <–start temperature conversion
4xx RAW2WIRE read BIT: 0 <–ack bit, OK
RAW2WIRE>
First, we send a start condition and the temperature conversion command (00000011=0x03). The SHTxx replies to a successful command by pulling the data line low for one bit (ack). After the ack bit, the data line goes high until the conversion finishes.
RAW2WIRE>.
4xx RAW2WIRE data INPUT, STATE: 0 <–data low when done
RAW2WIRE>
When the data line goes low, the temperature conversion is finished. ‘.’ is the Bus Pirate command to read the data state without a clock tick. now we can get hold of the result.
RAW2WIRE>r_^ r_^ r_^
430 RAW2WIRE READ: 0x17 <–data byte 1
4xx RAW2WIRE data OUTPUT, 0 <–data low
4xx RAW2WIRE 0x01 CLOCK TICKS <–send ack bit
430 RAW2WIRE READ: 0xCC <–data byte 2
4xx RAW2WIRE data OUTPUT, 0
4xx RAW2WIRE 0x01 CLOCK TICKS
430 RAW2WIRE READ: 0x0C <–crc
4xx RAW2WIRE data OUTPUT, 0
4xx RAW2WIRE 0x01 CLOCK TICKS
RAW2WIRE>
Each byte read (r) rNimmt ein I2C-Stilbestätigungsbit mit den Daten niedrig. Wir tun dies mit der _ ^-Sequenz; Daten niedrig (_), eine Uhr ticken (^).
Die ersten beiden Bytes sind die Temperaturanzeige (0x17cc), gefolgt von einem CRC (0x0c). Der Rohwert (0x17cc = 6092) wird mit den Gleichung und Koeffizienten auf Seite 9 des Datenblatts in Grad Celsius umgewandelt. Temperaturwerte sind standardmäßig 14Bit:
T = -39,7 + 0,01 * x
21.22c = -39,7 + (0.01 * 6092)
Feuchtigkeit
Feuchtigkeitsumsätze werden mit Code 00000101 (0x05 Hex) gestartet.
RAW2WIRE> – ^: 9 – / _ \ / – \ 0b00000101! <-Command.
4xx Raw2Wire-Datenausgabe, 1 <-Lear-Schnittstelle
4xx Raw2Wire 0x09 Uhr Ticks
4xx Raw2wire-Datenausgabe, 1 <-start-Bedingung
...
4xx Raw2wire-Uhr, 0
420 Raw2wire Write: 0x05 <-start Feuchtigkeitsumwandlung
4xx Raw2Wire-Lese-Bit: 0 <-Art-Bit, ok
Wie zuvor ist ein neuntes Bestätigungsbit niedrig, wenn der SHTXX den Befehl verarbeitet hat.
Raw2wire>.
4xx Raw2Wire-Dateneingabe, Zustand: 0 <-Data niedrig, wenn er fertig ist
Die Datenleitung geht hoch und kehrt dann niedrig zurück, wenn die Feuchtigkeitsumwandlung durchgeführt wird.
Raw2wire> r_ ^ r_ ^ r_ ^
430 Raw2wire Lesen: 0x05 <-Data Byte 1
4xx Raw2wire-Datenausgabe, 0 <-Data niedrig
4xx Raw2wire 0x01 Uhr Ticks <-Art-Bit
430 Raw2wire Lesen: 0x80 <-Data Byte 2
4xx Raw2wire-Datenausgabe, 0
4xx Raw2Wire 0x01 Uhr Ticks
430 Raw2wire Lesen: 0x46 <-CRC
4xx Raw2wire-Datenausgabe, 0
4xx Raw2Wire 0x01 Uhr Ticks
Raw2wire>
Eine vollständige Konvertierung erzeugt eine drei Byte-Antwort. Die ersten beiden Bytes sind der Rohfeuchtigkeitslese (0x0580 = 1408), das endgültige Byte ist ein CRC (0x46), der zur Überprüfung der Datenintegrität verwendet werden kann.
Feuchtigkeitswerte haben standardmäßig 12 Bit der Auflösung, um diese Gleichung in Feuchtigkeit umwandeln:
Rh = -2,0468 + 0.0367 (x) + (-0.0000015955 * (x ^ 2))
46,46% RH = -2,0468 + 0.0367 (1408) + (-0.0000015955 * (1408 ^ 2))
Fazit
Dies ist kein kostengünstiger Sensor, sondern erfordert kein sorgfältiges analoge Design wie die Honeywell HiH-Serie. Haben Sie mit einem Feuchtigkeitssensor gearbeitet?
Wie dieser Beitrag? Überprüfen Sie die Teileartikel, die Sie möglicherweise vermisst haben.