Cov txheej txheem:

Arduino Nano - HTS221 Tus txheeb ze Vaum thiab Kub Sensor Tutorial: 4 Kauj Ruam
Arduino Nano - HTS221 Tus txheeb ze Vaum thiab Kub Sensor Tutorial: 4 Kauj Ruam

Video: Arduino Nano - HTS221 Tus txheeb ze Vaum thiab Kub Sensor Tutorial: 4 Kauj Ruam

Video: Arduino Nano - HTS221 Tus txheeb ze Vaum thiab Kub Sensor Tutorial: 4 Kauj Ruam
Video: Arduino day 2020 - Novas Ferramentas do Arduino (vídeo 6) 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. Nov yog qhov ua piv txwv nrog arduino nano.

Kauj Ruam 1: Yam Koj Xav Tau..

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

1. Arduino Nano

2. HTS221

3. I²C Cable

4. I²C Shield rau Arduino Nano

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 daim I2C daim thaiv rau Arduino Nano thiab maj mam thawb nws hla tus pin ntawm Nano.

Tom qab ntawd txuas ib qho kawg ntawm I2C cable rau HTS221 sensor thiab lwm qhov kawg rau I2C daim ntaub thaiv.

Kev sib txuas tau qhia hauv daim duab saum toj no.

Kauj ruam 3: Code:

Txoj Cai
Txoj Cai

Tus lej arduino rau HTS221 tuaj yeem rub tawm los ntawm peb qhov chaw cia khoom github- DCUBE Community.

Nov yog qhov txuas rau tib yam:

github.com/DcubeTechVentures/HTS221/blob/master/Arduino/HTS221.ino

Peb suav nrog tsev qiv ntawv Wire.h los pab txhawb I2c kev sib txuas lus ntawm lub sensor nrog Arduino board.

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

#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);

}

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: