Cov txheej txheem:

Raspberry Pi - PCA9536 Kev Tawm Tswv Yim/Tso Tawm Expander Java Qhia: 4 Kauj Ruam
Raspberry Pi - PCA9536 Kev Tawm Tswv Yim/Tso Tawm Expander Java Qhia: 4 Kauj Ruam

Video: Raspberry Pi - PCA9536 Kev Tawm Tswv Yim/Tso Tawm Expander Java Qhia: 4 Kauj Ruam

Video: Raspberry Pi - PCA9536 Kev Tawm Tswv Yim/Tso Tawm Expander Java Qhia: 4 Kauj Ruam
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Hlis ntuj nqeg
Anonim
Image
Image

PCA9536 yog 8-tus pin CMOS ntaus ntawv uas muab 4 lub ntsis ntawm Lub Hom Phiaj Dav Dav thaum uas tig mus Kev Tawm/Tawm (GPIO) nthuav dav rau I2C-npav/SMBus daim ntawv thov. Nws suav nrog 4-ntsis Kev teeb tsa sau npe los ua haujlwm lub hom phiaj ntawm kev xaiv tswv yim lossis xaiv tawm, 4-ntsis Kev Nkag Nkag Chaw Nkag Nkag, 4-ntsis Chaw Tso Tawm Chaw Tso Npe thiab 4-ntsis Polarity Inversion register active HIGH lossis nquag ua haujlwm LOW. 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. PCA9536

LINK:

3. I²C Cable

LINK:

4. I²C Shield rau Raspberry Pi

LINK:

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

Nov yog qhov txuas rau tib yam:

github.com/DcubeTechVentures/PCA9536/blob/master/Java/PCA9536.java

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.

TIAB SA 9536

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

chav kawm pej xeem PCA9536

{

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

{

// Tsim I2C npav

I2CBus Bus = I2CFactory.getInstance (I2CBus. BUS_1);

// Tau txais I2C ntaus ntawv, PCA9536 I2C chaw nyob yog 0x41 (65)

I2CDevice ntaus ntawv = Bus.getDevice (0x41);

// Xaiv cov npe sau npe

// Txhua tus pin teeb tsa ua tswv yim

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

// Tso tawm rau lub vijtsam

System.out.printf ("Txhua lub xeev Pins yog HIGH %n");

Xov.sleep (500);

// Nyeem 1 byte ntawm cov ntaub ntawv

byte cov ntaub ntawv = tshiab byte [1];

cov ntaub ntawv [0] = (byte) device.read (0x00);

// Hloov cov ntaub ntawv mus rau 4-khoom

int data1 = (data [0] & 0x0F);

rau (int i = 0; i <4; i ++)

{

yog ((data1 & (int) Math.pow (2, i))) == 0)

{

System.out.printf ("I/O Pin %d State is LOW %n", i);

}

lwm tus

{

System.out.printf ("I/O Pin %d State is HIGH %n", i);

Xov.sleep (500);

}

}

}

}

Kauj Ruam 4: Cov ntawv thov:

PCA9536 tuaj yeem ua haujlwm ua I/O nthuav dav. Nws muab kev daws teeb meem yooj yim thaum xav tau cov tswv yim ntxiv/tso tawm. Feem ntau nws tau ua haujlwm hauv cov kab ke uas xav tau kev nthuav dav rau ACPI lub zog hloov pauv, ntsuas ntsuas, thawb khawm, LEDs, kiv cua, thiab lwm yam.

Pom zoo: