Cov txheej txheem:

Kev Ntsuas thiab Kev Ntsuas Kub Siv HTS221 thiab Raspberry Pi: 4 Cov Kauj Ruam
Kev Ntsuas thiab Kev Ntsuas Kub Siv HTS221 thiab Raspberry Pi: 4 Cov Kauj Ruam

Video: Kev Ntsuas thiab Kev Ntsuas Kub Siv HTS221 thiab Raspberry Pi: 4 Cov Kauj Ruam

Video: Kev Ntsuas thiab Kev Ntsuas Kub Siv HTS221 thiab Raspberry Pi: 4 Cov Kauj Ruam
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Kaum ib hlis
Anonim
Image
Image

HTS221 yog lub ntsuas hluav taws xob me me uas muaj peev xwm ntsuas tau rau qhov txheeb ze thiab qhov kub thiab txias. Nws suav nrog lub hauv paus ntsiab lus thiab qhov sib xyaw ua ke daim ntawv thov tshwj xeeb kev sib xyaw ua ke (ASIC) los muab cov ntaub ntawv ntsuas los ntawm kev cuam tshuam digital. Kev koom ua ke nrog ntau cov yam ntxwv no yog ib qho ntawm cov ntsuas tsim nyog tshaj plaws rau qhov ntsuas qhov ntsuas cua thiab ntsuas kub.

Hauv qhov kev qhia no kev cuam tshuam ntawm HTS221 sensor module nrog raspberry pi tau pom thiab nws cov phiaj xwm siv cov lus nab nab kuj tau piav qhia. Txhawm rau nyeem cov av noo thiab qhov ntsuas kub, peb tau siv raspberry pi nrog I2C adapter Qhov no I2C adapter ua rau kev txuas mus rau lub ntsuas qhov ntsuas tau yooj yim thiab ntseeg tau ntau dua.

Kauj Ruam 1: Yuav Tsum Kho Vajtse:

Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse

Cov ntaub ntawv uas peb xav tau kom ua tiav peb lub hom phiaj suav nrog cov khoom siv hauv qab no:

1. HTS221

2. Raspberry Pi

3. I2C Cable

4. I2C Shield rau raspberry pi

5. Ethernet Cable

Kauj ruam 2: Khoos phis tawj sib txuas:

Kho vajtse Hookup
Kho vajtse Hookup
Kho vajtse Hookup
Kho vajtse Hookup

Tshooj khoos phis tawj sib txuas ntu piav qhia qhov txuas txuas uas xav tau ntawm lub ntsuas cua thiab raspberry pi. Ua kom muaj kev sib txuas raug yog qhov tseem ceeb xav tau thaum ua haujlwm ntawm ib qho system rau qhov xav tau cov zis. Yog li, qhov xav tau kev sib txuas yog raws li hauv qab no:

HTS221 yuav ua haujlwm dhau I2C. Nov yog qhov piv txwv kab hluav taws xob daim duab, qhia txog yuav ua li cas xaim txhua lub interface ntawm lub sensor.

Tawm-ntawm-lub thawv, lub rooj tsavxwm tau teeb tsa rau I2C interface, zoo li peb pom zoo siv qhov kev sib txuas no yog tias koj tsis ntseeg lwm yam.

Txhua yam koj xav tau yog plaub lub xov hlau! Tsuas yog plaub qhov kev sib txuas xav tau Vcc, Gnd, SCL thiab SDA tus pin thiab cov no txuas nrog kev pab ntawm I2C cable.

Cov kev sib txuas no tau qhia hauv cov duab saum toj no.

Kauj Ruam 3: Txoj Cai rau Kev Ntsuas thiab Kev Ntsuas Kub:

Txoj Cai rau Kev Ntsuas thiab Kev Ntsuas Kub
Txoj Cai rau Kev Ntsuas thiab Kev Ntsuas Kub

Qhov zoo ntawm kev siv raspberry pi yog, uas yog muab rau koj qhov kev hloov pauv ntawm cov lus programming uas koj xav tau los teeb tsa lub rooj tsav xwm txhawm rau txhawm rau cuam tshuam lub sensor nrog nws. Kev siv cov txiaj ntsig zoo ntawm pawg thawj coj no, peb tab tom qhia ntawm no nws cov phiaj xwm hauv nab hab sej. Tus nab npawb nab npawb rau HTS221 tuaj yeem rub tawm los ntawm peb lub zej zog github uas yog Tswj Txhua Lub Zej Zog.

Ntxiv rau qhov yooj yim ntawm cov neeg siv, peb tab tom piav qhia cov cai ntawm no thiab:

Raws li thawj kauj ruam ntawm kev sau koj yuav tsum rub lub tsev qiv ntawv smbus thaum muaj nab nab, vim tias lub tsev qiv ntawv no txhawb nqa cov haujlwm siv hauv txoj cai. Yog li, txhawm rau rub lub tsev qiv ntawv koj tuaj yeem mus ntsib qhov txuas hauv qab no:

pypi.python.org/pypi/smbus-cffi/0.5.1

Koj tuaj yeem luam tus nab npawb nab npawb ua haujlwm rau lub ntsuas no los ntawm no kuj:

ntshuam smbus

lub sij hawm ntshuam

# Tau I2C npav

npav = smbus. SMBus (1)

# HTS221 chaw nyob, 0x5F (95)

# Xaiv qhov nruab nrab teeb tsa sau npe, 0x10 (16)

# 0x1B (27) Qhov ntsuas kub nruab nrab piv txwv = 256, Qhov ntsuas nruab nrab vaum = 512

bus.write_byte_data (0x5F, 0x10, 0x1B)

# HTS221 chaw nyob, 0x5F (95)

# Xaiv tswj sau npe1, 0x20 (32)

# 0x85 (133) Hwj chim ON, Hloov tshiab tas li, Cov ntaub ntawv tso tawm tus nqi = 1 Hz

bus.write_byte_data (0x5F, 0x20, 0x85)

sijhawm.s pw (0.5)

# HTS221 chaw nyob, 0x5F (95)

# Nyeem Calibration qhov tseem ceeb los ntawm lub cim xeeb tsis hloov pauv ntawm lub cuab yeej

# Humidity Calibration qhov tseem ceeb

# Nyeem cov ntaub ntawv rov qab los ntawm 0x30 (48), 1 byte

val = bus.read_byte_data (0x5F, 0x30)

H0 = val / 2

# Nyeem cov ntaub ntawv rov qab los ntawm 0x31 (49), 1 byte

val = bus.read_byte_data (0x5F, 0x31)

H1 = val /2

# Nyeem cov ntaub ntawv rov qab los ntawm 0x36 (54), 2 bytes

val0 = bus.read_byte_data (0x5F, 0x36)

val1 = bus.read_byte_data (0x5F, 0x37)

H2 = ((val1 & 0xFF) * 256) + (val0 & 0xFF)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x3A (58), 2 bytes

val0 = bus.read_byte_data (0x5F, 0x3A)

val1 = bus.read_byte_data (0x5F, 0x3B)

H3 = ((val1 & 0xFF) * 256) + (val0 & 0xFF)

# Qhov ntsuas ntsuas qhov ntsuas kub

# Nyeem cov ntaub ntawv rov qab los ntawm 0x32 (50), 1 byte

T0 = bus.read_byte_data (0x5F, 0x32)

T0 = (T0 & 0xFF)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x32 (51), 1 byte

T1 = bus.read_byte_data (0x5F, 0x33)

T1 = (T1 & 0xFF)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x35 (53), 1 byte

raw = bus.read_byte_data (0x5F, 0x35)

raw = (raw & 0x0F)

# Hloov qhov ntsuas Kub ntsuas qhov ntsuas kom 10-ntsis

T0 = ((raw & 0x03) * 256) + T0

T1 = ((raw & 0x0C) * 64) + T1

# Nyeem cov ntaub ntawv rov qab los ntawm 0x3C (60), 2 bytes

val0 = bus.read_byte_data (0x5F, 0x3C)

val1 = bus.read_byte_data (0x5F, 0x3D)

T2 = ((val1 & 0xFF) * 256) + (val0 & 0xFF)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x3E (62), 2 bytes

val0 = bus.read_byte_data (0x5F, 0x3E)

val1 = bus.read_byte_data (0x5F, 0x3F)

T3 = ((val1 & 0xFF) * 256) + (val0 & 0xFF)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x28 (40) nrog hais kom sau npe 0x80 (128), 4 bytes

# av noo msb, av noo lsb, temp msb, kub lsb

data = bus.read_i2c_block_data (0x5F, 0x28 | 0x80, 4)

# Hloov cov ntaub ntawv

av noo = (cov ntaub ntawv [1] * 256) + cov ntaub ntawv [0]

av noo = ((1.0 * H1) - (1.0 * H0)) * (1.0 * av noo - 1.0 * H2) / (1.0 * H3 - 1.0 * H2) + (1.0 * H0)

temp = (cov ntaub ntawv [3] * 256) + cov ntaub ntawv [2]

Yog tias kub> 32767:

temp -= 65536

cTemp = ((T1 - T0) / 8.0) * (temp - T2) / (T3 - T2) + (T0 / 8.0)

fTemp = (cTemp * 1.8) + 32

# Cov ntaub ntawv tso tawm rau lub vijtsam

luam tawm "txheeb ze vaum: %.2f %%" %av noo

luam tawm "Kub hauv Celsius: %.2f C" %cTemp

luam tawm "Kub hauv Fahrenheit: %.2f F" %fTemp

Ib feem ntawm cov cai hais hauv qab no suav nrog cov tsev qiv ntawv xav tau los ua kom raug ntawm cov nab npawb nab npawb.

ntshuam smbus

lub sij hawm ntshuam

Txoj cai tuaj yeem ua tiav los ntawm kev ntaus cov lus hais hauv qab no hauv kab hais kom ua.

$> nab hab sej HTS221.py

Cov zis ntawm lub ntsuas kuj tseem muaj nyob hauv daim duab saum toj no rau kev siv ntawm tus neeg siv.

Kauj Ruam 4: Cov ntawv thov:

Cov ntawv thov
Cov ntawv thov

HTS221 tuaj yeem ua haujlwm hauv ntau yam khoom siv xws li huab cua ua kom txias thiab tub yees thiab lwm yam.

Pom zoo: