Cov txheej txheem:

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

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

Video: Raspberry Pi - TSL45315 Ambient Light Sensor Java Qhia: 4 Kauj Ruam
Video: Raspberry Pi TSL45315 Ambient Light Sensor Java Tutorial 2024, Hlis ntuj nqeg
Anonim
Image
Image

TSL45315 yog lub teeb pom kev zoo ib puag ncig digital. Nws kwv yees tib neeg qhov muag teb raws ntau yam teeb pom kev zoo. Cov cuab yeej muaj peb lub sijhawm xaiv ua ke thiab muab ncaj qha 16-ntsis lux tso tawm ntawm I2C tsheb npav sib cuam tshuam. Cov cuab yeej muaj cov kab ntawv photodiode, kev sib xyaw ua ke sib piv-rau-digital hloov pauv (ADC), teeb liab ua cov kab hluav taws xob, cov lej xav txog qhov xav tau, thiab I2C cov lej sib cuam tshuam ntawm ib qho CMOS kev sib txuas ua ke los muab cov ntaub ntawv 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. TSL45315

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 kawg ntawm I2C cable rau TSL45315 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 TSL45315 tuaj yeem rub tawm los ntawm peb GitHub chaw cia khoom- Dcube Store.

Nov yog qhov txuas rau tib yam:

github.com/DcubeTechVentures/TSL45315

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.

TSL45315

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

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 TSL45315

{

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, TSL45315 I2C chaw nyob yog 0x29 (41)

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

// Xa cov lus txib pib

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

// Xa cov lus txib ntsuas

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

Xov.sleep (800);

// Nyeem 2 bytes ntawm cov ntaub ntawv los ntawm chaw nyob 0x04 (4), LSB ua ntej

byte cov ntaub ntawv = tshiab byte [2];

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

// Hloov cov ntaub ntawv mus rau lux

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

// Cov ntaub ntawv tso tawm rau lub vijtsam

System.out.printf ("Tag nrho cov luminance yog: %d lux %n", luminance);

}

}

Kauj Ruam 4: Cov ntawv thov:

Qhov dav dav dav ntawm lub teeb pom kev ib puag ncig ua rau nws muaj txiaj ntsig tshwj xeeb hauv kev siv sab nraum zoov uas nws raug rau tshav ntuj ncaj qha. Cov cuab yeej siv tau zoo tshaj plaws rau kev siv tsis siv neeg kev teeb ntawm txoj kev thiab kev nyab xeeb, daim ntawv tshaj tawm, thiab teeb pom kev zoo hauv tsheb. TSL45315 cov cuab yeej kuj tseem tuaj yeem siv hauv lub xeev ruaj khov thiab teeb pom kev zoo rau kev tswj tsis siv neeg thiab kev sau hnub nruab hnub kom ua kom muaj kev txuag hluav taws xob ntau. Lwm daim ntawv thov suav nrog tso saib lub teeb pom kev zoo txhawm rau txuas lub roj teeb lub neej thiab ua kom pom kev zoo hauv xov tooj ntawm tes, ntsiav tshuaj, thiab phau ntawv sau.

Pom zoo: