Cov txheej txheem:

Kev ntsuas lub teeb pom kev zoo los ntawm kev siv BH1715 thiab Raspberry Pi: 5 Kauj Ruam
Kev ntsuas lub teeb pom kev zoo los ntawm kev siv BH1715 thiab Raspberry Pi: 5 Kauj Ruam

Video: Kev ntsuas lub teeb pom kev zoo los ntawm kev siv BH1715 thiab Raspberry Pi: 5 Kauj Ruam

Video: Kev ntsuas lub teeb pom kev zoo los ntawm kev siv BH1715 thiab Raspberry Pi: 5 Kauj Ruam
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Hlis ntuj nqeg
Anonim
Image
Image

Nag hmo peb tau ua haujlwm ntawm LCD cov lus, thiab thaum ua haujlwm dhau ntawm lawv peb tau pom qhov tseem ceeb ntawm kev suav qhov teeb pom kev zoo. Kev siv lub teeb tsis yog tsuas yog qhov tseem ceeb hauv lub cev ntawm lub ntiaj teb no tab sis nws muaj nws lub luag haujlwm hais tau zoo hauv kev siv tshuaj lom neeg ib yam nkaus. Qhov kwv yees kwv yees ntawm lub teeb siv ua lub luag haujlwm tseem ceeb hauv peb cov txheej txheem, hauv kev loj hlob ntawm cov nroj tsuag, thiab lwm yam.

Hauv qhov kev qhia no, peb yuav los qhia txog kev ua haujlwm ntawm BH1715 nrog Raspberry pi, siv Java ua cov lus programming.

Kho vajtse uas koj yuav xav tau rau lub hom phiaj no yog raws li hauv qab no:

1. BH1715 - Ambient Teeb Sensor

2. Raspberryy Pi

3. I2C Cable

4. I2C Shield Rau Raspberry Pi

5. Ethernet Cable

Kauj Ruam 1: BH1715 Txheej Txheem:

Yam Koj Xav Tau.. !!
Yam Koj Xav Tau.. !!

Ua ntej tshaj plaws, peb xav paub koj nrog cov yam ntxwv tseem ceeb ntawm lub ntsuas qhov ntsuas uas yog BH1715 thiab kev sib txuas lus raws tu qauv uas nws ua haujlwm.

BH1715 yog digital Ambient Light Sensor nrog I²C tsheb npav sib cuam tshuam. BH1715 feem ntau yog siv kom tau txais cov ntaub ntawv teeb pom kev zoo los kho LCD thiab Keypad lub teeb pom kev zoo rau lub xov tooj ntawm tes. Cov cuab yeej no muaj 16-ntsis kev daws teeb meem thiab ntsuas ntsuas tau ntau, tso cai kuaj pom los ntawm.23 txog 100, 000 lux.

Cov txheej txheem kev sib txuas lus uas lub sensor ua haujlwm yog I2C. I2C sawv cev rau kev sib koom ua ke. Nws yog cov txheej txheem kev sib txuas lus uas kev sib txuas lus tau tshwm sim los ntawm SDA (cov ntaub ntawv xov xwm) thiab SCL (cov xov tooj). Nws tso cai txuas ntau yam khoom siv tib lub sijhawm. Nws yog ib qho ntawm cov txheej txheem kev sib txuas lus yooj yim tshaj plaws thiab muaj txiaj ntsig tshaj plaws.

Kauj Ruam 2: Yam Koj Xav Tau..

Yam Koj Xav Tau.. !!
Yam Koj Xav Tau.. !!
Yam Koj Xav Tau.. !!
Yam Koj Xav Tau.. !!
Yam Koj Xav Tau.. !!
Yam Koj Xav Tau.. !!

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

1. BH1715 - Ambient Teeb Sensor

2. Raspberry Pi

3. I2C Cable

4. I2C Shield Rau Raspberry Pi

5. Ethernet cable

Kauj Ruam 3: Khoos Phis Tawj Hookup:

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 ntsuas cua thiab raspberry pi. 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:

BH1715 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 4: Teeb Pom Kev Ntsuas Siv Java Code:

Kev Ntsuas Teeb Pom Kev Siv Siv Java Code
Kev Ntsuas Teeb Pom Kev Siv Siv Java Code
Kev Ntsuas Teeb Pom Kev Siv Siv Java Code
Kev Ntsuas Teeb Pom Kev Siv Siv Java Code

Qhov zoo ntawm kev siv raspberry pi yog, uas muab rau koj hloov pauv ntawm cov lus programming uas koj xav tau los teeb tsa lub rooj tsav xwm txhawm rau txhawm rau cuam tshuam lub sensor nrog nws. Kev siv cov txiaj ntsig zoo ntawm pawg no, peb tab tom qhia ntawm no nws tau ua haujlwm hauv Java. Java code rau BH1715 tuaj yeem rub tawm los ntawm peb cov zej zog GitHub uas yog Dcube Store.

Ntxiv rau qhov yooj yim ntawm cov neeg siv, peb tab tom piav qhia cov cai ntawm no thiab:

Raws li thawj kauj ruam ntawm kev sau npe, koj yuav tsum rub lub pi4j lub tsev qiv ntawv hauv java, vim tias lub tsev qiv ntawv no txhawb nqa cov haujlwm siv hauv txoj cai. Yog li, txhawm rau rub lub tsev qiv ntawv koj tuaj yeem mus ntsib qhov txuas hauv qab no:

pi4j.com/install.html

Koj tuaj yeem luam qhov ua haujlwm java code rau lub ntsuas no los ntawm no kuj:

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

SWB 1715 Stb

// Tus lej no yog tsim los ua haujlwm nrog BH1715_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 BH1715

{

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

{

// Tsim I2C npav

I2CBus tsheb npav = I2CFactory.getInstance (I2CBus. BUS_1);

// Tau txais I2C ntaus ntawv, BH1715 I2C chaw nyob yog 0x23 (35)

I2CDevice ntaus ntawv = bus.getDevice (0x23);

// Xa lub zog ntawm kev hais kom ua

ntaus ntawv.write ((byte) 0x01);

// Xa cov lus ntsuas ntsuas mus tas li

ntaus ntawv.write ((byte) 0x10);

Xov.sleep (500);

// Nyeem 2 bytes ntawm cov ntaub ntawv

// luminance msb, lumance lsb

byte cov ntaub ntawv = tshiab byte [2];

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

// Hloov cov ntaub ntawv

ob chav ci ntsa iab = ((cov ntaub ntawv [0] & 0xFF) * 256 + (cov ntaub ntawv [1] & 0xFF)) / 1.20;

// Cov ntaub ntawv tso tawm rau lub vijtsam

System.out.printf ("Ambient Light Luminance: %.2f lux %n", luminance);

}

}

Lub tsev qiv ntawv uas txhawb nqa i2c kev sib txuas lus ntawm lub sensor thiab pawg thawj coj yog pi4j, nws ntau pob khoom I2CBus, I2CDevice thiab I2CFactory pab tsim kom muaj kev sib txuas.

ntshuam com.pi4j.io.i2c. I2CBus; ntshuam com.pi4j.io.i2c. I2CDevice; ntshuam com.pi4j.io.i2c. I2CFactory; ntshuam java.io. IOException;

Ib feem ntawm txoj cai no ua rau lub ntsuas hluav taws xob ua haujlwm rau ntsuas lub teeb los ntawm kev sau cov lus txib tshwj xeeb uas siv sau () ua haujlwm thiab tom qab ntawd cov ntaub ntawv raug nyeem siv siv nyeem () ua haujlwm.

ntaus ntawv.write ((byte) 0x01); // hwj chim ntawm kev hais kom ua

ntaus ntawv.write ((byte) 0x10); // kev ntsuas ntsuas txuas ntxiv

byte cov ntaub ntawv = tshiab byte [2]; // Nyeem 2 bytes ntawm cov ntaub ntawv

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

Cov ntaub ntawv tau txais los ntawm lub ntsuas hluav taws xob tau hloov pauv mus rau qhov tsim nyog siv los ntawm kev siv cov hauv qab no:

ob npaug luminance = ((cov ntaub ntawv [0] & 0xFF) * 256 + (cov ntaub ntawv [1] & 0xFF)) / 1.20;

Cov zis tau luam tawm siv System.out.println () ua haujlwm, hauv cov qauv hauv qab no.

System.out.printf ("Ambient Light Luminance: %.2f lux %n", luminance);

Qhov tso tawm ntawm lub ntsuas hluav taws xob tau qhia hauv daim duab saum toj no.

Kauj Ruam 5: Cov ntawv thov:

Cov ntawv thov
Cov ntawv thov

BH1715 yog lub teeb pom kev ib puag ncig lub teeb pom kev zoo uas tuaj yeem suav nrog hauv xov tooj ntawm tes, LCD TV, NCEJ PC thiab lwm yam. siv lub teeb pom kev zoo.

Pom zoo: