Cov txheej txheem:

Raspberry Pi - PCA9536 Cov tswv yim/tso tawm Expander Python Tutorial: 4 Cov Kauj Ruam
Raspberry Pi - PCA9536 Cov tswv yim/tso tawm Expander Python Tutorial: 4 Cov Kauj Ruam

Video: Raspberry Pi - PCA9536 Cov tswv yim/tso tawm Expander Python Tutorial: 4 Cov Kauj Ruam

Video: Raspberry Pi - PCA9536 Cov tswv yim/tso tawm Expander Python Tutorial: 4 Cov Kauj Ruam
Video: Raspberry Pi PCA9536 Digital I/O Buzzer Java Tutorial 2024, Kaum ib hlis
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 tus lej nab npawb.

Kauj Ruam 1: Yam Koj Xav Tau..

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

1. Raspberry Pi

2. PCA9536

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 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 nab npawb nab npawb rau PCA9536 tuaj yeem rub tawm los ntawm peb qhov chaw cia khoom github- DCUBE Store.

Nov yog qhov txuas

Peb tau siv SMBus lub tsev qiv ntawv rau sej code, cov kauj ruam rau nruab SMBus ntawm raspberry pi tau piav qhia ntawm no:

pypi.python.org/pypi/smbus-cffi/0.5.1

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 sib txuam.

# TSA 9536

# Txoj cai no yog tsim los ua haujlwm nrog PCA9536_I2CIO I2C Mini Module #

ntshuam smbus

lub sij hawm ntshuam

# Tau I2C npav

npav = smbus. SMBus (1)

# PCA9536 chaw nyob, 0x41 (65)

# Xaiv kev teeb tsa sau npe, 0x03 (03)

# 0xFF (255) Txhua tus pin teeb tsa raws li cov tswv yim

bus.write_byte_data (0x41, 0x03, 0xFF)

# Tso tawm rau lub vijtsam

luam tawm "Txhua Lub Xeev Pins yog HIGH"

sijhawm.s pw (0.5)

# PCA9536 chaw nyob, 0x41 (65)

# Nyeem cov ntaub ntawv rov qab los ntawm 0x00 (00), 1 byte

cov ntaub ntawv = bus.read_byte_data (0x41, 0x00)

# Hloov cov ntaub ntawv mus rau 4-ntsis

data = (cov ntaub ntawv & 0x0F)

rau kuv hauv ntau (0, 4):

yog (cov ntaub ntawv & (2 ** i)) == 0:

luam tawm "I/O Pin %d Lub Xeev LOW" %i

lwm tus:

luam tawm "I/O Pin %d Lub Xeev yog HIGH" %i

sijhawm.s pw (0.5)

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: