Cov txheej txheem:

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

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

Video: Raspberry Pi TMP112 Kub Sensor Python Qhia: 4 Kauj Ruam
Video: How to Interface the TMP102 & TMP112 Temperature Sensors with Arduino 2024, Kaum ib hlis
Anonim
Image
Image
Yam Koj Xav Tau.. !!
Yam Koj Xav Tau.. !!

TMP112 High-Accuracy, Low-Power, Digital Kub Sensor I2C MINI module. TMP112 yog qhov zoo tshaj rau kev ntsuas kub ntxiv. Cov cuab yeej no muab qhov tseeb ntawm ± 0.5 ° C yam tsis tas yuav ntsuas qhov ntsuas lossis sab nrauv tiv thaiv teeb liab. Nov yog qhov ua piv txwv nrog Java code siv Raspberry Pi.

Kauj Ruam 1: Yam Koj Xav Tau..

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

1. Raspberry Pi

2. TMP112

3. I²C Cable

4. I²C Shield rau Raspberry Pi

5. Ethernet Cable

Kauj ruam 2: 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 TMP112 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 TMP112 tuaj yeem rub tawm los ntawm peb GitHub chaw cia khoom- Dcube Store.

Nov yog qhov txuas rau tib yam:

github.com/DcubeTechVentures/TMP112

Cov ntawv ntawm TMP112 tuaj yeem pom ntawm no:

www.ti.com/lit/ds/sbos473e/sbos473e.pdf

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.

#TMP112

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

ntshuam smbus

lub sij hawm ntshuam

# Tau I2C npav

npav = smbus. SMBus (1)

# TMP112 chaw nyob, 0x48 (72)

# Xaiv Configuration register, 0x01 (1)

# 0x60A0 (24736) Kev hloov pauv mus tas li, 12-ntsis kev daws teeb meem, Kev ua tsis raug yog 1 qhov txhaum

# Polarity qis, Thermostat hauv hom sib piv, Xiam oob khab hom# Hom qub, cov ntaub ntawv 12-ntsis

data = [0x60A0] bus.write_i2c_block_data (0x48, 0x01, cov ntaub ntawv)

sijhawm.s pw (0.5)

# TMP112 chaw nyob, 0x48 (72)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x00 (0), 2 bytes, MSB ua ntej

cov ntaub ntawv = bus.read_i2c_block_data (0x48, 0x00, 2)

# Hloov cov ntaub ntawv

temp = (cov ntaub ntawv [0] * 256 + cov ntaub ntawv [1]) / 16

Yog tias kub> 2047:

temp -= 4096

cTemp = temp * 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..:

Ntau daim ntawv thov suav nrog TMP112 lub zog qis, qhov tseeb cov ntsuas ntsuas kub suav nrog Lub Hwj Huam Saib Xyuas Kub Kub, Khoos phis tawj Ib puag ncig tiv thaiv cua sov, Kev tswj roj teeb nrog rau lub tshuab ua haujlwm.

Pom zoo: