PCF8574: About I2C I / O Kuwedzera kweArduino

PCF8574 TI CHIP

Iwe wakanyatsonzwa nezve iyo IC PCF8574, chip inogona kutengwa zvakasiyana kana kutosimudzirwa pamo module sevamwe vazhinji Zvemagetsi zvigadzirwa kufambisa kubatana kwako neako Arduino bhodhi. Mune ino kesi, iri inowedzeredza yezvipimo uye zvinobuda zve iyo I2C bhazi.

Iwe unogona kufunga kuti Arduino yatove neyayo yakabatanidzwa I2C bhazi, uye ichokwadi. Asi PCF8574 inogona kubatsira kuwedzera iro bhazi kupfuura miganho yebhodhi rako rekuvandudza, iro rinogona kubatsira zvakanyanya kune vamwe vanogadzira vanoda zvinopfuura izvo zvinopihwa naArduino.

Chii chinonzi I2C bhazi?

Arduino UNO millis inoshanda

Zita I2C rinobva Inopindirana-Dunhu kana maseketi akapindirana. Iyo vhezheni 1.0 yakagadzirwa muna 1992 naPhilips. Zvino yechipiri 2.1 yaizouya muna2000 uye nhasi yave muyero (pa100 kbit / s, kunyangwe ichitendera kusvika ku3.4 Mbit / s kunonyanyisa) apo patent yapera muna 2006 uye inogona kushandiswa zvakasununguka.

Parizvino iri kushandiswa zvakanyanya muindasitiri yekutaurirana, uye zvakare inokosheswa zvikuru nevagadziri vemapurojekiti avo ekutaurirana akasiyana ma microcontroller nemipendero yakabatanidzwa mune imwe IC.

El I2C ibhasi inonyatso kuzivikanwa kubva kune serial kutaurirana. Iyo inoshandisa yakawiriranwa yekutaurirana protocol ine chete 2 chiteshi (kune chetatu, asi chakabatanidzwa kune rejisheni kana GND), muchokwadi icho chinozivikanwawo seTWI ​​(Two Wire Interface):

  • Imwe yeawa (SCL).
  • Zvimwe zve data (SDA).
Ose ari maviri akavhurika anodhiraina CMOS kubatana uye anoda ekudhonza-kumusoro resistors. Zvakare, kana chimwe chishandiso chikatambidza 0 uye chimwe 1, panogona kunge paine matambudziko, saka mutsetse unogara wakaiswa ku1 (yakakwira nhanho) uye zvishandiso zvinogara zvichitumira 0 (yakaderera nhanho).

Izvi zvinoreva kuti iyo tenzi nemuranda ivo vanotumira data pamusoro peiyo imwechete tambo kana track, iyo inodzorwa neyekutanga iyo inogadzira iyo wachi chiratidzo. Chimwe nechimwe chezvigadzirwa zvepamberi zvakabatana nebhazi reI2C zvichave nekero yakasarudzika yakapihwa, kuitira kutungamira kufambisa. Asi hazvidi kuti mudzidzisi agare akafanana (multi-mudzidzisi), anogara ari iye anotangisa kuendesa.

Sezvandatove ndatsanangura muchinyorwa pamusoro Arduino I2C Ini ndamboreva pakutanga, bhodhi rega rega rine aya maI2C ekubatana munzvimbo dzakasiyana. Icho chinhu chaunofanirwa kuchengeta mundangariro kuti ukwanise kuchishandisa nemazvo mune yega vhezheni yeplate:

  • Arduino UNO: SDA iri muA4 uye SCK muA5
  • Arduino Nano: zvakafanana neyekare.
  • Arduino Mini Pro: zvakafanana.
  • Arduino Mega: SDA iri pini 20 uye SCK pa21.
  • Mamwe ruzivo nezve mahwendefa.

Unotoziva kuti iwe unogona kushandisa iyo I2C kune ako masiketi nyore, sezvo iyo Wire.h raibhurari nemabasa akasiyana siyana eiyi serial kutaurirana:

  • tanga (): tanga raibhurari yeWire uye utaure kana iri tenzi kana muranda
  • chikumbiroFrom (): inoshandiswa nashe kukumbira data kubva kumuranda.
  • tanga Kutumira (): tanga kutapurirana nemuranda.
  • EndTransmission (): kupera kupera.
  • nyora ()- Nyora data kubva kumuranda mukupindura kuchikumbiro kubva kuna tenzi, kana iwe unogona kumisikidza tenzi kutumira.
  • inowanikwa (): ichadzosera iyo nhamba yemabheti kuverenga.
  • verenga (): verenga byte inopfuudzwa kubva kumuranda kuenda kuna tenzi kana zvinopesana.
  • onReceive ()Inodaidza basa kana muranda agamuchira kufambiswa kubva kuna tenzi.
  • onRequest (): Inodaidza basa kana muranda achikumbira data kubva kuna tenzi.

Para mamwe mashoko nezve Arduino kuronga uye mabasa iwe unogona kurodha yedu PDF dzidziso.

Chii chinonzi PCF8574?

PCF8574 module

Iyo PCF8574 ndeye I2C bhazi zvigadzirwa zvemagetsi uye zvinobuda (I / O) expander. Inogona kugadzirwa nevagadziri vakasiyana siyana, pamusoro pekuve iine maIC nemamojuru. Chero zvazvingaitika, zvinonyanya kukosha kuti ubatanidze kune yako Arduino bhodhi uye uve nekwanisi yekudzora akawanda madhijidhi kupfuura ayo mamaboard anotendera.

El PCF8574 pinout yakapusa, nekuti inongosanganisira 8 mapini quasidirectional (P0-P7 apo machipisi ekutaurirana akabatana), uye kune rimwe divi une SDA uye SCL iyo iwe yaunofanirwa kubatanidza kuArduino bhodhi, pamwe neVCC neGND kuti upe simba module. Uye usakanganwe matatu matatu ekutaura pini A0, A1, A2 kusarudza kuti ndeapi emidziyo kutaurirana kwakanangidzirwa ...

Mufananidzo wePCF8574

Owens zvimwe zvinhu kuti iwe uzive:

  • Kubatana kwayo, kuve yakavhurika mvura, kunogona kudaro yakashandisa zvese zviri zviviri zvekubuda uye zvinobuda.
  • La yepamusoro yazvino iri 25mA painoshanda senge inobuda (kunyura, kana iyezvino ichiyerera yakananga PCF8574) uye 300 µA (tsime, yazvino kuyerera kubva paPCF8574).
  • La kunetsana magetsi i2.5 uye 6v. Iyo yekumira-nekushandisa yakanyanya kuderera, chete 10 µA.
  • Zvese zvinobuda vane latches, kuchengetedza nyika pasina chikonzero chezviito zvekunze. Iwe unongofanirwa kuita kana iwe uchida kuchinja nyika.
  • Unogona kuwana zvisere nzira dzinobvira, Ndokunge, anosvika pamasere masere ekutaurirana kana kushandisa 8 module kuti awedzere kusvika pamakumi matanhatu namatanhatu. Kero (pini A8, A64, A0) ichave iri:
    • 000: kero 0x20
    • 001: kero 0x21
    • 010: kero 0x22
    • 011: kero 0x23
    • 100: kero 0x24
    • 101: kero 0x25
    • 110: kero 0x26
    • 111: kero 0x27
  • Kubvuma kukanganisa (INT) netambo yakakosha kuti uone data pasina kugara uchiongorora.

Kubatanidzwa naArduino

Screenshot yaArduino IDE

Iko kubatana neArduino kuri nyore, iwe unongofanirwa kubatanidza Vcc ne 5v pini yeArduino bhodhi, uye GND neGND yeArduino. Kune rimwe divi, pini dzePCF8574 SDA uye SCL module inogona kuva batanidza nemapini 14 (A5 SCL) uye 15 (A4 SDA). Izvo chete zvaizotanga kushanda, zviri pachena kuti iwe unogona kushandisa iyo Px kubatanidza zvishandiso zvaunoda kutaura ...

Ipapo kwaizoshaikwa chete tanga nemuenzaniso sketch muArduino IDE. Unogona kuzviita pasina kushandisa raibhurari yekuwedzera senge ...

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

Sekuisa:

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

Kana zvakare shandisa maraibhurari, senge PCF8574 yaunogona download here uye shandisa kodhi yakafanana neiyi kubva pamuenzaniso pachawo unouya pamwe neraibhurari iyi:

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


Izvo zviri muchinyorwa zvinoomerera pamisimboti yedu ye tsika dzekunyora. Kuti utaure chikanganiso tinya pano.

Iva wekutanga kutaura

Siya yako yekutaura

Your kero e havazobvumirwi ichibudiswa. Raida minda anozivikanwa ne *

*

*

  1. Inotarisira iyo data: Miguel Ángel Gatón
  2. Chinangwa cheiyo data: Kudzora SPAM, manejimendi manejimendi.
  3. Legitimation: Kubvuma kwako
  4. Kutaurirana kwedata
  5. Dhata yekuchengetedza: Dhatabhesi inobatwa neOccentus Networks (EU)
  6. Kodzero: Panguva ipi neipi iwe unogona kudzora, kupora uye kudzima ruzivo rwako