Cov txheej txheem:

Chaw Nyob Huab Cua Tus Kheej Siv Raspberry Pi Nrog BME280 hauv Java: 6 Kauj Ruam
Chaw Nyob Huab Cua Tus Kheej Siv Raspberry Pi Nrog BME280 hauv Java: 6 Kauj Ruam

Video: Chaw Nyob Huab Cua Tus Kheej Siv Raspberry Pi Nrog BME280 hauv Java: 6 Kauj Ruam

Video: Chaw Nyob Huab Cua Tus Kheej Siv Raspberry Pi Nrog BME280 hauv Java: 6 Kauj Ruam
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Hlis ntuj nqeg
Anonim
Image
Image
Bill ntawm Cov Khoom Siv Tseem Ceeb
Bill ntawm Cov Khoom Siv Tseem Ceeb

Huab cua phem ib txwm zoo li tsis zoo los ntawm lub qhov rais

Peb ib txwm tau txaus siab los saib xyuas peb huab cua hauv nroog thiab qhov peb pom tawm ntawm lub qhov rais. Peb kuj xav tau kev tswj kom zoo dua peb cov cua sov thiab A/C system. Tsim Lub Tsev Chaw Huab Cua Tus Kheej yog qhov kev kawm tau zoo. Thaum koj ua tiav txoj haujlwm no koj yuav nkag siab zoo txog kev sib txuas lus wireless ua haujlwm li cas, cov cuab yeej ua haujlwm li cas, thiab lub zog Raspberry Pi platform tuaj yeem ua tau zoo li cas. Nrog txoj haujlwm no ua lub hauv paus thiab cov kev paub dhau los, koj yuav tuaj yeem tsim cov phiaj xwm nyuaj dua yav tom ntej.

Kauj Ruam 1: Nqi ntawm Cov Khoom Tseem Ceeb

Bill ntawm Cov Khoom Siv Tseem Ceeb
Bill ntawm Cov Khoom Siv Tseem Ceeb
Bill ntawm Cov Khoom Siv Tseem Ceeb
Bill ntawm Cov Khoom Siv Tseem Ceeb
Bill ntawm Cov Khoom Tseem Ceeb
Bill ntawm Cov Khoom Tseem Ceeb

1. Raspberry Pi

Thawj kauj ruam yog kom tau txais koj txhais tes ntawm Raspberry Pi board. Raspberry Pi yog Linux siv lub tshuab computer ib leeg. Nws lub hom phiaj yog txhawm rau txhim kho cov txuj ci txuj ci thiab kev nkag siab kho vajtse. Nws tau saws sai sai los ntawm hobbyists thiab cov neeg txhawb nqa hluav taws xob rau cov phiaj xwm tshiab.

2. I²C Shield rau Raspberry Pi

INPI2 (I2C adapter) muab Raspberry Pi 2/3 ib qho I²C chaw nres nkoj rau siv nrog ntau yam ntawm I²C cov cuab yeej. Nws muaj nyob ntawm Dcube Store

3. Digital Humidity, Siab thiab Kub Sensor, BME280

BME280 yog cov av noo, siab thiab ntsuas kub uas muaj lub sijhawm teb sai thiab qhov raug siab tag nrho. Peb tau yuav qhov ntsuas no los ntawm Dcube Store

4. I²C Txuas Cable

Peb muaj I²C txuas cov xov hluav taws xob muaj nyob ntawm Dcube Store

5. Micro USB cable

Lub micro USB cable Lub hwj chim muab yog qhov kev xaiv zoo tshaj plaws rau lub zog Raspberry Pi.

6. Txhais Kev Siv Internet ntawm EthernetCable/WiFi Adapter

Ib qho ntawm thawj yam uas koj yuav xav ua yog kom tau txais koj li Raspberry Pi txuas nrog rau Internet. Peb tuaj yeem txuas nrog siv Ethernet cable. Lwm qhov muaj peev xwm yog tias koj tuaj yeem txuas rau lub wireless network siv USB Wireless Adapter.

7. HDMI Cable (Zaub & txuas txuas)

Ib qho HDMI/DVI saib thiab txhua lub TV yuav tsum ua haujlwm zoo li Pi. Tab sis nws yog nyob ntawm yeem. Kev nkag mus rau tej thaj chaw deb (zoo li-SSH) tseem tsis tuaj yeem txiav tawm. Koj tseem tuaj yeem nkag tau nrog PUTTY software.

Kauj Ruam 2: Kev Sib Txuas Kho Vajtse rau Teeb

Kho vajtse sib txuas rau teeb
Kho vajtse sib txuas rau teeb
Kho vajtse sib txuas rau teeb
Kho vajtse sib txuas rau teeb

Ua lub Circuit Court raws li qhov schematic qhia.

Thaum kawm, peb tau ua tiav nrog cov hauv paus ntawm cov khoom siv hluav taws xob hais txog kev paub kho vajtse thiab software. Peb xav kos cov txheej txheem hluav taws xob yooj yim rau txoj haujlwm no. Kev kos duab hluav taws xob zoo li lub phiaj xwm rau hluav taws xob. Kos ib daim qauv thiab ua tib zoo tsim. Peb tau siv qee qhov pib ntawm cov khoom siv hluav taws xob ntawm no. Logic tau txais koj los ntawm A txog B, Kev xav yuav coj koj mus txhua qhov chaw!

Kev sib txuas ntawm Raspberry Pi thiab I²C Shield

Ua ntej tshaj plaws coj Raspberry Pi thiab tso I²C Shield (nrog Sab Hauv Lub ntsej muag I²C Port) rau nws. Nias lub Shield maj mam hla GPIO pins ntawm Pi thiab peb tau ua tiav nrog cov kauj ruam no yooj yim li ncuav qab zib (saib daim duab).

Kev sib txuas ntawm Sensor thiab Raspberry Pi

Coj lub sensor thiab Txuas I²C cable nrog nws. Nco ntsoov tias I²C Cov Zis Ib Leeg txuas rau I²C Cov Tswv Yim. Tib yam yuav tsum tau ua raws rau Raspberry Pi nrog I²C daim ntaub thaiv npog nws GPIO pins. Peb muaj I²C Shield thiab txuas cov xov hluav taws xob ntawm peb sab ua qhov kev pab loj heev thiab muaj txiaj ntsig zoo heev li peb tsuas yog sab laug nrog ntsaws thiab ua si xaiv. Tsis muaj tus pin thiab qhov teeb meem txuas ntxiv thiab yog li, tsis meej pem ploj mus. Tsuas yog xav txog koj tus kheej hauv lub vev xaib ntawm cov xov hlau thiab nkag mus rau qhov ntawd. Kev nplij siab los ntawm qhov ntawd. Qhov no ua rau tej yam tsis yooj yim.

Nco tseg: Cov xaim xim av yuav tsum ib txwm ua raws hauv av (GND) kev sib txuas ntawm cov khoom siv ntawm ib lub cuab yeej thiab cov tswv yim ntawm lwm lub cuab yeej

Kev Sib Txuas Internet yog Qhov Xav Tau

Koj muaj kev xaiv ntawm no tiag. Koj tuaj yeem txuas Raspberry Pi nrog LAN cable lossis wireless Nano USB Adapter rau WIFI Kev Sib Txuas. Txawm li cas los xij, qhov tshwm sim yog txuas rau internet uas ua tiav.

Kev ua kom muaj zog ntawm Circuit Court

Txuas lub Micro USB cable rau hauv lub hwj chim nkaus ntawm Raspberry Pi. Punch up thiab voila! Txhua yam zoo mus thiab peb yuav pib tam sim.

Kev Sib Txuas rau Zaub

Peb tuaj yeem muaj HDMI cable txuas nrog tus saib lossis TV. Peb tuaj yeem nkag mus rau Raspberry Pi yam tsis txuas nws mus rau tus saib xyuas siv -SSH (Nkag mus rau kab hais kom ua ntawm Pi los ntawm lwm lub khoos phis tawj). Koj kuj tseem tuaj yeem siv PUTTY software rau qhov ntawd. Qhov kev xaiv no yog rau cov neeg siv siab heev yog li peb yuav tsis nthuav dav nws ntawm no.

Kuv tau hnov tias yuav muaj kev poob qis, Kuv tau txiav txim siab tsis koom nrog

Kauj Ruam 3: Raspberry Pi Programming hauv Java

Raspberry Pi Programming hauv Java
Raspberry Pi Programming hauv Java

Java Code rau Raspberry Pi thiab BME280 Sensor. Nws muaj nyob hauv pebGithub chaw cia khoom.

Ua ntej mus rau txoj cai, nco ntsoov koj tau nyeem cov lus qhia muab hauv Readme cov ntaub ntawv thiab teeb tsa koj li Raspberry Pi raws li nws. Nws yuav siv sijhawm ib pliag los ua li ntawd. Chaw nres tsheb huab cua tus kheej yog txheej txheem ntsuas huab cua ua haujlwm los ntawm tus kheej, koom nrog, koom nrog, lossis tseem ua lag luam. Cov chaw siv huab cua tus kheej tuaj yeem ua haujlwm nkaus xwb rau kev txaus siab thiab kev kawm ntawm tus tswv, tab sis ntau tus neeg ua haujlwm chaw nres tsheb huab cua tus kheej kuj tseem qhia lawv cov ntaub ntawv nrog lwm tus, xws li los ntawm kev suav sau cov ntaub ntawv thiab faib nws, lossis los ntawm kev siv internet lossis xov tooj cua nyiam.

Txoj cai nyob hauv nws daim ntawv yooj yim tshaj plaws uas koj tuaj yeem xav txog thiab koj yuav tsum tsis muaj teeb meem nrog nws tab sis nug yog tias koj muaj. Txawm hais tias koj paub ntau txhiab yam, tseem nug ib tus neeg paub.

Koj tuaj yeem luam qhov java code ua haujlwm rau lub ntsuas no los ntawm no ib yam.

// Tshaj tawm nrog daim ntawv tso cai pub dawb.// Siv nws txhua txoj hauv kev koj xav tau, muaj txiaj ntsig lossis pub dawb, muab nws haum rau hauv daim ntawv tso cai ntawm nws cov haujlwm ua haujlwm. // BME280 // Txoj cai no yog tsim los ua haujlwm nrog BME280_I2CS I2C Mini Module muaj los ntawm ControlEverything.com. //

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 BME280

{pej xeem zoo li qub tsis muaj dab tsi tseem ceeb (Txoj hlua sib cav ) cuam tshuam kev zam {// Tsim I2C npav I2CBus npav = I2CFactory.getInstance (I2CBus. BUS_1); // Tau I2C ntaus ntawv, BME280 I2C chaw nyob yog 0x76 (108) I2CDevice ntaus ntawv = bus.getDevice (0x76); // Nyeem 24 bytes ntawm cov ntaub ntawv los ntawm chaw nyob 0x88 (136) byte b1 = tshiab byte [24]; device.read (0x88, b1, 0, 24); // Hloov cov ntaub ntawv // temp coefficients int dig_T1 = (b1 [0] & 0xFF) + ((b1 [1] & 0xFF) * 256); int dig_T2 = (b1 [2] & 0xFF) + ((b1 [3] & 0xFF) * 256); yog (dig_T2> 32767) {dig_T2 -= 65536; } int dig_T3 = (b1 [4] & 0xFF) + ((b1 [5] & 0xFF) * 256); yog (dig_T3> 32767) {dig_T3 -= 65536; } // siab coefficients int dig_P1 = (b1 [6] & 0xFF) + ((b1 [7] & 0xFF) * 256); int dig_P2 = (b1 [8] & 0xFF) + ((b1 [9] & 0xFF) * 256); yog (dig_P2> 32767) {dig_P2 -= 65536; } int dig_P3 = (b1 [10] & 0xFF) + ((b1 [11] & 0xFF) * 256); yog (dig_P3> 32767) {dig_P3 -= 65536; } int dig_P4 = (b1 [12] & 0xFF) + ((b1 [13] & 0xFF) * 256); yog (dig_P4> 32767) {dig_P4 -= 65536; } int dig_P5 = (b1 [14] & 0xFF) + ((b1 [15] & 0xFF) * 256); yog (dig_P5> 32767) {dig_P5 -= 65536; } int dig_P6 = (b1 [16] & 0xFF) + ((b1 [17] & 0xFF) * 256); yog (dig_P6> 32767) {dig_P6 -= 65536; } int dig_P7 = (b1 [18] & 0xFF) + ((b1 [19] & 0xFF) * 256); yog (dig_P7> 32767) {dig_P7 -= 65536; } int dig_P8 = (b1 [20] & 0xFF) + ((b1 [21] & 0xFF) * 256); yog (dig_P8> 32767) {dig_P8 -= 65536; } int dig_P9 = (b1 [22] & 0xFF) + ((b1 [23] & 0xFF) * 256); yog (dig_P9> 32767) {dig_P9 -= 65536; } // Nyeem 1 byte ntawm cov ntaub ntawv los ntawm chaw nyob 0xA1 (161) int dig_H1 = ((byte) device.read (0xA1) & 0xFF); // Nyeem 7 bytes ntawm cov ntaub ntawv los ntawm chaw nyob 0xE1 (225) device.read (0xE1, b1, 0, 7); // Hloov cov ntaub ntawv // vaum coefficients int dig_H2 = (b1 [0] & 0xFF) + (b1 [1] * 256); yog (dig_H2> 32767) {dig_H2 -= 65536; } int dig_H3 = b1 [2] & 0xFF; int dig_H4 = ((b1 [3] & 0xFF) * 16) + (b1 [4] & 0xF); yog (dig_H4> 32767) {dig_H4 -= 65536; } int dig_H5 = ((b1 [4] & 0xFF) / 16) + ((b1 [5] & 0xFF) * 16); yog (dig_H5> 32767) {dig_H5 -= 65536; } int dig_H6 = b1 [6] & 0xFF; yog (dig_H6> 127) {dig_H6 -= 256; } // Xaiv tswj kev tso npe vaum // Vaum dhau qhov piv txwv = 1 device.write (0xF2, (byte) 0x01); // Xaiv tswj kev ntsuas sau npe // Hom qub, ntsuas thiab ntsuas siab piv txwv piv txwv = 1 device.write (0xF4, (byte) 0x27); // Xaiv teeb tsa sau npe // Stand_by sijhawm = 1000 ms device.write (0xF5, (byte) 0xA0); // Nyeem 8 bytes ntawm cov ntaub ntawv los ntawm chaw nyob 0xF7 (247) // siab msb1, siab msb, siab lsb, temp msb1, temp msb, temp lsb, humidity lsb, humidity msb byte cov ntaub ntawv = tshiab byte [8]; device.read (0xF7, cov ntaub ntawv, 0, 8); // Hloov cov ntaub ntawv ntsuas thiab ntsuas kub mus rau 19-ntsis ntev adc_p = (((ntev) (cov ntaub ntawv [0] & 0xFF) * 65536) + ((ntev) (cov ntaub ntawv [1] & 0xFF) * 256) + (ntev) (cov ntaub ntawv [2] & 0xF0)) / 16; ntev adc_t = (((ntev) (cov ntaub ntawv [3] & 0xFF) * 65536) + ((ntev) (cov ntaub ntawv [4] & 0xFF) * 256) + (ntev) (cov ntaub ntawv [5] & 0xF0)) / 16; // Hloov cov ntaub ntawv av noo ntev adc_h = ((ntev) (cov ntaub ntawv [6] & 0xFF) * 256 + (ntev) (cov ntaub ntawv [7] & 0xFF)); // Kev ntsuas qhov ntsuas kub ntsuas ob npaug var1 = (((ob npaug) adc_t) / 16384.0 - ((ob npaug) dig_T1) / 1024.0) * ((ob npaug) dig_T2); ob var2 = (((ob npaug) adc_t) / 131072.0 - ((ob npaug) dig_T1) / 8192.0) * (((ob npaug) adc_t) /131072.0 - ((ob npaug) dig_T1) /8192.0)) * ((ob npaug) dig_T3); ob t_fine = (ntev) (var1 + var2); ob cTemp = (var1 + var2) / 5120.0; ob fTemp = cTemp * 1.8 + 32; // Kev ntsuas qhov ntsuas siab ntsuas var1 = ((ob npaug) t_fine / 2.0) - 64000.0; var2 = var1 * var1 * ((ob npaug) dig_P6) / 32768.0; var2 = var2 + var1 * ((ob npaug) dig_P5) * 2.0; var2 = (var2 / 4.0) + (((ob npaug) dig_P4) * 65536.0); var1 = (((ob npaug) dig_P3) * var1 * var1 / 524288.0 + ((ob npaug) dig_P2) * var1) / 524288.0; var1 = (1.0 + var1 / 32768.0) * ((ob npaug) dig_P1); ob p = 1048576.0 - (ob npaug) adc_p; p = (p - (var2 / 4096.0)) * 6250.0 / var1; var1 = ((ob npaug) dig_P9) * p * p / 2147483648.0; var2 = p * ((ob npaug) dig_P8) / 32768.0; ob npaug siab = (p + (var1 + var2 + ((ob npaug) dig_P7))) / 16.0) / 100; // Humidity offset calculations ob var_H = (((ob) t_fine) - 76800.0); var_H = (adc_h - (dig_H4 * 64.0 + dig_H5 / 16384.0 * var_H)) * (dig_H2 / 65536.0 * (1.0 + dig_H6 / 67108864.0 * var_H * (1.0 + dig_H3 / 67108864.0 * var_H)))); ob npaug av noo = var_H * (1.0 - dig_H1 * var_H / 524288.0); yog (av noo> 100.0) {av noo = 100.0; } lwm qhov yog (av noo <0.0) {av noo = 0.0; } // Cov ntaub ntawv tawm mus rau tshuaj ntsuam System.out.printf ("Kub hauv Celsius: %.2f C %n", cTemp); System.out.printf ("Kub hauv Fahrenheit: %.2f F %n", fTemp); System.out.printf ("Siab: %.2f hPa %n", siab); System.out.printf ("Tus txheeb ze Vaum: %.2f %% RH %n", av noo); }}

Kauj Ruam 4: Txoj Cai Siv Tau

Txoj Cai Xyaum Ua
Txoj Cai Xyaum Ua

Tam sim no, rub tawm (lossis git rub) cov cai thiab qhib nws hauv Raspberry Pi.

Khiav cov lus txib kom Sib Sau thiab Tshaj Tawm cov cai ntawm lub davhlau ya nyob twg thiab pom cov khoom tso tawm ntawm Saib. Tom qab ob peb lub sijhawm, nws yuav tshuaj xyuas txhua qhov ntsuas. Ua kom ntseeg tau tias koj muaj txoj cai hloov pauv thiab ua rau muaj kev thaj yeeb (ish), koj xav txog ntau lub tswv yim los hloov kho ntxiv (Txhua Qhov Haujlwm pib nrog Zaj Dab Neeg).

Kauj Ruam 5: Siv Hauv Ntiaj Teb Tsim

BME280 ua tiav qhov ua tau zoo hauv txhua daim ntawv thov xav tau cov av noo thiab ntsuas siab. Cov ntawv thov uas tau tshwm sim no yog Kev Paub Txog Cov ntsiab lus, xws li Kev Tshawb Pom Ntawm Daim tawv nqaij, Kev Tshawb Nrhiav Hloov Chaw, Kev Saib Xyuas Lub Cev / Nyob Zoo, Ceeb Toom Txog Kev Qhuav lossis Kub Kub, Kev Ntsuas Ntim thiab Huab Cua ntws, Kev Tswj Xyuas Lub Tsev Hauv Tsev, Tswj Cua Kub, Cua Txias, Cua Txias (HVAC), Internet ntawm Yam (IoT), Kev Txhim Kho GPS (piv txwv li Sijhawm-Rau-Thawj-Txhim Kho, Tuag Rov Los, Nrhiav Kom Pom), Kev Taw Qhia Sab Hauv Tsev (Hloov Kev Tshawb Fawb Hauv Pem Hauv Ntej, Kev Tshawb Fawb Hauv Tsev), Kev Taw Qhia Sab Nraud, Kev Ua Si & Kev Ua Si, Huab Cua Huab Cua Thiab Vertical Velocity Indication (Sawv/Dab Dej) Ceev).

Kauj Ruam 6: Xaus

Raws li koj tuaj yeem pom, txoj haujlwm no yog qhov ua piv txwv zoo ntawm yam khoom kho vajtse thiab software muaj peev xwm ua tau. Hauv lub sijhawm me me, ib tus tuaj yeem tsim qhov haujlwm zoo kawg nkaus! Tau kawg, qhov no yog qhov pib xwb. Ua kom lub Chaw Saib Xyuas Huab Cua Zoo Tshaj Plaws zoo li Lub Tsev Tshav Dav Hlau Tus Kheej Cov Chaw Huab Cua tuaj yeem koom nrog qee qhov kev ntsuas ntau dua li Anemometer (cua nrawm), Transmissometer (pom kev), Pyranometer (hnub ci tawg) thiab lwm yam Peb muaj cov vis dis aus qhia hauv Youtube muaj qhov ua haujlwm yooj yim ntawm I²C sensor nrog Rasp Pi. Nws yog qhov txaus siab tiag tiag los saib cov txiaj ntsig thiab ua haujlwm ntawm I²C kev sib txuas lus. Txheeb nws ib yam. Muaj kev lom zem tsim thiab kawm! Thov qhia rau peb paub tias koj xav li cas txog cov lus qhia no. Peb yuav nyiam ua qee qhov kev txhim kho yog tias tsim nyog.

Pom zoo: