I-PCF8574: Mayelana ne-I2C I / O Expander ye-Arduino

PCF8574 TI CHIP

Ngokuqinisekile uzwile ngefayela le- Incazelo: IC PCF8574, i-chip engathengwa ngokuhlukile noma isivele ifakwe kumodyuli njengabanye abaningi Izingxenye ze-elekthronikhi ukwenza lula ukuhlanganiswa kwakho nebhodi lakho le-Arduino. Kulokhu, kungukukhishwa kokufakwayo nemiphumela ye- ibhasi le-I2C.

Ungase ucabange ukuthi i-Arduino isivele inayo eyayo I-I2C ibhasi elihlanganisiwe, futhi kuyiqiniso. Kepha i-PCF8574 ingasiza ukunweba lelo bhasi ngale kwemikhawulo yebhodi lakho lokuthuthuka, elingaba usizo olukhulu kwabanye abenzi abadinga okungaphezu kwalokho okunikezwa yi-Arduino.

Liyini ibhasi le-I2C?

Arduino UNO imisebenzi yama-millis

Igama I2C livela ku- Isekethe Ehlanganisiwe noma amasekethe ahlanganisiwe. Inguqulo yayo engu-1.0 yadalwa ngo-1992 nguPhilips. Bese kuthi u-2.1 wesibili afike ngo-2000 futhi namuhla sekuyinto ejwayelekile (ngama-100 kbit / s, yize ivumela kufika ku-3.4 Mbit / s esiphezulu) lapho ilungelo lobunikazi liphela ngo-2006 futhi lingasetshenziswa ngokukhululeka.

Njengamanje isetshenziswa kabanzi embonini yokuxhumana, futhi futhi baziswa kakhulu abenzi bamaphrojekthi abo wokuxhumana ngama-microcontroller ahlukahlukene nemikhawulo ehlanganiswe ku-IC eyodwa.

El I2C ibhasi kwaziwa kahle ngokuxhumana okuyi-serial. Isebenzisa inqubo yokuxhumana ehambisanayo eneziteshi ezi-2 kuphela (kunesithathu, kepha ihlanganiswe nesethenjwa noma i-GND), empeleni yaziwa nangokuthi yi-TWI (Two Wire Interface):

  • Eyodwa yewashi (SCL).
  • Okunye kwedatha (i-SDA).
Kokubili ukuxhumana okuvulekile kwe-CMOS futhi kudinga iziphikisi zokudonsa. Futhi, uma idivaysi eyodwa idlulisa i-0 bese enye ingu-1, kungaba nezinkinga, ngakho-ke ulayini uhlala usethelwe ku-1 (izinga eliphakeme) futhi amadivayisi ahlala edlulisa u-0 (izinga eliphansi).

Lokho kusho ukuthi inkosi nesigqila bathumela idatha ngentambo efanayo noma ithrekhi, elawulwa eyokuqala eyenza isignali yewashi. Idivayisi ngayinye yomngcele exhunywe ebhasini le-I2C izoba nekheli eliyingqayizivele elinikezwe, ukuqondisa ukuhanjiswa. Kepha akudingekile ukuthi uthisha ahlale efanayo (othisha abaningi), njalo nguye oqala ukudluliswa.

Njengoba ngichazile vele endatshaneni ku I-Arduino I2C Ngikhombisile phambilini, ibhodi ngalinye linokuxhumana kwe-I2C ezindaweni ezahlukahlukene. Kuyinto okufanele uyikhumbule ukuze ukwazi ukuyisebenzisa kahle enguqulweni ngayinye yepuleti:

  • Arduino UNO: I-SDA iku-A4 ne-SCK iku-A5
  • U-Arduino Nano: kufana nokwedlule.
  • I-Arduino Mini Pro: okufanayo.
  • I-Arduino Mega: I-SDA iku-pin 20 ne-SCK iku-21.
  • Imininingwane engaphezulu ngamacwecwe.

Usuvele uyazi ukuthi ungasebenzisa i-I2C ngemidwebo yakho kalula, ngoba Umtapo wolwazi weWire.h ngemisebenzi eyahlukahlukene yalokhu ukuxhumana okulandelayo:

  • qala (): qala umtapo wolwazi we-Wire bese ucacisa uma uyinkosi noma uyisigqila
  • isiceloFrom (): kusetshenziswe inkosi ukucela idatha encekwini.
  • startTransmission (): qala ukudluliswa ngesigqila.
  • EndTransmission (): ukudluliswa kokuphela.
  • bhala ()- Bhala idatha kusuka esigqileni uphendule isicelo esivela enkosini, noma ungangena emgqeni wokudluliselwa kwenkosi.
  • kuyatholakala (): izobuyisa inani lama-byte azofundwa.
  • funda (): funda i-byte edluliselwe isuka esigqileni iye enkosini noma okuphambene nalokho.
  • onReceive ()Ibiza umsebenzi lapho isigqila sithola ukudluliswa okuvela enkosini.
  • onRequest (): Kubiza umsebenzi lapho isigqila sicela idatha kusuka enkosini.

para ulwazi oluthe xaxa mayelana nohlelo lwe-Arduino nemisebenzi ongayilanda Isifundo se-PDF.

Yini i-PCF8574?

PCF8574 module

I-PCF8574 iyi- Okokufaka nemiphumela yebhasi ledijithali ye-I2C (I / O) expander. Ingakhiqizwa ngabakhiqizi abahlukahlukene, ngaphezu kokuthi itholakale kuma-IC nakumamojula. Kunoma ikuphi, kuyasiza kakhulu ukuyixhuma ebhodini lakho le-Arduino futhi ube namandla okulawula amadivayisi amaningi kune-motherboard evumayo.

El I-PCF8574 pinout ilula, ngoba ifaka phakathi kuphela Amaphini we-8 i-quasi-directional (P0-P7 lapho ama-chips wokuxhumana axhunyiwe khona), kanti ngakolunye uhlangothi une-SDA ne-SCL okufanele uyixhume ebhodini le-Arduino, kanye ne-VCC ne-GND ukuze uphinde unike amandla imodyuli. Futhi ungakhohlwa izikhonkwane ezintathu zokubhekana no-A0, A1, A2 ukukhetha ukuthi iyiphi ukuxhumana ukuxhumana okuqondiswe ...

I-PCF8574 pinout

Own nezinye izici okufanele wazi:

  • Ukuxhumana kwayo, kungaba ngumsele ovulekile, kungaba njalo kusetshenziswe kokubili njengokufakwayo nemiphumela.
  • La inani eliphakeme lamanje kungama-25mA lapho isebenza njengokukhiphayo (isinki, lapho okwamanje kugeleza kubheke ku-PCF8574) naku-300 µA (umthombo, ukugeleza kwamanje kusuka ku-PCF8574).
  • La Ukushuba kwesimo phakathi ugesi u-2.5 no-6v. Ukusetshenziswa kokuma kuphansi kakhulu, yi-10 onlyA kuphela.
  • Yonke imiphumela babe nama-latches, ukugcina umbuso ngaphandle kwesidingo sezenzo zangaphandle. Kufanele wenze kuphela lapho ufuna ukuguqula isimo.
  • Ungathola i-8 izinkomba, okungukuthi, kufika kumadivayisi ayi-8 ukuxhumana noma ukusebenzisa amamojula ayi-8 ukuyikhulisa ifinyelela kumadivayisi angama-64. Amakheli (izikhonkwane A0, A1, A2) kuzoba:
    • 000: ikheli 0x20
    • 001: ikheli 0x21
    • 010: ikheli 0x22
    • 011: ikheli 0x23
    • 100: ikheli 0x24
    • 101: ikheli 0x25
    • 110: ikheli 0x26
    • 111: ikheli 0x27
  • Ukuvuma ukuphazamiseka (INT) ngomugqa okhethekile wokuthola idatha ngaphandle kokuqapha njalo.

Ukuhlanganiswa ne-Arduino

Isithombe se-Arduino IDE

Ukuxhumeka ne-Arduino kulula kakhulu, kufanele nje uxhume i-Vcc ngophini we-5v webhodi le-Arduino, ne-GND ne-GND ye-Arduino. Ngakolunye uhlangothi, izikhonkwane ze-PCF8574 SDA ne-SCL module zingaba njalo xhuma ngezikhonkwane 14 (A5 SCL) no-15 (A4 SDA). Ngalokho kuphela kuzoqala ukusebenza, kusobala ukuthi ungasebenzisa i-Px ukuxhuma amadivayisi ofuna ukuxhumana ...

Lapho-ke bekuyobe kulahlekile kuphela qala ngomdwebo wesibonelo ku-Arduino IDE. Ungakwenza ngaphandle kokusebenzisa umtapo wezincwadi owengeziwe njenge ...

#include <Wire.h>
 
const int address = 0x38;
 
void setup()
{
   Wire.begin();
   Serial.begin(9600);
}
 
void loop()
{
   for (short channel = 0; channel < 8; channel++)
   {
      // Escribir dato en cada uno de los 8 canales
      Wire.beginTransmission(address);
      Wire.write(~(1 << channel));
      Wire.endTransmission();
      
      // Lee dato del canal
      delay(500);
   }
}

Njengokufaka:

#include <Wire.h>
 
const int address = 0x38;
 
void setup()
{
   Wire.begin();
   Serial.begin(9600);
}
 
void loop()
{
   short channel = 1;
   byte value = 0;
 
   // Leer el dato del canal
   Wire.requestFrom(pcfAddress, 1 << channel);
   if (Wire.available())
   {
      value = Wire.read();
   }
   Wire.endTransmission();
 
   // Mostrar el valor leido por el monitor serie
   Serial.println(value);
}

Noma futhi sebenzisa imitapo yolwazi, njengePCF8574 ongakwazi landa lapha bese usebenzisa ikhodi efana nalena kusuka esibonelweni uqobo eza nalomtapo wezincwadi:

#include <Wire.h>
#include "PCF8574.h"
 
PCF8574 expander;
 
void setup() 
{
  Serial.begin(9600);
  
  expander.begin(0x20);
  
  /* Setup some PCF8574 pins for demo */
  expander.pinMode(0, OUTPUT);
  expander.pinMode(1, OUTPUT);
  expander.pinMode(2, OUTPUT);
  expander.pinMode(3, INPUT_PULLUP);
 
  /* Blink hardware LED for debug */
  digitalWrite(13, HIGH);  
  
  /* Toggle PCF8574 output 0 for demo */
  expander.toggle();
  
  /* Blink hardware LED for debug */
  digitalWrite(13, LOW);
}
 
 
 
void loop() 
{
}


Yiba ngowokuqala ukuphawula

Shiya umbono wakho

Ikheli lakho le ngeke ishicilelwe. Ezidingekayo ibhalwe nge *

*

*

  1. Ubhekele imininingwane: Miguel Ángel Gatón
  2. Inhloso yedatha: Lawula Ugaxekile, ukuphathwa kwamazwana.
  3. Ukusemthethweni: Imvume yakho
  4. Ukuxhumana kwemininingwane: Imininingwane ngeke idluliselwe kubantu besithathu ngaphandle kwesibopho esisemthethweni.
  5. Isitoreji sedatha: Idatabase ebanjwe yi-Occentus Networks (EU)
  6. Amalungelo: Nganoma yisiphi isikhathi ungakhawulela, uthole futhi ususe imininingwane yakho.