Cov txheej txheem:

Raspberry Pi - BH1715 Digital Ambient Light Sensor Java Qhia: 4 Kauj Ruam
Raspberry Pi - BH1715 Digital Ambient Light Sensor Java Qhia: 4 Kauj Ruam

Video: Raspberry Pi - BH1715 Digital Ambient Light Sensor Java Qhia: 4 Kauj Ruam

Video: Raspberry Pi - BH1715 Digital Ambient Light Sensor Java Qhia: 4 Kauj Ruam
Video: Raspberry Pi BH1715 Digital Ambient Light Sensor Java Tutorial 2024, Kaum ib hlis
Anonim
Image
Image

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. Nov yog nws qhov ua piv txwv nrog raspberry pi siv java code.

Kauj Ruam 1: Yam Koj Xav Tau..

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

1. Raspberry Pi

2. HLB 1715

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 daim I2C daim thaiv rau raspberry pi thiab maj mam thawb nws hla gpio pins ntawm raspberry pi.

Tom qab ntawd txuas ib qho kawg ntawm I2C cable rau BH1715 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:

Txoj Cai
Txoj Cai

Tus lej java rau BH1715 tuaj yeem rub tawm los ntawm peb GitHub chaw cia khoom- Dcube Store

Nov yog qhov txuas rau tib yam:

github.com/DcubeTechVentures/BH1715…

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.

SWB 1715 Stb

// Cov cai no tau tsim los ua haujlwm nrog BH1715_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 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 npaug luminance = ((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);

}

}

Kauj Ruam 4: 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: