Cov txheej txheem:

Kev Ntsuas thiab Kev Ntsuas Kub Siv HTS221 thiab Arduino Nano: 4 Cov Kauj Ruam
Kev Ntsuas thiab Kev Ntsuas Kub Siv HTS221 thiab Arduino Nano: 4 Cov Kauj Ruam

Video: Kev Ntsuas thiab Kev Ntsuas Kub Siv HTS221 thiab Arduino Nano: 4 Cov Kauj Ruam

Video: Kev Ntsuas thiab Kev Ntsuas Kub Siv HTS221 thiab Arduino Nano: 4 Cov Kauj Ruam
Video: Plab Plab Ntswg..(Pluav Pluav Ntswg) Maiv Twm New Song 2023-2024 2024, Hlis ntuj nqeg
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.

Hauv qhov kev qhia no kev cuam tshuam ntawm HTS221 sensor module nrog arduino nano tau piav qhia. Txhawm rau nyeem cov av noo thiab qhov ntsuas kub, peb tau siv arduino 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

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

1. HTS221

2. Arduino Nano

3. I2C Cable

4. I2C Shield rau Arduino Nano

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 sensor thiab arduino nano. 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:

HTS221 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: Txoj Cai rau Kev Ntsuas thiab Kev Ntsuas Kub:

Txoj Cai rau Kev Ntsuas thiab Kev Ntsuas Kub
Txoj Cai rau Kev Ntsuas thiab Kev Ntsuas Kub

Cia peb pib nrog Arduino code tam sim no.

Thaum siv lub ntsuas ntsuas nrog Arduino, peb suav nrog Wire.h lub tsev qiv ntawv. "Hlau" lub tsev qiv ntawv muaj cov haujlwm uas pab txhawb i2c kev sib txuas lus ntawm lub sensor thiab Arduino board.

Tag nrho cov cai Arduino tau muab hauv qab no kom yooj yim ntawm cov neeg siv:

#suav nrog

// HTS221 I2C chaw nyob yog 0x5F

#define Ntxiv 0x5F

void teeb tsa ()

{

// Pib I2C kev sib txuas lus li MASTER

Hlau.begin ();

// Initialise serial communication, teeb baud tus nqi = 9600

Serial.begin (9600);

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xaiv qhov nruab nrab teeb tsa sau npe

Hlau.write (0x10);

// Qhov ntsuas kub nruab nrab piv txwv = 256, Qhov ntsuas nruab nrab vaum = 512

Hlau.write (0x1B);

// Nres I2C Kev Kis

Wire.endTransmission ();

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xaiv tswj npe 1

Hlau.write (0x20);

// Hwj chim ON, Hloov kho tas li, Cov ntaub ntawv tso tawm tus nqi = 1 Hz

Hlau.write (0x85);

// Nres I2C Kev Kis

Wire.endTransmission ();

ncua (300);

}

void lub voj ()

{

unsigned int cov ntaub ntawv [2];

unsigned int val [4];

unsigned int H0, H1, H2, H3, T0, T1, T2, T3, nyoos;

// Vaum qhov kev txiav txim siab qhov tseem ceeb

rau (int kuv = 0; kuv <2; kuv ++)

{

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xa cov ntaub ntawv sau npe

Hlau.write ((48 + i));

// Nres I2C Kev Kis

Wire.endTransmission ();

// Thov 1 byte ntawm cov ntaub ntawv

Wire.requestFrom (Addr, 1);

// Nyeem 1 byte ntawm cov ntaub ntawv

yog (Wire.available () == 1)

{

cov ntaub ntawv = Wire.read ();

}

}

// Hloov cov ntaub ntawv Vaum

H0 = cov ntaub ntawv [0] / 2;

H1 = cov ntaub ntawv [1] / 2;

rau (int kuv = 0; kuv <2; kuv ++)

{

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xa cov ntaub ntawv sau npe

Hlau.write ((54 + i));

// Nres I2C Kev Kis

Wire.endTransmission ();

// Thov 1 byte ntawm cov ntaub ntawv

Wire.requestFrom (Addr, 1);

// Nyeem 1 byte ntawm cov ntaub ntawv

yog (Wire.available () == 1)

{

cov ntaub ntawv = Wire.read ();

}

}

// Hloov cov ntaub ntawv Vaum

H2 = (cov ntaub ntawv [1] * 256.0) + cov ntaub ntawv [0];

rau (int kuv = 0; kuv <2; kuv ++)

{

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xa cov ntaub ntawv sau npe

Hlau.write ((58 + i));

// Nres I2C Kev Kis

Wire.endTransmission ();

// Thov 1 byte ntawm cov ntaub ntawv

Wire.requestFrom (Addr, 1);

// Nyeem 1 byte ntawm cov ntaub ntawv

yog (Wire.available () == 1)

{

cov ntaub ntawv = Wire.read ();

}

}

// Hloov cov ntaub ntawv Vaum

H3 = (cov ntaub ntawv [1] * 256.0) + cov ntaub ntawv [0];

// Qhov ntsuas qhov ntsuas kub

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xa cov ntaub ntawv sau npe

Hlau.write (0x32);

// Nres I2C Kev Kis

Wire.endTransmission ();

// Thov 1 byte ntawm cov ntaub ntawv

Wire.requestFrom (Addr, 1);

// Nyeem 1 byte ntawm cov ntaub ntawv

yog (Wire.available () == 1)

{

T0 = Hlau.read ();

}

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xa cov ntaub ntawv sau npe

Hlau.write (0x33);

// Nres I2C Kev Kis

Wire.endTransmission ();

// Thov 1 byte ntawm cov ntaub ntawv

Wire.requestFrom (Addr, 1);

// Nyeem 1 byte ntawm cov ntaub ntawv

yog (Wire.available () == 1)

{

T1 = Hlau.read ();

}

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xa cov ntaub ntawv sau npe

Hlau.write (0x35);

// Nres I2C Kev Kis

Wire.endTransmission ();

// Thov 1 byte ntawm cov ntaub ntawv

Wire.requestFrom (Addr, 1);

// Nyeem 1 byte ntawm cov ntaub ntawv

yog (Wire.available () == 1)

{

raw = Hlau.read ();

}

raw = raw & 0x0F;

// Hloov qhov ntsuas qhov ntsuas qhov ntsuas kub mus rau 10-ntsis

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

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

rau (int kuv = 0; kuv <2; kuv ++)

{

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xa cov ntaub ntawv sau npe

Hlau.write ((60 + i));

// Nres I2C Kev Kis

Wire.endTransmission ();

// Thov 1 byte ntawm cov ntaub ntawv

Wire.requestFrom (Addr, 1);

// Nyeem 1 byte ntawm cov ntaub ntawv

yog (Wire.available () == 1)

{

cov ntaub ntawv = Wire.read ();

}

}

// Hloov cov ntaub ntawv

T2 = (data [1] * 256.0) + data [0];

rau (int kuv = 0; kuv <2; kuv ++)

{

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xa cov ntaub ntawv sau npe

Hlau.write ((62 + i));

// Nres I2C Kev Kis

Wire.endTransmission ();

// Thov 1 byte ntawm cov ntaub ntawv

Wire.requestFrom (Addr, 1);

// Nyeem 1 byte ntawm cov ntaub ntawv

yog (Wire.available () == 1)

{

cov ntaub ntawv = Wire.read ();

}

}

// Hloov cov ntaub ntawv

T3 = (data [1] * 256.0) + data [0];

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xa cov ntaub ntawv sau npe

Wire.write (0x28 | 0x80);

// Nres I2C Kev Kis

Wire.endTransmission ();

// Thov 4 bytes ntawm cov ntaub ntawv

Wire.requestFrom (Addr, 4);

// Nyeem 4 bytes ntawm cov ntaub ntawv

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

yog (Wire.available () == 4)

{

val [0] = Hlau.read ();

val [1] = Hlau.read ();

val [2] = Hlau.read ();

val [3] = Hlau.read ();

}

// Hloov cov ntaub ntawv

ntab ntub = (val [1] * 256.0) + val [0];

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

int temp = (nqi [3] * 256) + val [2];

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

ntab fTemp = (cTemp * 1.8) + 32;

// Cov ntaub ntawv tso tawm rau tus saib xyuas

Serial.print ("Txheeb ze cov av noo:");

Serial.print (av noo);

Serial.println (" % RH");

Serial.print ("Kub hauv Celsius:");

Serial.print (cTemp); Serial.println ("C");

Serial.print ("Kub hauv Fahrenheit:");

Serial.print (fTemp);

Serial.println ("F");

ncua (500);

}

Hauv cov tsev qiv ntawv xaim Wire.write () thiab Wire.read () yog siv los sau cov lus txib thiab nyeem cov ntawv tso tawm.

Serial.print () thiab Serial.println () yog siv los tso saib cov zis ntawm lub sensor ntawm cov saib xyuas ntawm Arduino IDE.

Qhov tso tawm ntawm lub ntsuas hluav taws xob tau qhia hauv daim duab saum toj no.

Kauj Ruam 4: Cov ntawv thov:

Cov ntawv thov
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: