PCF8574: Game da I2C I / O Expander don Arduino

PCF8574 TI CHIP

Lallai kun ji labarin IC PCF8574, guntu wanda za'a iya siyan shi daban ko an riga an ɗora shi a kan modulu kamar sauran mutane Kayan lantarki don sauƙaƙe haɗin ku tare da kwamitinku na Arduino. A wannan yanayin, tsokaci ne na abubuwan shigarwa da kayan haɓaka don bas din I2C.

Kuna iya tunanin cewa Arduino ya riga ya sami nasa hadedde I2C bas, kuma gaskiyane. Amma PCF8574 na iya taimakawa wajen faɗaɗa wannan bas ɗin sama da iyakar hukumar ci gaban ku, wanda zai iya zama babban taimako ga wasu masu ƙirar da ke buƙatar fiye da abin da Arduino ke samarwa.

Menene motar I2C?

Arduino UNO ayyuka na millis

Sunan I2C ya fito ne daga Hadadden Maɗaukaki ko hanyoyin hade-hade. An kirkiro sigar ta 1.0 a shekarar 1992 ta hanyar Philips. Sannan 2.1 na biyu zai zo a 2000 kuma a yau ya zama mizanin (a 100 kbit / s, kodayake yana ba da izini har zuwa 3.4 Mbit / s matsakaicin) lokacin da haƙƙin mallaka ya ƙare a 2006 kuma za a iya amfani da shi kyauta.

A halin yanzu ana amfani dashi sosai a cikin masana'antar don sadarwa.

El I2C bas ne sanannun daga sadarwa serial. Yana amfani da yarjejeniya ta hanyar sadarwa tare da tashoshi 2 kawai (akwai na uku, amma an haɗa shi da tunani ko GND), a zahiri ana kiransa TWI (Hanyar Waya Biyu):

  • Daya na agogo (SCL).
  • Sauran don bayanai (SDA).
Dukansu suna buɗe hanyoyin haɗin CMOS kuma suna buƙatar tsayayya-up resistors. Hakanan, idan wata na'urar ta watsa 0 wani kuma na 1, za'a iya samun matsala, saboda haka a kowane lokaci layin na saita zuwa 1 (babban matakin) kuma na'urori koyaushe suna watsa 0 (matakin ƙasa).

Wannan yana nuna cewa maigida da bawa suna aika bayanai ta kan waya ɗaya ko waƙa, wanda farkon yake sarrafawa wanda ke haifar da siginar agogo. Kowane ɗayan na'urorin da ke haɗe da motar I2C zai sami adireshin da aka keɓance da shi, don jagorantar watsawa. Amma ba lallai ba ne cewa malami koyaushe iri ɗaya ne (malami ne da yawa), koyaushe shi ne yake fara canja wurin.

Kamar yadda na riga nayi bayani a cikin labarin akan Arduino I2C Na ambata a baya, kowane kwamiti yana da waɗannan haɗin I2C a wurare daban-daban. Abu ne da dole ne ku kiyaye don iya amfani dashi da kyau a cikin kowane nau'in farantin:

  • Arduino UNO: SDA yana cikin A4 da SCK a cikin A5
  • Arduino Nano: daidai yake da na baya.
  • Arduino Mini Pro: daidai.
  • Arduino Mega: SDA yana kan fil 20 da SCK akan 21.
  • Informationarin bayani game da faranti.

Kun riga kun san cewa zaku iya amfani da I2C don zane-zanen ku a sauƙaƙe, tunda Wajen karatu na Wire.h tare da ayyuka daban-daban don wannan sadarwar ta serial:

  • fara (): fara laburaren Waya ka ayyana idan mai gida ne ko bawa
  • nemaDaga (): amfani da maigidan don neman bayanai daga bawan.
  • Farawa (): fara watsawa tare da bawa.
  • karshen watsawa (): karshen watsawa.
  • rubuta ()- Rubuta bayanai daga bawa domin amsar fatawar daga maigidan, ko kuma zaka iya yin jerin gwano wurin watsa maigidan.
  • akwai (): zai dawo da adadin baiti ya karanta.
  • karanta (): karanta baiti da aka watsa daga bawa zuwa ga maigida ko akasin haka.
  • Karba (): Kira aiki yayin da bawa ya karɓi watsa daga maigidan.
  • Tambaya (): Kira aiki yayin da bawa ya nemi bayanai daga maigidan.

para ƙarin bayani game da shirye-shiryen Arduino da ayyuka zaku iya sauke namu Koyarwar PDF.

Menene PCF8574?

PCF8574 module

PCF8574 shine Abubuwan shigar dijital na I2C da kayan aiki (I / O) mai fadadawa. Ana iya ƙera shi ta masana'antun daban-daban, ban da samun sa a cikin ICs da kayayyaki. A kowane hali, yana da amfani sosai don haɗa shi da allon Arduino ɗinka kuma yana da ƙarfin sarrafa na'urori da yawa fiye da yadda mahaɗan yake ba da dama.

El Kwamfutar PCF8574 mai sauki ne, tunda kawai ya hada da 8 pines madaidaiciya-kwatance (P0-P7 inda kwakwalwan don sadarwa zasu haɗu), kuma a gefe guda kuna da SDA da SCL waɗanda dole ne ku haɗi da kwamitin Arduino, da VCC da GND don kuma ba da ƙarfin injin ɗin. Kuma kar a manta da alamomin adireshi guda uku A0, A1, A2 don zaɓar wanne daga cikin na'urorin da sadarwa ke fuskantar ...

Kwamfutar PCF8574

Mallaka sauran fasali cewa ya kamata ka sani:

  • Haɗin sa, kasancewar buɗe magudanan ruwa, na iya zama anyi amfani dashi azaman kayan shigarwa da kayan aiki.
  • La ganiya halin yanzu 25mA ne lokacin da yake aiki azaman fitarwa (nutsewa, lokacin da abin yake gudana zuwa PCF8574) da 300 (A (tushe, mai gudana daga PCF8574).
  • La damuwa samar da wuta shine 2.5 da 6v. Amfanin tsaye yana da ƙasa ƙwarai, 10 µA kawai.
  • Duk abinda aka samu yi latches, don kula da jihar ba tare da buƙatar ayyukan waje ba. Dole ne kawai kuyi aiki lokacin da kuke son canza jihar.
  • Zaka iya samun 8 yiwu kwatance, ma'ana, har zuwa na'urori 8 don sadarwa tare ko amfani da kayayyaki 8 don fadada shi har zuwa na'urori 64. Adiresoshin (fil A0, A1, A2) zasu zama:
    • 000: adireshin 0x20
    • 001: adireshin 0x21
    • 010: adireshin 0x22
    • 011: adireshin 0x23
    • 100: adireshin 0x24
    • 101: adireshin 0x25
    • 110: adireshin 0x26
    • 111: adireshin 0x27
  • Yarda katsewa (INT) ta layi na musamman don gano bayanai ba tare da saka idanu akai-akai ba.

Haɗuwa tare da Arduino

Screenshot na Arduino IDE

Hadin kai da Arduino abu ne mai sauki, kawai sai ka hada Vcc da pin din 5v na hukumar Arduino, da GND tare da GND na Arduino. A gefe guda, fil na PCF8574 SDA da SCL module na iya zama haɗi tare da fil 14 (A5 SCL) da 15 (A4 SDA). Tare da wannan kawai zai fara aiki, a bayyane zaka iya amfani da Px don haɗa na'urorin da kake son sadarwa ...

Sannan zai bata ne kawai fara da misali zane a cikin Arduino IDE. Kuna iya yin shi ba tare da amfani da ƙarin ɗakin karatu ba kamar ...

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

Kamar yadda labari:

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

Ko kuma amfani da dakunan karatu, kamar PCF8574 da zaku iya download a nan kuma yi amfani da lambar kama da wannan daga misalin kanta wanda yazo tare da wannan laburaren:

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


Abubuwan da ke cikin labarin suna bin ka'idodinmu na ka'idojin edita. Don yin rahoton kuskure danna a nan.

Kasance na farko don yin sharhi

Bar tsokaci

Your email address ba za a buga. Bukata filayen suna alama da *

*

*

  1. Mai alhakin bayanan: Miguel Ángel Gatón
  2. Dalilin bayanan: Gudanar da SPAM, gudanar da sharhi.
  3. Halacci: Yarda da yarda
  4. Sadarwar bayanan: Ba za a sanar da wasu bayanan ga wasu kamfanoni ba sai ta hanyar wajibcin doka.
  5. Ajiye bayanai: Bayanin yanar gizo wanda Occentus Networks (EU) suka dauki nauyi
  6. Hakkoki: A kowane lokaci zaka iyakance, dawo da share bayanan ka.