Cov txheej txheem:

Raspberry Pi - TCN75A Kub Sensor Python Qhia: 4 Kauj Ruam
Raspberry Pi - TCN75A Kub Sensor Python Qhia: 4 Kauj Ruam

Video: Raspberry Pi - TCN75A Kub Sensor Python Qhia: 4 Kauj Ruam

Video: Raspberry Pi - TCN75A Kub Sensor Python Qhia: 4 Kauj Ruam
Video: Raspberry Pi TCN75A Temperature Sensor Java Tutorial 2024, Hlis ntuj nqeg
Anonim
Image
Image

TCN75A yog ob txoj kab hluav taws xob ntsuas kub sib xyaw ua ke nrog ntsuas kub-rau-digital hloov pauv. Nws tau suav nrog cov neeg siv cov ntawv sau npe uas muab kev hloov pauv rau kev thov ntsuas kub. Cov chaw tso npe tso cai rau cov neeg siv teeb tsa hom kev txuag hluav taws xob, kaw lub kaw lus, ib hom kev txhaj tshuaj thiab lwm yam. Nov yog nws qhov ua piv txwv nrog raspberry pi siv tus lej nab npawb.

Kauj Ruam 1: Yam Koj Xav Tau..

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

1. Raspberry Pi

2. TCN75A

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 kawg ntawm I2C cable rau TCN75A 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:

Txoj Cai
Txoj Cai

Tus nab npawb nab npawb rau TCN75A tuaj yeem rub tawm los ntawm peb qhov chaw cia khoom github-DCUBE Store.

Nov yog qhov txuas rau tib yam:

github.com/DcubeTechVentures/TCN75A/blob/master/Python/TCN75A.py

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.

# TCN75A

# Txoj cai no yog tsim los ua haujlwm nrog TCN75A_I2CS I2C Mini Module.

ntshuam smbus

lub sij hawm ntshuam

# Tau I2C npav

npav = smbus. SMBus (1)

# TCN75A chaw nyob, 0x48 (72)

# Xaiv kev teeb tsa sau npe, 0x01 (01)

# 0x60 (96) 12-ntsis ADC daws teeb meem

bus.write_byte_data (0x48, 0x01, 0x60)

sijhawm.s pw (0.5)

# TCN75A chaw nyob, 0x48 (72)

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

# temp MSB, temp LSB

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

# Hloov cov ntaub ntawv mus rau 12-ntsis

temp = ((cov ntaub ntawv [0] * 256) + (data [1] & 0xF0)) / 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: %.2f C" %cTemp

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

Kauj Ruam 4: Cov ntawv thov:

TCN75A yog lub ntsuas cua kub uas tuaj yeem ua haujlwm hauv lub khoos phis tawj ntiag tug thiab servers. Nws tseem tuaj yeem siv rau hauv kev lom zem, chaw ua haujlwm khoom siv, ua haujlwm nyuaj tsav thiab lwm yam khoom siv hauv PC.

Pom zoo: