Cov txheej txheem:

Kev Ntsuas Kub Siv MCP9808 thiab Raspberry Pi: 4 Kauj Ruam
Kev Ntsuas Kub Siv MCP9808 thiab Raspberry Pi: 4 Kauj Ruam

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

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

MCP9808 yog qhov ntsuas qhov ntsuas qhov ntsuas qhov tseeb ntau ± 0.5 ° C I2C mini module. Lawv tau suav nrog cov npe siv tau-programmable uas pab txhawb kev thov ntsuas kub. MCP9808 qhov ntsuas qhov ntsuas qhov ntsuas kub tau dhau los ua tus qauv kev lag luam raws li daim ntawv foos thiab kev txawj ntse, muab kev ntsuas ntsuas, ntsuas qhov ntsuas qhov ntsuas hauv digital, hom I2C.

Hauv qhov kev qhia no kev cuam tshuam ntawm MCP9808 sensor module nrog raspberry pi tau pom thiab nws cov phiaj xwm siv cov lus nab nab kuj tau piav qhia. Txhawm rau nyeem 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. MCP9808

2. Raspberry Pi

3. I2C Cable

4. I2C ntaub thaiv npog 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:

MCP9808 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 Kub:

Code rau Kev Ntsuas Kub
Code rau 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. Nab hab sej yog ib qho ntawm cov lus yooj yim programming nrog cov lus yooj yim tshaj plaws. Tus nab npawb nab npawb rau MCP9808 tuaj yeem rub tawm los ntawm peb lub zej zog github uas yog DCUBE Store Community.

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 SMBus lub tsev qiv ntawv thaum muaj nab nab, vim tias lub tsev qiv ntawv no txhawb nqa cov haujlwm uas 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 cov cai ua haujlwm los ntawm no kuj:

ntshuam smbus

lub sij hawm ntshuam

# Tau I2C busbus = smbus. SMBus (1)

# MCP9808 chaw nyob, 0x18 (24)

# Xaiv kev teeb tsa rau npe, 0x01 (1)

# 0x0000 (00) Kev hloov pauv mus tas li, Lub hwj chim ua neej nyob

config = [0x00, 0x00] bus.write_i2c_block_data (0x18, 0x01, teeb tsa)

# MCP9808 chaw nyob, 0x18 (24)

# Xaiv qhov kev daws teeb meem rgister, 0x08 (8)

# 0x03 (03) Kev daws teeb meem = +0.0625 / C.

bus.write_byte_data (0x18, 0x08, 0x03)

sijhawm.s pw (0.5)

# MCP9808 chaw nyob, 0x18 (24)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x05 (5), 2 bytes

# Temp MSB, TEMP LSB

cov ntaub ntawv = bus.read_i2c_block_data (0x18, 0x05, 2)

# Hloov cov ntaub ntawv mus rau 13-ntsis

ctemp = ((cov ntaub ntawv [0] & 0x1F) * 256) + cov ntaub ntawv [1]

yog tias ctemp> 4095:

xwm -8192

ctemp = ctemp * 0.0625

ftemp = ctemp * 1.8 + 32

# Cov ntaub ntawv tso tawm rau lub vijtsam

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

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

Txoj cai tau ua tiav siv cov lus txib hauv qab no:

$> nab nab MCP9808.py gt; nab hab sej MCP9808.py

gt; nab hab sej MCP9808.py

Cov zis ntawm lub ntsuas tau pom 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

MCP9808 Digital Kub Sensor muaj ntau daim ntawv thov kev lag luam uas suav nrog cov tub yees txias thiab tub yees nrog rau ntau yam txheej txheem khoom noj. Qhov ntsuas no tuaj yeem ua haujlwm rau ntau lub khoos phis tawj ntiag tug, servers nrog rau lwm yam khoom siv hauv PC.

Pom zoo: