Cov txheej txheem:

Kev Ntsuas Kub thiab Vaum Siv SHT25 thiab Raspberry Pi: 5 Kauj Ruam
Kev Ntsuas Kub thiab Vaum Siv SHT25 thiab Raspberry Pi: 5 Kauj Ruam

Video: Kev Ntsuas Kub thiab Vaum Siv SHT25 thiab Raspberry Pi: 5 Kauj Ruam

Video: Kev Ntsuas Kub thiab Vaum Siv SHT25 thiab Raspberry Pi: 5 Kauj Ruam
Video: Lub Zog Nruab Nrog (Hmong Dubbed) 2024, Kaum ib hlis
Anonim
Image
Image

Tsis ntev los no peb tau ua haujlwm ntawm ntau txoj haujlwm uas xav tau kev ntsuas kub thiab av noo thiab tom qab ntawd peb pom tau tias ob qhov kev ntsuas no tau ua lub luag haujlwm tseem ceeb hauv kev kwv yees ntawm kev ua haujlwm ntawm lub system. Ob qho tib si ntawm qib kev lag luam thiab cov txheej txheem tus kheej qhov ntsuas kub zoo tshaj yog qhov yuav tsum tau ua kom tau txais txiaj ntsig zoo ntawm lub kaw lus.

Qhov no yog vim li cas, hauv qhov kev qhia no peb yuav piav qhia kev ua haujlwm ntawm SHT25 cov av noo thiab ntsuas kub siv raspberry pi. Hauv qhov kev qhia tshwj xeeb no nws ua haujlwm tau raug qhia pom siv java code.

Kho vajtse uas koj yuav xav tau rau lub hom phiaj no yog:

1. TSH25

2. Raspberry Pi

3. I2C Cable

4. I2C ntaub thaiv npog rau raspberry pi

Kauj Ruam 1: SHT25 Txheej Txheem:

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

Ua ntej tshaj plaws cia pib nrog kev nkag siab yooj yim ntawm lub sensor thiab cov txheej txheem uas nws ua haujlwm.

SHT25 I2C Vaum thiab Kub Sensor ± 1.8%RH ± 0.2 ° C I2C Mini Module. Nws yog qhov tseeb cov av noo thiab qhov ntsuas kub tau dhau los ua tus txheej txheem 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. Kev koom ua ke nrog tshwj xeeb analog thiab digital Circuit no lub ntsuas pa yog ib qho cuab yeej siv tau zoo tshaj plaws los ntsuas qhov kub thiab txias.

Cov txheej txheem kev sib txuas lus uas lub sensor ua haujlwm yog I2C. I2C sawv cev rau kev sib koom ua ke. Nws yog cov txheej txheem kev sib txuas lus uas kev sib txuas lus tau tshwm sim los ntawm SDA (cov ntaub ntawv xov xwm) thiab SCL (cov xov tooj). Nws tso cai txuas ntau yam khoom siv tib lub sijhawm. Nws yog ib qho ntawm cov txheej txheem kev sib txuas lus yooj yim tshaj plaws thiab muaj txiaj ntsig tshaj plaws.

Kauj Ruam 2: Yam Koj Xav Tau …

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

Cov ntaub ntawv uas peb xav tau kom ua tiav peb lub hom phiaj suav nrog cov khoom siv hauv qab no:

1. SHT25 av noo thiab ntsuas kub

2. Raspberry pib

3. I2C Cable

4. I2C Shield rau Raspberry Pi

5. Ethernet Cable

Kauj Ruam 3: Khoos Phis Tawj Hookup:

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:

  • SHT25 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 4: Kub thiab Vaum Xyuas Java Code:

Kub thiab Vaum Xyuas Java Code
Kub thiab Vaum Xyuas Java Code
Kub thiab Vaum Xyuas Java Code
Kub thiab Vaum Xyuas Java Code

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 txoj haujlwm hauv Java. Tus lej Java rau SHT25 tuaj yeem rub tawm los ntawm peb cov zej zog github uas yog Dcube Store.

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 pi4j lub tsev qiv ntawv hauv java, vim tias lub tsev qiv ntawv no txhawb nqa cov haujlwm siv hauv txoj cai. Yog li, txhawm rau rub lub tsev qiv ntawv koj tuaj yeem mus ntsib qhov txuas hauv qab no:

pi4j.com/install.html

Koj tuaj yeem luam qhov ua haujlwm java code rau lub ntsuas no los ntawm no kuj:

ntshuam com.pi4j.io.i2c. I2CBus;

ntshuam com.pi4j.io.i2c. I2CDevice; ntshuam com.pi4j.io.i2c. I2CFactory; ntshuam java.io. IOException; pej xeem chav SHT25 {pej xeem zoo li qub tsis muaj qhov tseem ceeb (Txoj hlua sib cav ) cuam tshuam qhov zam {// Tsim I2C npav I2CBus Bus = I2CFactory.getInstance (I2CBus. BUS_1); // Tau I2C ntaus ntawv, SHT25 I2C chaw nyob yog 0x40 (64) I2CDevice ntaus ntawv = Bus.getDevice (0x40); // Xa cov lus ntsuas ntsuas ntsuas, TSIS MUAJ tus tswv cuab ntaus ntawv.write ((byte) 0xF3); Xov.sleep (500); // Nyeem 2 bytes ntawm cov ntaub ntawv // temp msb, temp lsb byte cov ntaub ntawv = tshiab byte [2]; device.read (cov ntaub ntawv, 0, 2); // Hloov cov ntaub ntawv ob cTemp = (((((cov ntaub ntawv [0] & 0xFF) * 256) + (data [1] & 0xFF)) * 175.72) / 65536.0) - 46.85; ob fTemp = (cTemp * 1.8) + 32; // Xa cov lus ntsuas ntsuas av noo, TSIS MUAJ HOLD master device.write ((byte) 0xF5); Xov.sleep (500); // Nyeem 2 bytes ntawm cov ntaub ntawv // av noo msb, av noo lsb device.read (cov ntaub ntawv, 0, 2); // Hloov cov ntaub ntawv ob npaug av noo = ((((data [0] & 0xFF) * 256) + (data [1] & 0xFF)) * 125.0) / 65536.0) - 6; // Cov ntaub ntawv tso tawm rau lub vijtsam System.out.printf ("Txheeb ze Vaum: %.2f %% RH %n", av noo); System.out.printf ("Kub hauv Celsius: %.2f C %n", cTemp); System.out.printf ("Kub hauv Farhenheit: %.2f F %n", fTemp); }}

Qhov tsim tawm ntawm txoj cai kuj tseem muaj nyob hauv daim duab saum toj no.

Lub tsev qiv ntawv uas txhawb nqa i2c kev sib txuas lus ntawm lub sensor thiab pawg thawj coj yog pi4j, nws ntau pob khoom I2CBus, I2CDevice thiab I2CFactory pab tsim kom muaj kev sib txuas.

ntshuam com.pi4j.io.i2c. I2CBus;

ntshuam com.pi4j.io.i2c. I2CDevice; ntshuam com.pi4j.io.i2c. I2CFactory; ntshuam java.io. IOException;

Ib feem ntawm txoj cai no ua rau lub ntsuas hluav taws xob ntsuas kub thiab ntsuas cov av noo los ntawm kev sau cov lus txib tshwj xeeb uas siv kev sau () ua haujlwm thiab tom qab ntawd cov ntaub ntawv raug siv siv nyeem () ua haujlwm.

device.write ((byte) 0xF3);

Xov.sleep (500);

// Nyeem 2 bytes ntawm cov ntaub ntawv

// temp msb, kub lsb

byte cov ntaub ntawv = tshiab byte [2];

device.read (cov ntaub ntawv, 0, 2);

// Xa cov lus ntsuas ntsuas av noo, Tsis muaj tus tswv tuav

ntaus ntawv.write ((byte) 0xF5);

Xov.sleep (500);

// Nyeem 2 bytes ntawm cov ntaub ntawv

// av noo msb, av noo lsb

device.read (cov ntaub ntawv, 0, 2);

Kauj Ruam 5: 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. Peb kuj tseem tau ua haujlwm ntsuas qhov ntsuas no rau hauv daim ntawv thov huab cua nrog rau kev tshuaj xyuas tsev cog khoom.

Pom zoo: