Cov txheej txheem:

Raspberry Pi MCP9805 Kub Sensor Java Qhia: 4 Kauj Ruam
Raspberry Pi MCP9805 Kub Sensor Java Qhia: 4 Kauj Ruam

Video: Raspberry Pi MCP9805 Kub Sensor Java Qhia: 4 Kauj Ruam

Video: Raspberry Pi MCP9805 Kub Sensor Java Qhia: 4 Kauj Ruam
Video: Raspberry Pi MCP9805 Temperature Sensor Java Tutorial 2024, Hlis ntuj nqeg
Anonim
Image
Image

MCP9805 yog lub cim xeeb cim digital ntsuas kub. Nws tau suav nrog cov neeg siv cov ntawv sau npe uas muab kev yooj yim rau kev ntsuas qhov ntsuas kub. Qhov ntsuas no tau tsim los koom nrog hauv mobile platform nco module 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. MCP9805

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 kawg ntawm I2C cable rau MCP9805 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

Code
Code

Java code rau MCP9805 tuaj yeem rub tawm los ntawm peb GitHub chaw cia khoom-Dcube Store.

Nov yog qhov txuas rau tib yam:

github.com/DcubeTechVentures/MCP9805

Cov ntaub ntawv ntawm MCP9805 tuaj yeem pom ntawm no:

ww1.microchip.com/downloads/en/DeviceDoc/21…

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.

NPE MC9805

// Cov cai no tau tsim los ua haujlwm nrog MCP9808_I2CS I2C Mini Module muaj nyob hauv Dcube Store.

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 kawm MCP9805

{

pej xeem zoo li qub tsis muaj dab tsi tseem ceeb (Txoj hlua args ) cuam tshuam zam

{

// Tsim I2C npav

I2CBus Bus = I2CFactory.getInstance (I2CBus. BUS_1);

// Tau txais I2C ntaus ntawv, MCP9805 I2C chaw nyob yog 0x18 (24)

I2CDevice ntaus ntawv = Bus.getDevice (0x18);

Xov.sleep (300);

// Xaiv cov npe sau npe

// Nruam hloov dua siab tshiab hom, Fais fab tuag

byte teeb tsa = tshiab byte [2];

config [0] = 0x00;

config [1] = 0x00;

ntaus ntawv.write (0x01, teeb tsa, 0, 2);

// Xaiv qhov kev daws teeb meem rgister

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

device.write (0x08, (byte) 0x03);

Xov.sleep (300);

// Nyeem 2 bytes ntawm cov ntaub ntawv los ntawm chaw nyob 0x05 (05)

// temp msb, kub lsb

byte cov ntaub ntawv = tshiab byte [2];

device.read (0x05, cov ntaub ntawv, 0, 2);

// Hloov cov ntaub ntawv mus rau 13-ntsis

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

yog (temp> 4095)

{

temp -= 8192;

}

ob cTemp = temp * 0.0625;

ob fTemp = cTemp * 1.8 + 32;

// Cov ntaub ntawv tso tawm rau lub vijtsam

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

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

}

}

Kauj ruam 4: Cov ntawv thov..:

MCP9805 tuaj yeem suav nrog hauv ntau yam kab ke uas suav nrog ob kab hauv kab cim cim (DIMM) ntsuas kev ntsuas kub, tshuab computer thiab servers. Feem ntau, nws tuaj yeem siv ua lub hom phiaj dav dav ntsuas kub.

Pom zoo: