Cov txheej txheem:

Siv Raspberry Pi, Ntsuas Qhov Siab, Siab, thiab Kub Nrog MPL3115A2: 6 Cov Kauj Ruam
Siv Raspberry Pi, Ntsuas Qhov Siab, Siab, thiab Kub Nrog MPL3115A2: 6 Cov Kauj Ruam

Video: Siv Raspberry Pi, Ntsuas Qhov Siab, Siab, thiab Kub Nrog MPL3115A2: 6 Cov Kauj Ruam

Video: Siv Raspberry Pi, Ntsuas Qhov Siab, Siab, thiab Kub Nrog MPL3115A2: 6 Cov Kauj Ruam
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Hlis ntuj nqeg
Anonim
Image
Image
Cov Khoom Uas Peb Tsis Xav Tau
Cov Khoom Uas Peb Tsis Xav Tau

Paub tias koj yog leej twg, thiab paub vim li cas koj thiaj li muaj nws

Nws yog qhov txaus ntshai. Peb nyob hauv lub hnub nyoog ntawm Internet Automation raws li nws plunges rau hauv plethora ntawm cov ntawv thov tshiab. Raws li lub khoos phis tawj thiab khoom siv hluav taws xob, peb tau kawm ntau yam nrog Raspberry Pi thiab txiav txim siab muab peb cov kev nyiam. Txoj haujlwm no siv sijhawm li ib teev yog tias koj tshiab rau I²C kev sib txuas thiab teeb tsa Software, thiab nws yog txoj hauv kev zoo los nthuav lub peev xwm ntawm MPL3115A2 nrog Raspberry Pi hauv Java.

Kauj Ruam 1: Cov Khoom Uas Peb Xav Tau

Cov Khoom Uas Peb Tsis Xav Tau
Cov Khoom Uas Peb Tsis Xav Tau
Cov Khoom Uas Peb Tsis Xav Tau
Cov Khoom Uas Peb Tsis Xav Tau
Cov Khoom Uas Peb Tsis Xav Tau
Cov Khoom Uas Peb Tsis Xav Tau

1. Raspberry Pi

Thawj kauj ruam yog tau txais Raspberry Pi board. Qhov ntse me me no yog siv los ntawm hobbyists, cov kws qhia ntawv thiab hauv kev tsim kho ib puag ncig ib puag ncig.

2. I2C Shield rau Raspberry Pi

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

3. Altimeter, Siab thiab Kub Sensor, MPL3115A2

MPL3115A2 yog MEMS lub siab ntsuas nrog I²C interface los muab Cov Ntaub Ntawv Siab, Qhov Siab, thiab Kub. Qhov ntsuas no siv I²2 raws tu qauv rau kev sib txuas lus. Peb tau yuav qhov ntsuas no los ntawm Dcube Store.

4. Txuas Cable

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

5. Micro USB cable

Raspberry Pi tau siv los ntawm micro USB khoom.

6. Kev Txhim Kho Kev Siv Internet - Ethernet Cable/WiFi Module

Ib qho ntawm thawj yam uas koj yuav xav ua yog kom tau txais koj li Raspberry Pi txuas nrog rau Internet. Koj tuaj yeem txuas nrog siv Ethernet cable lossis nrog Wireless USB Nano WiFi adapter.

7. HDMI Cable (Yeem, Koj Xaiv)

Koj tuaj yeem txuas Raspberry Pi mus rau tus saib xyuas siv HDMI cable. Tsis tas li, koj tuaj yeem nkag mus rau koj li Raspberry Pi los ntawm kev siv SSH/PuTTY.

Kauj Ruam 2: Khoos Phis Tawj Sib Txuas los Muab Ua Ke Hauv Circuit

Kho vajtse sib txuas los muab tso ua ke hauv Circuit
Kho vajtse sib txuas los muab tso ua ke hauv Circuit
Kho vajtse sib txuas los muab tso ua ke hauv Circuit
Kho vajtse sib txuas los muab tso ua ke hauv Circuit

Ua qhov Circuit Court raws li qhov qhia pom hauv qhov dav, kev sib txuas yog yooj yim heev. Ua raws cov lus qhia thiab cov duab saum toj no, thiab koj yuav tsum tsis muaj teeb meem. Thaum npaj, peb tau saib xyuas kho vajtse thiab coding nrog rau cov khoom siv hluav taws xob pib. Peb xav tsim cov txheej txheem hluav taws xob yooj yim rau txoj haujlwm no. Hauv daim duab, koj tuaj yeem pom qhov sib txawv, cov khoom siv hluav taws xob thiab I²C sensor tom qab I²C cov txheej txheem kev sib txuas lus. Vam tias, qhov no qhia qhov yooj yim ntawm cov khoom siv hluav taws xob rau txoj haujlwm no.

Kev sib txuas ntawm Raspberry Pi thiab I2C Shield

Txog qhov no, Raspberry Pi thiab tso I²C Shield rau nws. Nias lub Shield maj mam (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 ua raws los ntawm Raspberry Pi nrog I²C daim ntaub thaiv npog nws. Peb muaj I²C Shield thiab I²C txuas cov xov hluav taws xob ntawm peb sab raws li qhov txiaj ntsig zoo heev raws li peb tau tsuas yog ntsaws thiab ua si xaiv. Tsis muaj tus pin thiab qhov teeb meem txuas ntxiv thiab yog li, tsis meej pem ploj mus. Dab tsi yog kev nplij siab tsuas yog xav txog koj tus kheej hauv lub vev xaib ntawm xov hlau thiab nkag mus rau qhov ntawd. Yooj yim li qhov no!

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 Tseem Ceeb

Txhawm rau kom peb txoj haujlwm tiav, peb xav tau kev siv internet rau peb Raspberry Pi. Hauv qhov no, koj muaj kev xaiv xws li txuas Ethernet (LAN) cable. Tsis tas li, raws li kev xaiv tab sis txoj hauv kev zoo los siv WiFi adapter.

Kev ua kom muaj zog ntawm Circuit Court

Txuas lub Micro USB cable rau hauv lub hwj chim nkaus ntawm Raspberry Pi. Qhib nws thiab voila, peb zoo mus!

Kev Sib Txuas rau Screen

Peb tuaj yeem muaj HDMI cable txuas nrog tus saib lossis peb tuaj yeem hloov kho me ntsis los ua peb lub taub hau Pi (siv -SSH/PuTTY) uas pab txiav tus nqi ntxiv vim tias peb yog qee yam nyiam ua haujlwm.

Thaum tus cwj pwm pib them nyiaj, nws hu ua kev nyiam ua

Kauj Ruam 3: Raspberry Pi Programming hauv Java

Raspberry Pi Programming hauv Java
Raspberry Pi Programming hauv Java

Java Code rau Raspberry Pi thiab MPL3115A2 Sensor. Nws muaj nyob hauv peb Github chaw cia khoom.

Ua ntej mus rau txoj cai, nco ntsoov koj 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. Qhov siab yog xam los ntawm kev siv cov zauv hauv qab no:

h = 44330.77 {1 - (p / p0) ^ 0.1902632} + OFF_H (Sau Tus Nqi)

qhov twg p0 = qib siab hiav txwv (101326 Pa) thiab h yog hauv meters. MPL3115A2 siv tus nqi no txij li cov npe offset tau txhais tias yog 2 Pascals ib LSB. Txoj cai tau hais meej nyob rau hauv pem hauv ntej ntawm koj thiab nws nyob hauv daim ntawv yooj yim tshaj plaws uas koj tuaj yeem xav txog thiab koj yuav tsum tsis muaj teeb meem.

Koj tuaj yeem luam theej Java txoj haujlwm ua haujlwm rau lub ntsuas no los ntawm no thiab.

// 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. // MPL3115A2 // Txoj cai no yog tsim los ua haujlwm nrog MPL3115A2_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 chav kawm MPL3115A2

{pej xeem zoo li qub tsis muaj dab tsi tseem ceeb (Txoj hlua sib cav ) cuam tshuam kev zam {// Tsim I2C npav I2CBus Bus = I2CFactory.getInstance (I2CBus. BUS_1); // Tau txais I2C ntaus ntawv, MPL3115A2 I2C chaw nyob yog 0x60 (96) I2CDevice ntaus ntawv = Bus.getDevice (0x60); // Xaiv tswj kev sau npe // Ua haujlwm nquag, OSR = 128, hom ntsuas qhov siab ntaus ntawv.write (0x26, (byte) 0xB9); // Xaiv cov ntaub ntawv teeb tsa sau npe // Cov ntaub ntawv npaj tau tshwm sim qhib rau qhov siab, siab, ntsuas kub.write (0x13, (byte) 0x07); // Xaiv tswj kev sau npe // Ua haujlwm nquag, OSR = 128, hom ntsuas qhov siab ntaus ntawv.write (0x26, (byte) 0xB9); Xov.sleep (1000);

// Nyeem 6 bytes ntawm cov ntaub ntawv los ntawm chaw nyob 0x00 (00)

// xwm txheej, tHeight msb1, tHeight msb, tHeight lsb, temp msb, temp lsb byte cov ntaub ntawv = tshiab byte [6]; device.read (0x00, cov ntaub ntawv, 0, 6);

// Hloov cov ntaub ntawv mus rau 20-ntsis

int tHeight = (((data [1] & 0xFF) * 65536) + ((data [2] & 0xFF) * 256) + (data [3] & 0xF0)) / 16); int temp = ((cov ntaub ntawv [4] * 256) + (data [5] & 0xF0)) / 16; ob qhov siab = tHeight / 16.0; ob cTemp = (temp / 16.0); ob fTemp = cTemp * 1.8 + 32;

// Xaiv tswj sau npe

// Hom ua haujlwm, OSR = 128, hom ntsuas cua ntsuas ntaus ntawv.write (0x26, (byte) 0x39); Xov.sleep (1000); // Nyeem 4 bytes ntawm cov ntaub ntawv los ntawm chaw nyob 0x00 (00) // xwm txheej, pres msb1, pres msb, pres lsb device.read (0x00, cov ntaub ntawv, 0, 4);

// Hloov cov ntaub ntawv mus rau 20-ntsis

int pres = (((cov ntaub ntawv [1] & 0xFF) * 65536) + ((data [2] & 0xFF) * 256) + (data [3] & 0xF0)) / 16; ob npaug siab = (pres / 4.0) / 1000.0; // Cov ntaub ntawv tso tawm rau lub vijtsam System.out.printf ("Siab: %.2f kPa %n", siab); System.out.printf ("Qhov siab: %.2f m %n", qhov siab); System.out.printf ("Kub hauv Celsius: %.2f C %n", cTemp); System.out.printf ("Kub hauv Fahrenheit: %.2f F %n", fTemp); }}

Kauj Ruam 4: Kev Xyaum Ua Haujlwm ntawm Txoj Cai (Ua Haujlwm)

Kev Xyaum Ua Haujlwm ntawm Txoj Cai (Ua Haujlwm)
Kev Xyaum Ua Haujlwm ntawm Txoj Cai (Ua Haujlwm)

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 feeb, nws yuav tso tawm txhua qhov ntsuas. Tom qab ua kom ntseeg tau tias txhua yam ua haujlwm tau zoo, koj tuaj yeem coj txoj haujlwm no mus rau hauv qhov haujlwm loj dua.

Kauj Ruam 5: Cov ntawv thov thiab Nta

Kev siv ntau ntawm MPL3115A2 Precision Altimeter sensor yog nyob rau hauv daim ntawv thov xws li Daim Ntawv Qhia (Daim Ntawv Qhia Kev Pabcuam, Kev Taw Qhia), Sib Nqus Sib Nqus, lossis GPS (GPS Tuag Txheeb Ze, Kev Txhim Kho GPS Rau Kev Pabcuam Thaum Muaj Xwm Ceev), Kev Ua Tau Zoo Tshaj Plaws, Smartphones/Tablets, Tus Kheej Cov Khoom Siv Hluav Taws Xob thiab Satellites (Cov Khoom Siv Hauv Chaw Huab Cua/Huab Cua).

Rau xws li Siv lub ntsuas no thiab Rasp Pi, koj tuaj yeem tsim Digital Visual Altimeter, qhov tseem ceeb tshaj plaws ntawm cov cuab yeej dhia saum ntuj, uas tuaj yeem ntsuas qhov siab, huab cua siab, thiab kub. Koj tuaj yeem ntxiv cua ntsuas cua thiab lwm yam kev ntsuas kom ua rau muaj qhov ntxim nyiam dua.

Kauj Ruam 6: Xaus

Txij li qhov kev zov me nyuam tuaj yeem hloov kho tau zoo, muaj ntau txoj hauv kev txaus siab uas koj tuaj yeem txuas ntxiv txoj haujlwm no thiab ua kom nws zoo dua. Piv txwv li, Ib qho altimeter/interferometer yuav suav nrog ob peb qhov siab tau teeb tsa ntawm masts uas yuav tau txais kev ntsuas ib txhij, yog li muab kev txuas mus tas li, ib leeg-lossis ntau-altimeter dav-npog thaj tsam. Peb muaj cov vis dis aus nthuav qhia hauv YouTube uas tuaj yeem pab koj kom nkag siab zoo txog txoj haujlwm no.

Pom zoo: