Cov txheej txheem:

Daim ntawv thov MCP-23008 Siv Kev Sib Txuas Sib Txuas (I2C) :: 6 Kauj Ruam
Daim ntawv thov MCP-23008 Siv Kev Sib Txuas Sib Txuas (I2C) :: 6 Kauj Ruam

Video: Daim ntawv thov MCP-23008 Siv Kev Sib Txuas Sib Txuas (I2C) :: 6 Kauj Ruam

Video: Daim ntawv thov MCP-23008 Siv Kev Sib Txuas Sib Txuas (I2C) :: 6 Kauj Ruam
Video: Hmong New Song 2019 Xy Lee feat. SuabNag Yaj - Koj Yog Kuv Lub Neej (Official MV - 4K) 2024, Hlis ntuj nqeg
Anonim
Daim ntawv thov MCP-23008 Siv Kev Sib Txuas Sib Txuas (I2C)
Daim ntawv thov MCP-23008 Siv Kev Sib Txuas Sib Txuas (I2C)

Nyob zoo

Nyob zoo os.. !!

Kuv (Somanshu Choudhary) sawv cev ntawm Dcube thev naus laus zis kev lag luam mus rau kev tswj hwm ntawm I2C raws tu qauv siv Arduino nano thiab MCP23008.

Kauj ruam 1: Txheej txheem cej luam

Txheej txheem cej luam
Txheej txheem cej luam
  • Cov cuab yeej MCP23X08 muab 8-ntsis, lub hom phiaj dav, nthuav dav I/O nthuav dav rau I2C tsheb npav lossis daim ntawv thov SPI.
  • MCP23X08 muaj ntau yam 8-ntsis teeb tsa cov npe rau kev tawm tswv yim, tso tawm thiab xaiv polarity. Tus txheej txheem txheej txheem tuaj yeem ua haujlwm rau I/Os li kev nkag los lossis tawm los ntawm kev sau I/O teeb tsa me ntsis. Cov ntaub ntawv rau txhua qhov kev tawm tswv yim lossis tso tawm raug khaws cia hauv qhov sib nkag tau nkag los lossis tso tawm npe. Lub polarity ntawm Kev Nkag Mus Nkag Chaw Nkag tuaj yeem hloov pauv nrog Polarity Inversion register. Txhua qhov sau npe tuaj yeem nyeem los ntawm tus txheej txheem.
  • DATASHEET LINK:

Kauj ruam 2: Yam Koj Xav Tau / Txuas

Yam Koj Xav Tau / Txuas
Yam Koj Xav Tau / Txuas

1. Arduino Nano LINK:

2. Siv thaiv rau Arduino Nano LINK:

3. USB Cable Hom A rau Micro Hom B 6 Taw Ntev

4. I²C Cable LINK:

5. Yim SPDT I²C Tswj Kev Tshaj Tawm

6. Adapter LINK:

Kauj Ruam 3: Daim duab Circuit Court

Daim duab Circuit Court
Daim duab Circuit Court
Daim duab Circuit Court
Daim duab Circuit Court

Kauj ruam 4: Programming - Kuv

Programming - Kuv
Programming - Kuv
Programming - Kuv
Programming - Kuv
  • Hauv txoj cai no, Kuv siv Txoj Haujlwm Pabcuam Txheej Txheem
  • Kuv siv cov tab sib txawv rau kev txhais lub luag haujlwm thiab kev hu xov tooj

CODE UNDER TAB Q:

// Yooj yim ua haujlwm hu xov tooj

#suav nrog qhov tsis muaj teeb tsa teeb tsa ()

{

// I2C chaw nyob ntawm MCP23008

#txhais MCP_ADDR 0x20

// Koom nrog I2C Bus li tus tswv

Hlau.begin ();

// Pib kev sib txuas lus txuas thiab teeb tsa tus nqi

Serial.begin (9600);

// Pib kis nrog cov khoom siv ntawm I2C npav

Wire.beginTransmission (MCP_ADDR);

// Xaiv IODIR - I/O DIRECTION REGISTER sau npe

Hlau.write (0x00);

// Xaiv qhov yuav tsum tau ua haujlwm (tso tawm)

Hlau.write (0x00);

// Xaiv CONFIGURATION sau npe

Hlau.write (0x05);

// Xaiv qhov yuav tsum tau ua haujlwm

Hlau.write (0x0E);

// kawg kis

Wire.endTransmission ();

}

void lub voj ()

{

a1_on ();

ncua (1000);

a1_off ();

ncua (1000);

a2_on ();

ncua (1000);

a2_off ();

ncua (1000);

a3_on ();

ncua (1000);

a3_off ();

ncua (1000);

a4_on ();

ncua (1000);

a4_off ();

ncua (1000);

a5_on ();

ncua (1000);

a5_off ();

ncua (1000);

a6_on ();

ncua (1000);

a6_off ();

ncua (1000);

a7_on ();

ncua (1000);

a7_off ();

ncua (1000);

a8_on ();

ncua (1000);

a8_off ();

}

CODE UNDER TAB Q1:

// Tus lej no yog rau thiab tawm relay 1 ntawm lub nkoj

void a1_on () {

// Pib kis

Wire.beginTransmission (MCP_ADDR);

Hlau.write (0x09);

Hlau.write (0x01);

ncua (1800);

Wire.requestFrom (MCP_ADDR, 1);

int GPIO = Hlau.read ();

Wire.endTransmission ();

// Tso tawm rau lub vijtsam

Serial.print ("GPIO tus nqi:");

Serial.println (GPIO, BIN);

}

tsis muaj dab tsi a1_off ()

{

// Pib kis

Wire.beginTransmission (MCP_ADDR);

Hlau.write (0x09);

Hlau.write (0x00);

ncua (1800);

Wire.requestFrom (MCP_ADDR, 1);

int GPIO = Hlau.read ();

Wire.endTransmission ();

// Tso tawm rau lub vijtsam

Serial.print ("GPIO tus nqi:");

Serial.println (GPIO, BIN);

}

CODE UNDER TAB Q2:

// Tus lej no yog rau thiab tawm relay 2 ntawm lub nkoj

void a2_on () {

// Pib kis

Wire.beginTransmission (MCP_ADDR);

Hlau.write (0x09);

Hlau.write (0x02);

ncua (1800);

Wire.requestFrom (MCP_ADDR, 1);

int GPIO = Hlau.read ();

Wire.endTransmission ();

// Tso tawm rau lub vijtsam

Serial.print ("GPIO tus nqi:");

Serial.println (GPIO, BIN);

}

tsis muaj dabtsis a2_off ()

{

// Pib kis

Wire.beginTransmission (MCP_ADDR);

Hlau.write (0x09);

Hlau.write (0x00);

ncua (1800);

Wire.requestFrom (MCP_ADDR, 1);

int GPIO = Hlau.read ();

Wire.endTransmission ();

// Tso tawm rau lub vijtsam

Serial.print ("GPIO tus nqi:");

Serial.println (GPIO, BIN);

}

CODE UNDER TAB q3: // Tus lej no yog rau thiab tawm relay 3 ntawm lub nkoj

tsis muaj dab tsi a3_on ()

{

// Pib kis

Wire.beginTransmission (MCP_ADDR);

Hlau.write (0x09);

Hlau.write (0x04);

ncua (1800);

Wire.requestFrom (MCP_ADDR, 1);

int GPIO = Hlau.read ();

Wire.endTransmission ();

// Tso tawm rau lub vijtsam

Serial.print ("GPIO tus nqi:");

Serial.println (GPIO, BIN);

}

tsis muaj dab tsi a3_off ()

{

// Pib kis

Wire.beginTransmission (MCP_ADDR);

Hlau.write (0x09);

Hlau.write (0x00);

ncua (1800);

Wire.requestFrom (MCP_ADDR, 1);

int GPIO = Hlau.read ();

Wire.endTransmission ();

// Tso tawm rau lub vijtsam

Serial.print ("GPIO tus nqi:");

Serial.println (GPIO, BIN);

}

Kauj ruam 5: Programming - II

Programming - II
Programming - II

CODE UNDER TAB Q4:

// Tus lej no yog rau thiab tawm relay 4 ntawm lub nkoj

tsis muaj dab tsi a4_on ()

{

// Pib kis

Wire.beginTransmission (MCP_ADDR);

Hlau.write (0x09);

Hlau.write (0x08);

ncua (1800);

Wire.requestFrom (MCP_ADDR, 1);

int GPIO = Hlau.read ();

Wire.endTransmission ();

// Tso tawm rau lub vijtsam

Serial.print ("GPIO tus nqi:");

Serial.println (GPIO, BIN);

}

tsis muaj dab tsi a4_off ()

{

// Pib kis

Wire.beginTransmission (MCP_ADDR);

Hlau.write (0x09);

Hlau.write (0x00);

ncua (1800);

Wire.requestFrom (MCP_ADDR, 1);

int GPIO = Hlau.read ();

Wire.endTransmission ();

// Tso tawm rau lub vijtsam

Serial.print ("GPIO tus nqi:");

Serial.println (GPIO, BIN);

}

CODE UNDER TAB Q5:

// Tus lej no yog rau thiab tawm relay 5 ntawm lub nkoj

tsis muaj dab tsi a5_on ()

{

// Pib kis

Wire.beginTransmission (MCP_ADDR);

Hlau.write (0x09);

Hlau.write (0x10);

ncua (1800);

Wire.requestFrom (MCP_ADDR, 1);

int GPIO = Hlau.read ();

Wire.endTransmission ();

// Tso tawm rau lub vijtsam

Serial.print ("GPIO tus nqi:");

Serial.println (GPIO, BIN);

}

tsis muaj dabtsis a5_off ()

{

// Pib kis

Wire.beginTransmission (MCP_ADDR);

Hlau.write (0x09);

Hlau.write (0x00);

ncua (1800);

Wire.requestFrom (MCP_ADDR, 1);

int GPIO = Hlau.read ();

Wire.endTransmission ();

// Tso tawm rau lub vijtsam

Serial.print ("GPIO tus nqi:");

Serial.println (GPIO, BIN);

}

CODE UNDER TAB q6: // Tus lej no yog rau thiab tawm relay 6 ntawm lub nkoj

tsis muaj dab tsi a6_on ()

{

// Pib kis

Wire.beginTransmission (MCP_ADDR);

Hlau.write (0x09);

Hlau.write (0x20);

ncua (1800);

Wire.requestFrom (MCP_ADDR, 1);

int GPIO = Hlau.read ();

Wire.endTransmission ();

// Tso tawm rau lub vijtsam

Serial.print ("GPIO tus nqi:");

Serial.println (GPIO, BIN);

}

tsis muaj dab tsi a6_off ()

{

// Pib kis

Wire.beginTransmission (MCP_ADDR);

Hlau.write (0x09);

Hlau.write (0x00);

ncua (1800);

Wire.requestFrom (MCP_ADDR, 1);

int GPIO = Hlau.read ();

Wire.endTransmission ();

// Tso tawm rau lub vijtsam

Serial.print ("GPIO tus nqi:");

Serial.println (GPIO, BIN);

}

CODE UNDER TAB q7: // Tus lej no yog rau thiab tawm relay 7 ntawm lub nkoj

void a7_on () {

// Pib kis

Wire.beginTransmission (MCP_ADDR);

Hlau.write (0x09);

Hlau.write (0x40);

ncua (1800);

Wire.requestFrom (MCP_ADDR, 1);

int GPIO = Hlau.read ();

Wire.endTransmission ();

// Tso tawm rau lub vijtsam

Serial.print ("GPIO tus nqi:");

Serial.println (GPIO, BIN);

}

tsis muaj dab tsi a7_off ()

{

// Pib kis

Wire.beginTransmission (MCP_ADDR);

Hlau.write (0x09);

Hlau.write (0x00);

ncua (1800);

Wire.requestFrom (MCP_ADDR, 1);

int GPIO = Hlau.read ();

Wire.endTransmission ();

// Tso tawm rau lub vijtsam

Serial.print ("GPIO tus nqi:");

Serial.println (GPIO, BIN);

}

CODE UNDER TAB q8: // Tus lej no yog rau thiab tawm relay 8 ntawm lub nkoj

void a8_on () {

// Pib kis

Wire.beginTransmission (MCP_ADDR);

Hlau.write (0x09);

Hlau.write (0x80);

ncua (1800);

Wire.requestFrom (MCP_ADDR, 1);

int GPIO = Hlau.read ();

Wire.endTransmission ();

// Tso tawm rau lub vijtsam

Serial.print ("GPIO tus nqi:");

Serial.println (GPIO, BIN);

}

tsis muaj dab tsi a8_off ()

{

// Pib kis

Wire.beginTransmission (MCP_ADDR);

Hlau.write (0x09);

Hlau.write (0x00);

ncua (1800);

Wire.requestFrom (MCP_ADDR, 1);

int GPIO = Hlau.read ();

Wire.endTransmission ();

// Tso tawm rau lub vijtsam

Serial.print ("GPIO tus nqi:");

Serial.println (GPIO, BIN);

}

Kauj ruam 6: Yees duab

Yog xav paub ntxiv thov mus saib peb lub xaib:

www.dcubetechnologies.com

Pom zoo: