Cov txheej txheem:

Raspberry Pi SHT25 Vaum & Kub Sensor Python Qhia: 4 Kauj Ruam
Raspberry Pi SHT25 Vaum & Kub Sensor Python Qhia: 4 Kauj Ruam

Video: Raspberry Pi SHT25 Vaum & Kub Sensor Python Qhia: 4 Kauj Ruam

Video: Raspberry Pi SHT25 Vaum & Kub Sensor Python Qhia: 4 Kauj Ruam
Video: Amazing arduino project 2024, Kaum ib hlis
Anonim
Raspberry Pi SHT25 Vaum & Kub Sensor Python Tutorial
Raspberry Pi SHT25 Vaum & Kub Sensor Python Tutorial

SHT25 I2C Vaum thiab Kub Sensor ± 1.8%RH ± 0.2 ° C I2C Mini Module. SHT25 qhov tseeb qhov ntsuas qhov ntsuas cua thiab qhov 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 Python code siv Raspberry Pi.

Kauj Ruam 1: Yam Koj Xav Tau

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

1. Raspberry Pi

2. SHT25

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 SHT25 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 hauv qab no.

Kauj ruam 3: Pyhton Code

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

Txoj cai tuaj yeem pom ntawm no:

github.com/DcubeTechVentures/SHT25/blob/master/Python/SHT25.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:

#Kev faib tawm 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.

# TSW 25

ntshuam smbus

lub sij hawm ntshuam

# Tau I2C npav

npav = smbus. SMBus (1)

# SHT25 chaw nyob, 0x40 (64)

# Xa cov lus ntsuas ntsuas kub

# 0xF3 (243) Tsis muaj tus tswv tuav

bus.write_byte (0x40, 0xF3)

sijhawm.s pw (0.5)

# SHT25 chaw nyob, 0x40 (64)

# Nyeem cov ntaub ntawv rov qab, 2 bytes

# Temp MSB, Temp LSB

data0 = npav.read_byte (0x40)

data1 = npav.read_byte (0x40)

# Hloov cov ntaub ntawv

temp = data0 * 256 + data1

cTemp = -46.85 + ((temp * 175.72) / 65536.0)

fTemp = cTemp * 1.8 + 32

# SHT25 chaw nyob, 0x40 (64)

# Xa cov lus txib ntsuas cov av noo

# 0xF5 (245) Tsis muaj tus tswv tuav

bus.write_byte (0x40, 0xF5)

sijhawm.s pw (0.5)

# SHT25 chaw nyob, 0x40 (64)

# Nyeem cov ntaub ntawv rov qab, 2 bytes

# Vaum MSB, Vaum LSB

data0 = npav.read_byte (0x40)

data1 = npav.read_byte (0x40)

# Hloov cov ntaub ntawv

av noo = data0 * 256 + data1

av noo = -6 + ((av noo * 125.0) / 65536.0)

# Cov ntaub ntawv tso tawm rau lub vijtsam

luam "Cov txheeb ze Vaum yog: %.2f %%" %av noo

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

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

Kauj Ruam 4: Cov ntawv thov

SHT25 qhov ntsuas kub thiab qhov txheeb ze cov txheeb ze muaj ntau yam kev siv xws li ntsuas kub, khoos phis tawj ib puag ncig tiv thaiv cua sov thiab lwm yam.

Pom zoo: