Cov txheej txheem:

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

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

Video: Kev Ntsuas Kub Siv MCP9808 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

MCP9808 yog qhov ntsuas qhov ntsuas qhov ntsuas qhov tseeb ntau ± 0.5 ° C I2C mini module. Lawv tau suav nrog cov npe siv tau-programmable uas pab txhawb kev thov ntsuas kub. MCP9808 qhov ntsuas qhov ntsuas qhov ntsuas kub tau dhau los ua tus qauv kev lag luam raws li daim ntawv foos thiab kev txawj ntse, muab kev ntsuas ntsuas, ntsuas qhov ntsuas qhov ntsuas hauv digital, hom I2C.

Hauv qhov kev qhia no kev cuam tshuam ntawm MCP9808 sensor module nrog arduino nano tau pom. Txhawm rau nyeem qhov ntsuas kub, 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

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

1. MCP9808

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:

MCP9808 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 Kub:

Code rau Kev Ntsuas Kub
Code rau 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

// MCP9808 I2C chaw nyob yog 0x18 (24)

#define Ntxiv 0x18

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 cov npe sau npe

Hlau.write (0x01);

// Kev hloov pauv mus tas li, Lub hwj chim ua ntej

Hlau.write (0x00);

Hlau.write (0x00);

// Nres I2C Kev Kis

Wire.endTransmission ();

// Pib I2C Kev Kis

Wire.beginTransmission (Addr);

// Xaiv qhov kev daws teeb meem sau npe

Hlau.write (0x08);

// Kev daws teeb meem = +0.0625 / C.

Hlau.write (0x03);

// Nres I2C Kev Kis

Wire.endTransmission ();

}

void lub voj ()

{

unsigned int cov ntaub ntawv [2];

// Pib I2C kev sib txuas lus

Wire.beginTransmission (Addr);

// Xaiv cov ntaub ntawv sau npe

Hlau.write (0x05);

// Nres I2C kev xa mus

Wire.endTransmission ();

// Thov 2 bytes ntawm cov ntaub ntawv

Wire.requestFrom (Addr, 2);

// Nyeem 2 bytes ntawm cov ntaub ntawv

// temp MSB, temp LSB

yog (Wire.available () == 2)

{

cov ntaub ntawv [0] = Wire.read ();

cov ntaub ntawv [1] = Wire.read ();

}

// Hloov cov ntaub ntawv mus rau 13-ntsis

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

yog (temp> 4095)

{

temp -= 8192;

}

ntab cTemp = temp * 0.0625;

ntab fTemp = cTemp * 1.8 + 32;

// Cov ntaub ntawv tso tawm rau lub vijtsam

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

Serial.println (cTemp);

Serial.println ("C");

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

Serial.println (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

MCP9808 Digital Kub Sensor muaj ntau daim ntawv thov kev lag luam uas suav nrog cov tub yees txias thiab tub yees nrog rau ntau yam txheej txheem khoom noj. Qhov ntsuas no tuaj yeem ua haujlwm rau ntau lub khoos phis tawj ntiag tug, servers nrog rau lwm yam khoom siv hauv PC.

Pom zoo: