PCF8574: Mabapi le I2C I / O Expander bakeng sa Arduino

PCF8574 TI CHIP

Ka sebele u utloile ka IC PCF8574, chip e ka rekiloeng ka thoko kapa e se e kentsoe mojuleng joalo ka tse ling tse ngata Lisebelisoa tsa elektroniki ho tsamaisa kopanyo ea hau le boto ea hau ea Arduino. Maemong ana, ke extender ea lisebelisoa le litholoana tsa bese ea I2C.

U kanna oa nahana hore Arduino e se e ntse e na le eona e kopantsoeng I2C bese, 'me ke' nete. Empa PCF8574 e ka thusa ho holisa bese eo ho feta meeli ea boto ea hau ea nts'etsopele, e ka bang thuso e kholo ho baetsi ba bang ba hlokang ho fetang feela seo Arduino e fanang ka sona.

Bese ea I2C ke eng?

Arduino UNO mesebetsi ea millis

Lebitso I2C le tsoa ho Potoloho e Kopaneng kapa lipotoloho tse kopaneng. Mofuta oa eona oa 1.0 o thehiloe ka 1992 ke Philips. Eaba 2.1 ea bobeli e tla ka 2000 mme kajeno e fetohile standard (ho 100 kbit / s, leha e lumella ho fihla ho 3.4 Mbit / s maximum) ha patent e felile ka 2006 mme e ka sebelisoa ka bolokolohi.

Hajoale e sebelisoa haholo indastering bakeng sa puisano, hape e ananeloa haholo ke baetsi bakeng sa merero ea bona ea ho buisana le li-microcontroller tse fapaneng le lisebelisoa tse kopaneng ho IC e le 'ngoe.

El I2C ke bese puisano e tsebahalang ea serial. E sebelisa protocol ea puisano e lumellanang e nang le liteishene tse 2 feela (ho na le karolo ea boraro, empa e hokahane le litšupiso kapa GND), ha e le hantle e tsejoa e le TWI (Two Wire Interface):

  • E 'ngoe bakeng sa oache (SCL).
  • Tse ling tsa data (SDA).
Ka bobeli ke likhokahano tse bulehileng tsa drain tsa CMOS 'me li hloka lihanyetsi tse hulang. Hape, haeba sesebelisoa se seng se fetisa 0 'me se seng e le 1, ho ka ba le mathata, ke ka lebaka leo mohala o lulang o behiloe ho 1 (boemo bo phahameng) mme lisebelisoa li lula li fetisa 0 (boemo bo tlase).

Seo se bolela hore monghali le lekhoba ba romella data ka thapo e le 'ngoe kapa pina, e laoloang ke ea pele eo e leng eona e hlahisang lets'oao la oache. Sesebelisoa se seng le se seng se hokahaneng le bese ea I2C se tla ba le aterese e ikhethang e abetsoeng, e le ho tsamaisa phetisetso. Empa ha ho hlokahale hore monghali o lula a tšoana (multi-master), ke eena ea qalisang phetiso.

Joalokaha ke se ke hlalositse sengoloeng se mabapi le Arduino I2C Ke boletse pejana, boto e ngoe le e ngoe e na le lihokelo tsa I2C libakeng tse fapaneng. Ke ntho eo u tlamehang ho e boloka kelellong ea hau ho tseba ho e sebelisa hantle phetolelong ka 'ngoe ea poleiti:

U se u ntse u tseba hore u ka sebelisa I2C bakeng sa litšoantšo tsa hau habonolo, kaha file ea Laebrari ea Wire.h ka mesebetsi e fapaneng bakeng sa puisano ena ea serial:

  • qala (): qala laeborari ea terata 'me u hlalose hore na e hloahloa kapa ke lekhoba
  • kopoFrom (): e sebelisitsoeng ke monghali ho kopa data ho lekhoba.
  • qala Phetiso (): qala phetiso ka lekhoba.
  • Phetiso (): phetiso ea ho qetela.
  • ngola ()- Ngola data ho tsoa ho lekhoba ho arabela kopo ea mong'a lona, ​​kapa u ka ema moleng oa phetisetso ea monghali.
  • fumaneha (): e tla khutlisa palo ea li-byte ho e bala.
  • bala (): bala byte e fetisitsoeng ho tloha lekhoba ho ea ho monghali kapa ka tsela e fapaneng.
  • amohela ()E bitsa mosebetsi ha lekhoba le amohela phetiso ho tsoa ho mong'a lona.
  • onRequest ()E bitsa mosebetsi ha lekhoba le kopa data ho mong'a lona.

le para tlhahisoleseding e eketsehileng mabapi le lenaneo la Arduino le mesebetsi eo u ka e jarollang Thupelo ea PDF.

PCF8574 ke eng?

Mojule oa PCF8574

PCF8574 ke Lits'ebetso le lipehelo tsa libese tsa I2C (I / O) li atolosoa. E ka etsoa ke bahlahisi ba fapaneng, ntle le ho ba le eona ho li-IC le li-module. Ho sa tsotellehe boemo leha e le bofe, ho molemo haholo ho e hokahanya le boto ea hau ea Arduino mme o na le bokhoni ba ho laola lisebelisoa tse ngata ho feta tseo board ea mama e lumellang.

El Tlhaloso ea PCF8574 E bonolo, hobane e kenyelletsa feela Lipilisi tsa 8 quasi-directional (P0-P7 moo li-chips tse hokahanang li hokahane), 'me ka lehlakoreng le leng u na le SDA le SCL tseo u tlamehang ho li hokahanya le board ea Arduino, hammoho le VCC le GND ho matlafatsa module. Mme o seke oa lebala lithakhisa tse tharo tsa ho bua le A0, A1, A2 ho khetha lisebelisoa tseo puisano e lebisitsoeng ho tsona ...

Tlhaloso ea PCF8574

Bong likarolo tse ling hore o tsebe:

  • Litšebelisano tsa eona, e ka ba metsi a bulehileng, e ka ba e sebelisitsoe ka bobeli e le lisebelisoa le litholoana.
  • La tlhoro ea morao-rao ke 25mA ha e sebetsa e le tlhahiso (teba, ha hona joale e phallela ho PCF8574) le 300 µA (mohloli, hona joale o phalla ho tloha PCF8574).
  • La tsitsipano phepelo ea motlakase ke 2.5 le 6v. Ts'ebeliso ea thekiso e tlase haholo, ke 10 µA feela.
  • Liphetho tsohle na le latches, ho boloka mmuso ntle le tlhoko ea liketso tsa kantle. O tlameha feela ho nka khato ha o batla ho fetola mmuso.
  • U ka fumana tse 8 litaelo tse ka bang teng, ke hore, ho fihlela ho lisebelisoa tse 8 ho buisana le kapa ho sebelisa li-module tsa 8 ho e holisa ho fihlela lisebelisoa tse 64. Liaterese (lithakhisa A0, A1, A2) e tla ba:
    • 000: aterese 0x20
    • 001: aterese 0x21
    • 010: aterese 0x22
    • 011: aterese 0x23
    • 100: aterese 0x24
    • 101: aterese 0x25
    • 110: aterese 0x26
    • 111: aterese 0x27
  • E amohela tšitiso (INT) ka mohala o ikhethileng oa ho fumana lintlha ntle le ho lekola khafetsa.

Tšebelisano le Arduino

Setšoantšo sa Arduino IDE

Khokahano le Arduino e bonolo haholo, o tlameha feela ho hokela Vcc le phini ea 5v ea boto ea Arduino, le GND le GND ea Arduino. Ka lehlakoreng le leng, lithakhisa tsa module ea PCF8574 SDA le SCL e ka ba ikopanya le lithakhisa 14 (A5 SCL) le 15 (A4 SDA). Feela ka hore e tla qala ho sebetsa, ho hlakile hore o ka sebelisa Px ho hokela lisebelisoa tseo u batlang ho buisana le tsona ...

Joale e ne e tla ba sieo feela qala ka mohlala sketch ka Arduino IDE. U ka e etsa ntle le ho sebelisa laebrari e ngoe e joalo ka ...

#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);
   }
}

E le kenyelletso:

#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);
}

Kapa hape sebelisa lilaebrari, joalo ka PCF8574 eo u ka e khonang kenya mona 'me u sebelise khoutu e ts'oanang le ena ho tsoa mohlaleng ka booona o tlang le laeborari ena:

#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() 
{
}


Litaba tsa sengoloa sena li latela melao-motheo ea rona ea melao ea boitšoaro ea bongoli. Ho tlaleha phoso tlanya mona.

E-ba oa pele ho fana ka maikutlo

Siea maikutlo a hau

aterese ya hao ya imeile ke ke ho phatlalatswa. masimo a hlokahala a tšoailoe ka *

*

*

  1. E ikarabella bakeng sa data: Miguel Ángel Gatón
  2. Morero oa data: Laola SPAM, tsamaiso ea maikutlo.
  3. Molao: Tumello ea hau
  4. Puisano ea data: Lintlha li ke ke tsa tsebisoa batho ba boraro ntle le ka tlamo ea molao.
  5. Polokelo ea data: Database e hapiloeng ke Occentus Networks (EU)
  6. Litokelo: Nako efe kapa efe o ka fokotsa, oa hlaphoheloa mme oa hlakola tlhaiso-leseling ea hau.