Cov txheej txheem:

Raspberry Pi MCP9808 Kub Sensor Python Qhia: 4 Kauj Ruam
Raspberry Pi MCP9808 Kub Sensor Python Qhia: 4 Kauj Ruam

Video: Raspberry Pi MCP9808 Kub Sensor Python Qhia: 4 Kauj Ruam

Video: Raspberry Pi MCP9808 Kub Sensor Python Qhia: 4 Kauj Ruam
Video: Датчик температуры MCP9808, обзор и сравнение 2024, Hlis ntuj nqeg
Anonim
Image
Image
Yam Koj Xav Tau.. !!
Yam Koj Xav Tau.. !!

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. Nov yog qhov ua piv txwv nrog tus nab npawb nab npawb siv Raspberry Pi.

Kauj Ruam 1: Yam Koj Xav Tau..

Yam Koj Xav Tau.. !!
Yam Koj Xav Tau.. !!

1. Raspberry Pi

2. MCP9808

3. I²C Cable

4. I²C Shield rau Raspberry Pi

5. Ethernet Cable

Kauj ruam 2: Kev sib txuas

Kev sib txuas
Kev sib txuas
Kev sib txuas
Kev sib txuas
Kev sib txuas
Kev sib txuas
Kev sib txuas
Kev sib txuas

Siv I2C daim thaiv rau raspberry pi thiab maj mam thawb nws hla gpio pins ntawm raspberry pi.

Tom qab ntawd txuas ib qho kawg ntawm I2C cable rau MCP9808 sensor thiab lwm qhov kawg rau I2C daim ntaub thaiv.

Kuj txuas Ethernet cable rau pi lossis koj tuaj yeem siv WiFi module.

Kev sib txuas tau qhia hauv daim duab saum toj no.

Kauj ruam 3: Code

Tus nab npawb nab npawb rau MCP9808 tuaj yeem rub tawm los ntawm peb GitHub chaw cia khoom- Dcube Store

Nov yog qhov txuas rau tib yam:

github.com/DcubeTechVentures/MCP9808

Cov ntaub ntawv ntawm MCP9808 tuaj yeem pom ntawm no:

ww1.microchip.com/downloads/en/DeviceDoc/25…

Peb tau siv SMBus lub tsev qiv ntawv rau sej code, cov kauj ruam rau nruab SMBus ntawm raspberry pi tau piav qhia ntawm no:

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

Koj tseem tuaj yeem luam cov cai los ntawm no, nws tau muab raws li hauv qab no:

# Faib nrog daim ntawv tso cai yuav dawb.

# Siv nws txhua txoj hauv kev uas koj xav tau, muaj txiaj ntsig lossis pub dawb, muab nws haum rau hauv daim ntawv tso cai ntawm nws cov haujlwm sib txuam.

# MCP9808

# Txoj cai no tau tsim los ua haujlwm nrog MCP9808_I2CS I2C Mini Module muaj nyob hauv Dcube Store.

ntshuam smbus

lub sij hawm ntshuam

# Tau I2C npav

npav = 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

teeb tsa = [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)

time.sleep (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

Kauj ruam 4: 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: