Cov txheej txheem:

Ntsuas Kev Ntsuas Siv HYT939 thiab Raspberry Pi: 4 Kauj Ruam
Ntsuas Kev Ntsuas Siv HYT939 thiab Raspberry Pi: 4 Kauj Ruam

Video: Ntsuas Kev Ntsuas Siv HYT939 thiab Raspberry Pi: 4 Kauj Ruam

Video: Ntsuas Kev Ntsuas Siv HYT939 thiab Raspberry Pi: 4 Kauj Ruam
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Kaum ib hlis
Anonim
Image
Image

HYT939 yog lub ntsuas hluav taws xob digital uas ua haujlwm ntawm I2C kev sib txuas lus raws tu qauv. Cov av noo yog qhov ntsuas tseem ceeb thaum nws los txog rau kev kho mob thiab chaw kuaj mob, Yog li txhawm rau ua kom tiav cov hom phiaj no peb tau sim cuam tshuam HYT939 nrog raspberry pi. Hauv qhov kev qhia no kev cuam tshuam ntawm HYT939 sensor module nrog raspberry pi tau pom thiab nws cov phiaj xwm siv Java lus kuj tseem tau piav qhia.

Txhawm rau nyeem qhov ntsuas qhov av noo, peb tau siv raspberry pi nrog I2c adapter Qhov no I2C adapter ua rau kev txuas mus rau lub ntsuas qhov ntsuas tau yooj yim thiab ntseeg tau ntau dua.

Kauj Ruam 1: Yuav Tsum Kho Vajtse:

Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse
Yuav tsum tau kho vajtse

Kho vajtse uas yuav tsum tau ua kom tiav txoj haujlwm yog raws li hauv qab no:

1. HYT939

2. Raspberry Pi

3. I2C Cable

4. I2C Shield Rau Raspberry Pi

5. Ethernet Cable

-

Kauj ruam 2: Khoos phis tawj sib txuas:

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:

HYT939 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 3: Java Code rau Kev Ntsuas Ntsuas:

Java Code rau Kev Ntsuas Ntsuas
Java Code rau Kev Ntsuas Ntsuas
Java Code rau Kev Ntsuas Ntsuas
Java Code rau Kev Ntsuas Ntsuas

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 HYT939 tuaj yeem rub tawm los ntawm peb lub 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 HYT939

{

pej xeem zoo li qub tsis muaj dab tsi tseem ceeb (Txoj hlua args ) cuam tshuam zam

{

// Tsim I2CBus

I2CBus tsheb npav = I2CFactory.getInstance (I2CBus. BUS_1);

// Tau I2C ntaus ntawv, HYT939 I2C chaw nyob yog 0x28 (40)

I2CDevice ntaus ntawv = bus.getDevice (0x28);

// Xa ib txwm hais kom ua hom

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

Xov.sleep (500);

// Nyeem 4 bytes ntawm cov ntaub ntawv

// humidity msb, humidity lsb, temp msb, temp lsb

byte cov ntaub ntawv = tshiab byte [4];

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

// Hloov cov ntaub ntawv mus rau 14-ntsis

ob npaug av noo = (((data [0] & 0x3F) * 256) + (data [1] & 0xFF)) * (100.0 / 16383.0);

ob cTemp = ((((cov ntaub ntawv [2] & 0xFF) * 256) + (data [3] & 0xFC)) / 4) * (165.0 / 16383.0) - 40;

ob fTemp = (cTemp * 1.8) + 32;

// Cov ntaub ntawv tso tawm rau lub vijtsam

System.out.printf ("Tus txheeb ze Vaum yog: %.2f %% RH %n", av noo);

System.out.printf ("Kub hauv Celsius yog: %.2f C %n", cTemp);

System.out.printf ("Kub hauv Fahrenheit yog: %.2f F %n", fTemp);

}

}

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;

sau () thiab nyeem () lub luag haujlwm tau siv los sau qee cov lus txib tshwj xeeb rau lub ntsuas cua kom nws ua haujlwm hauv ib qho tshwj xeeb thiab nyeem cov ntawv tso tawm feem. Ua raws ib feem ntawm txoj cai qhia txog kev siv cov haujlwm no.

// Xa ib txwm hais kom ua ntaus ntawv.write ((byte) 0x80); Xov.sleep (500); // Nyeem 4 bytes ntawm cov ntaub ntawv // humidity msb, humidity lsb, temp msb, temp lsb byte cov ntaub ntawv = tshiab byte [4]; device.read (cov ntaub ntawv, 0, 4);

Qhov tso tawm ntawm lub sensor kuj tseem muaj nyob hauv daim duab saum toj no.

Kauj Ruam 4: Cov ntawv thov:

Cov ntawv thov
Cov ntawv thov

HYT939 ua qhov ntsuas cov av noo zoo tau ua haujlwm hauv Kev Kho Mob, Autoclaves. Ntsuas dej ntsuas taw tes thiab Tshuab Kom Qhuav kuj pom qhov siv ntawm qhov ntsuas qhov ntsuas no. Hauv ntau qhov Laboratories qhov twg cov av noo tsim nyog yog qhov ntsuas tseem ceeb rau kev sim, qhov ntsuas no tuaj yeem siv rau qhov ntsuas qhov av noo.

Pom zoo: