Cov txheej txheem:

Raspberry Pi - TMD26721 Infrared Digital Proximity Detector Java Qhia: 4 Kauj Ruam
Raspberry Pi - TMD26721 Infrared Digital Proximity Detector Java Qhia: 4 Kauj Ruam

Video: Raspberry Pi - TMD26721 Infrared Digital Proximity Detector Java Qhia: 4 Kauj Ruam

Video: Raspberry Pi - TMD26721 Infrared Digital Proximity Detector Java Qhia: 4 Kauj Ruam
Video: Raspberry Pi TMD26721 Infrared Digital Proximity Detector Java Tutorial 2024, Hlis ntuj nqeg
Anonim

TMD26721 yog lub ntsuas hluav taws xob digital sib ze uas muab qhov ua kom pom qhov sib thooj sib xws thiab cov txheej txheem digital sib cuam tshuam hauv ib tus lej 8-pin nto mount module. Qhov kev tshawb pom qhov sib xws suav nrog txhim kho teeb liab-rau-nrov thiab raug. Ib qho kev sib thooj sau npe tso cai them nyiaj rau qhov khoos phis tawj sib txuas nruab nrab ntawm IR LED thiab lub sensor. 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.. !!
Yam Koj Xav Tau.. !!
Yam Koj Xav Tau.. !!

1. Raspberry Pi

2. TMD26721

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 TMD26721 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 TMD26721 tuaj yeem rub tawm los ntawm peb qhov chaw cia khoom github- Dcube Store Community.

Nov yog qhov txuas

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.

TMD26721

// Cov cai no tau tsim los ua haujlwm nrog TMD26721_I2CS I2C Mini Module muaj los ntawm

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 TMD26721

{

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, TMD26721 I2C chaw nyob yog 0x39 (57)

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

// Xaiv lub sijhawm sib thooj sau npe lossis hais kom sau npe

// Lub sij hawm = 2.73 ms

device.write (0x02 | 0x80, (byte) 0xFF);

// Xaiv tos lub sijhawm sau npe LOSSIS nrog sau npe hais kom ua

// Sijhawm = 2.73 ms

device.write (0x03 | 0x80, (byte) 0xFF);

// Xaiv memse suav sau npe LOS nrog sau npe hais kom ua

// Pulse suav = 32

device.write (0x0E | 0x80, (byte) 0x20);

// Xaiv tswj kev sau npe LOS nrog sau npe hais kom ua

// 100 mA LED lub zog, qhov sib thooj siv CH1 diode, 1x PGAIN, 1x AGAIN

device.write (0x0F | 0x80, (byte) 0x20);

// Xaiv kom tso npe LOS YOG nrog hais kom sau npe

// Teeb Fais Fab ON, nyob sib ze thiab tos kom qhib

device.write (0x00 | 0x80, (byte) 0x0D);

Xov.sleep (800);

// Nyeem 2 bytes ntawm cov ntaub ntawv los ntawm chaw nyob 0x18 (24)

// sib thooj lsb, sib thooj msb

byte cov ntaub ntawv = tshiab byte [2];

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

// Hloov cov ntaub ntawv

int sib thooj = (((data [1] & 0xFF) * 256)+ (data [0] & 0xFF)));

// Cov ntaub ntawv tso tawm rau lub vijtsam

System.out.printf ("Qhov sib thooj ntawm lub cuab yeej: %d %n", sib thooj);

}

}

Kauj Ruam 4: Cov ntawv thov:

TMD26721 yog lub infrared digital sib thooj sensor uas tuaj yeem suav nrog hauv Txawb Xov Tooj Ntawm Tes Touchscreen Control thiab Tsis Siv Neeg Lub Xov Tooj Pab Tau. Nws kuj tseem tuaj yeem muab Cov Neeg Siv Khoom Hloov Hloov pauv ntxiv rau Kev Ruaj Ntseg Ntawv. Nws qhov kev ua haujlwm siab thiab ntseeg tau ua rau nws haum rau ntau yam kev nyob ze kev thov.

Pom zoo: