Cov txheej txheem:

Raspberry Pi HTS221 Tus txheeb ze Vaum thiab Kub Sensor Java Qhia: 4 Kauj Ruam
Raspberry Pi HTS221 Tus txheeb ze Vaum thiab Kub Sensor Java Qhia: 4 Kauj Ruam

Video: Raspberry Pi HTS221 Tus txheeb ze Vaum thiab Kub Sensor Java Qhia: 4 Kauj Ruam

Video: Raspberry Pi HTS221 Tus txheeb ze Vaum thiab Kub Sensor Java Qhia: 4 Kauj Ruam
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Kaum ib hlis
Anonim
Image
Image

HTS221 yog lub ntsuas hluav taws xob me me uas muaj peev xwm ntsuas tau rau qhov txheeb ze thiab qhov kub thiab txias. Nws suav nrog lub hauv paus ntsiab lus thiab qhov sib xyaw ua ke daim ntawv thov tshwj xeeb kev sib xyaw ua ke (ASIC) los muab cov ntaub ntawv ntsuas los ntawm kev cuam tshuam digital. Kev koom ua ke nrog ntau cov yam ntxwv no yog ib qho ntawm cov ntsuas tsim nyog tshaj plaws rau qhov ntsuas qhov ntsuas cua thiab ntsuas kub. 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. HTS221

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 HTS221 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 HTS221 tuaj yeem rub tawm los ntawm peb qhov chaw cia khoom github-Dcube Store

Nov yog qhov txuas rau tib yam:

github.com/DcubeTechVentures/HTS221/blob/master/Java/HTS221.java

Peb tau siv pi4j tsev qiv ntawv rau java code, cov kauj ruam rau nruab pi4j ntawm raspberry pi tau piav qhia ntawm no:

pi4j.com/install.html

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 ua haujlwm.

HWV 221

// Tus lej no yog tsim los ua haujlwm nrog HTS221_I2CS I2C Mini Module.

ntshuam com.pi4j.io.i2c. I2CBus;

ntshuam com.pi4j.io.i2c. I2CDevice;

ntshuam com.pi4j.io.i2c. I2CFactory;

ntshuam java.io. IOException;

pej xeem hauv chav HTS221 {pej xeem zoo li qub void lub ntsiab (Txoj hlua args ) cuam tshuam Kev zam

{

// Tsim I2CBus

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

// Tau txais I2C ntaus ntawv, HTS221 I2C chaw nyob yog 0x5F (95)

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

// Xaiv qhov nruab nrab teeb tsa sau npe

// Qhov ntsuas kub nruab nrab piv txwv = 16, ntsuas qhov nruab nrab qhov nruab nrab = 32

device.write (0x10, (byte) 0x1B);

// Xaiv tswj npe 1

// Fais fab, thaiv cov ntaub ntawv hloov tshiab, cov ntaub ntawv tus nqi o/p = 1 Hz

ntaus ntawv.write (0x20, (byte) 0x85);

Xov.sleep (500);

// Nyeem Calibration qhov tseem ceeb los ntawm lub cim xeeb tsis hloov pauv ntawm lub cuab yeej

// Humidity Calibration qhov tseem ceeb

byte val = tshiab byte [2];

// Nyeem 1 byte ntawm cov ntaub ntawv los ntawm chaw nyob 0x30 (48)

val [0] = (byte) ntaus ntawv nyeem (0x30);

// Nyeem 1 byte ntawm cov ntaub ntawv los ntawm chaw nyob 0x31 (49)

val [1] = (byte) ntaus ntawv nyeem (0x31);

int H0 = (val [0] & 0xFF) / 2;

int H1 = (val [1] & 0xFF) / 2;

// Nyeem 1 byte ntawm cov ntaub ntawv los ntawm chaw nyob 0x36 (54)

val [0] = (byte) ntaus ntawv nyeem (0x36);

// Nyeem 1 byte ntawm cov ntaub ntawv los ntawm chaw nyob 0x37 (55)

val [1] = (byte) ntaus ntawv nyeem (0x37);

int H2 = ((val [1] & 0xFF) * 256) + (val [0] & 0xFF);

// Nyeem 1 byte ntawm cov ntaub ntawv los ntawm chaw nyob 0x3A (58)

val [0] = (byte) ntaus ntawv nyeem (0x3A);

// Nyeem 1 byte ntawm cov ntaub ntawv los ntawm chaw nyob 0x3B (59)

val [1] = (byte) ntaus ntawv nyeem (0x3B);

int H3 = ((val [1] & 0xFF) * 256) + (val [0] & 0xFF);

// Kub Calibration qhov tseem ceeb

// Nyeem 1 byte ntawm cov ntaub ntawv los ntawm chaw nyob 0x32 (50)

int T0 = ((byte) device.read (0x32) & 0xFF);

// Nyeem 1 byte ntawm cov ntaub ntawv los ntawm chaw nyob 0x33 (51)

int T1 = ((byte) device.read (0x33) & 0xFF);

// Nyeem 1 byte ntawm cov ntaub ntawv los ntawm chaw nyob 0x35 (53)

int raw = ((byte) device.read (0x35) & 0x0F);

// Hloov qhov ntsuas kub ntsuas qhov ntsuas kom 10-ntsis

T0 = ((raw & 0x03) * 256) + T0;

T1 = ((raw & 0x0C) * 64) + T1;

// Nyeem 1 byte ntawm cov ntaub ntawv los ntawm chaw nyob 0x3C (60)

val [0] = (byte) ntaus ntawv nyeem (0x3C);

// Nyeem 1 byte ntawm cov ntaub ntawv los ntawm chaw nyob 0x3D (61)

val [1] = (byte) ntaus ntawv nyeem (0x3D);

int T2 = ((val [1] & 0xFF) * 256) + (val [0] & 0xFF);

// Nyeem 1 byte ntawm cov ntaub ntawv los ntawm chaw nyob 0x3E (62)

val [0] = (byte) ntaus ntawv.read (0x3E);

// Nyeem 1 byte ntawm cov ntaub ntawv los ntawm chaw nyob 0x3F (63)

val [1] = (byte) ntaus ntawv nyeem (0x3F);

int T3 = ((val [1] & 0xFF) * 256) + (val [0] & 0xFF);

// Nyeem 4 bytes ntawm cov ntaub ntawv

// hmoob, hmoob, hmoob, hmoob, hmoob, hmoob, hmoob, hmoob

byte cov ntaub ntawv = tshiab byte [4]; device.read (0x28 | 0x80, cov ntaub ntawv, 0, 4);

// Hloov cov ntaub ntawv

int hum = ((cov ntaub ntawv [1] & 0xFF) * 256) + (cov ntaub ntawv [0] & 0xFF);

int temp = ((cov ntaub ntawv [3] & 0xFF) * 256) + (data [2] & 0xFF);

yog (temp> 32767)

{

temp -= 65536;

}

ob npaug av noo = ((1.0 * H1) - (1.0 * H0)) * (1.0 * hum - 1.0 * H2) / (1.0 * H3 - 1.0 * H2) + (1.0 * H0);

ob cTemp = ((T1 - T0) / 8.0) * (temp - T2) / (T3 - T2) + (T0 / 8.0);

ob fTemp = (cTemp * 1.8) + 32;

// Cov ntaub ntawv tso tawm rau lub vijtsam

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

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

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

}

}

Kauj Ruam 4: Cov ntawv thov:

HTS221 tuaj yeem ua haujlwm hauv ntau yam khoom siv xws li huab cua ua kom txias thiab tub yees thiab lwm yam.

Pom zoo: