Cov txheej txheem:

Kev Ntsuas thiab Kev Ntsuas Kub Siv HTS221 thiab Particle Photon: 4 Cov Kauj Ruam
Kev Ntsuas thiab Kev Ntsuas Kub Siv HTS221 thiab Particle Photon: 4 Cov Kauj Ruam

Video: Kev Ntsuas thiab Kev Ntsuas Kub Siv HTS221 thiab Particle Photon: 4 Cov Kauj Ruam

Video: Kev Ntsuas thiab Kev Ntsuas Kub Siv HTS221 thiab Particle Photon: 4 Cov Kauj Ruam
Video: Npawg Xeeb thiab Maiv Xis part2 Dab neeg Dab 4/28/2020 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.

Hauv qhov kev qhia no kev cuam tshuam ntawm HTS221 sensor module nrog particle photon tau piav qhia. Txhawm rau nyeem cov av noo thiab qhov ntsuas kub, peb tau siv cov khoom me me nrog I2c adapter. Qhov 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. Particle Photon

3. I2C Cable

4. I2C Shield rau particle photon

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 txuas uas xav tau ntawm lub sensor thiab cov duab photon. 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 cov lej me me tam sim no.

Thaum siv lub ntsuas qhov ntsuas nrog qhov me me, peb suav nrog application.h thiab lub tsev qiv ntawv spark_wiring_i2c.h. "application.h" thiab lub tsev qiv ntawv spark_wiring_i2c.h muaj cov haujlwm uas pab txhawb kev sib txuas lus i2c ntawm lub sensor thiab cov khoom me me.

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

#suav nrog

#suav nrog

// HTS221 I2C chaw nyob yog 0x5F

#define Ntxiv 0x5F

ob chav av noo = 0.0;

ob cTemp = 0.0;

ob fTemp = 0.0;

int cov = 0;

void teeb tsa ()

{

// Teem sib txawv

Particle.variable ("i2cdevice", "HTS221");

Particle.variable ("Vaum", av noo);

Particle.variable ("cTemp", cTemp);

// 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

vaum = (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);

temp = (nqi [3] * 256) + val [2]; cTemp = (((T1 - T0) / 8.0) * (temp - T2)) / (T3 - T2) + (T0 / 8.0);

fTemp = (cTemp * 1.8) + 32;

// Tso tawm cov ntaub ntawv rau dashboard

Particle.publish ("Txheeb ze cov av noo:", Txoj hlua (av noo));

ncua (1000);

Particle.publish ("Kub hauv Celsius:", String (cTemp));

ncua (1000);

Particle.publish ("Kub hauv Fahrenheit:", String (fTemp));

ncua (1000);

}

Particle.variable () muaj nuj nqi tsim cov kev hloov pauv kom khaws cov zis tawm ntawm lub sensor thiab Particle.publish () muaj nuj nqi qhia cov zis ntawm lub dashboard ntawm lub xaib.

Cov zis sensor tau pom hauv daim duab saum toj no rau koj siv.

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: