PCF8574: No I2C I / ʻO Expander no Arduino

ʻO PCF8574 TI CHIP

Lohe nō ʻoe i nā IC PCF8574, kahi puʻukū i hiki ke kūʻai ʻokoʻa a kau ʻia paha ma kahi module e like me nā poʻe ʻē aʻe Nā mea uila e kōkua i kāu hoʻohui me kāu papa Arduino. I kēia hihia, he mea hoʻonui o nā mea hoʻokomo a me nā huahana no ke kaʻa ʻōhua I2C.

E noʻonoʻo paha ua loaʻa iā Arduino kāna iho hoʻohui pahi I2C, a he ʻoiaʻiʻo. Akā hiki i ka PCF8574 ke kōkua i ka hoʻolōʻihi ʻana i kēlā bus ma ʻō aku o nā palena o kāu papa hoʻomohala, i hiki ke kōkua nui i kekahi mau mea hana e pono ai ma mua o ka mea i hāʻawi ʻia e Arduino.

He aha ke kaʻa ʻōhua I2C?

Arduino UNO millis hana

Noʻu ka inoa I2C Kaapuni Pākuʻi waena aiʻole nā ​​kaapuni hoʻohui waena. Ua hoʻokumu ʻia kāna mana 1.0 i 1992 e Philips. A laila e hiki mai kahi lua 2.1 i 2000 a i kēia lā ua lilo ia i kūlana (ma 100 kbit / s, ʻoiai e ʻae ʻia a hiki i ka 3.4 Mbit / s ka nui) ke pau ka patent ma 2006 a hiki ke hoʻohana manuahi.

I kēia manawa ua hoʻohana ākea ia i ka ʻoihana no ke kamaʻilio, a mahalo nui ʻia e nā mea hana no kā lākou papahana e kamaʻilio i nā microcontrollers ʻokoʻa a me nā peripherals i hoʻohui ʻia i hoʻokahi IC.

El He kaʻa ʻo I2C kaulana loa mai ke kamaʻilio pūkaʻina. Hoʻohana ia i kahi protocol kamaʻilio pū me nā kahawai 2 wale nō (aia kahi hapakolu, akā hoʻopili ʻia ia i kahi kūmole a i ʻole GND), ʻo ka ʻoiaʻiʻo ua ʻike ʻia ʻo TWI (Two Wire Interface):

  • Hoʻokahi no ka uaki (SCL).
  • Nā mea ʻē aʻe no ka ʻikepili (SDA).
ʻO nā mea ʻelua he wehe i nā pilina CMOS a koi aku i nā mea pale huki. Eia kekahi, inā hoʻouna kekahi hāmeʻa i kahi 0 a me kekahi a 1, aia paha he mau pilikia, ʻo ia ke kumu e hoʻonoho mau ai ka laina i 1 (pae kiʻekiʻe) a hoʻouna pinepine nā hāmeʻa iā 0 (pae haʻahaʻa)

Hōʻike ia i ka haku a kauā hoʻouna lākou i ka ʻikepili ma luna o ke kaula like a i ʻole ke ala like, i kaohi ʻia e ka mea mua e hana i ka hōʻailona uaki. E loaʻa i kēlā me kēia meahana pili i ka pahi I2C kahi helu ʻokoʻa i hāʻawi ʻia, i mea e kuhikuhi ai i nā lawe. Akā ʻaʻole pono ia he like mau ka haku (multi-master), ʻo ia ka mea nāna i hoʻomaka ka hoʻololi.

E like me kaʻu i wehewehe mua ai i ka ʻatikala ma Arduino I2C Ua kuhikuhi wau ma mua, aia i kēlā me kēia papa kēia mau pilina I2C ma nā wahi like ʻole. He mea ia āu e noʻonoʻo ai e hiki ke hoʻohana pono iā ia i kēlā me kēia mana o ka pā.

  • Arduino UNO: Aia ʻo SDA i A4 a me SCK ma A5
  • Arduino Nano: like me ka mea i hala.
  • ʻO Arduino Mini Pro: like.
  • ʻO Arduino Mega: Aia ʻo SDA ma ka pin 20 a me SCK ma ka 21.
  • Nā ʻike hou aʻe e pili ana i nā pā.

Maopopo iā ʻoe hiki iā ʻoe ke hoʻohana i ka I2C no kāu sketches maʻalahi, ʻoiai ka Waihona.h hale waihona puke me nā hana like ʻole no kēia kamaʻilio pūkaʻina.

  • hoʻomaka (): e hoʻomaka i ka waihona Waihona a kuhikuhi inā he haku a kauā paha ia
  • noiFrom (): hoʻohana ʻia e ka haku e noi i ka ʻikepili mai ke kauā.
  • hoʻomakaTransmission (): hoʻomaka hoʻoili me ke kauā.
  • hoʻouna hope (): hoʻoili hopena.
  • kākau ()- Kākau i ka ʻikepili mai kahi kauā e pane i kahi noi mai ka haku, a i ʻole hiki iā ʻoe ke kūlou i ka lawe ʻana o kahi haku.
  • loaʻa (): e hoʻihoʻi i ka helu o nā bytes e heluhelu.
  • heluhelu(): heluhelu i kahi byte i hoʻoili ʻia mai ke kauā i kahi haku a i ʻole ka hope.
  • onReceive (): Kāhea i kahi hana ke loaʻa i kahi kauā kahi lawe mai kahi haku.
  • i noi (): Kāhea i kahi hana ke noi ke kauā i ka ʻikepili mai kahi haku.

No ʻike hou aku e pili ana i ka hoʻolālā Arduino a me nā hana hiki iā ʻoe ke hoʻoiho i kā mākou PDF hōʻike aʻo.

He aha ka PCF8574?

Kōnae PCF8574

ʻO ka PCF8574 a Nā hoʻokomo kikohoʻe I2C pahi a me nā mea hoʻokomo (I / O) expander. Hiki ke hana ʻia e nā mea hana like ʻole, me ka loaʻa iā ia i nā IC a me nā modula. I kēlā me kēia hihia, he kūpono loa e hoʻopili iā ia i kāu papa Arduino a hiki i ka hiki ke kaohi i nā ʻoihana hou aʻe ma mua o ka motherboard i ʻae.

El PCF8574 pinout He maʻalahi ia, ʻoiai e hoʻopili wale 8 pines quasidirectional (P0-P7 kahi e pili ai nā ʻāpana e pili ai), a ma ka ʻaoʻao ʻē aʻe iā ʻoe ka SDA a me SCL e pili pono ʻoe i ka papa Arduino, a ʻo VCC a me GND e hoʻomāhuahua pū i ka modula. A mai poina i nā māka kuhikuhi ʻekolu iā A0, A1, A2 e koho ai i kahi o nā hāmeʻa e kuhikuhi ai ka kamaʻilio i ...

ʻO PCF8574 pinout

Nāwai nā hiʻohiʻona ʻē aʻe i ʻike ʻoe:

  • Kona pili, i ka wehe hamama, hiki ke hoʻohana ʻia ma ke ʻano he hoʻokomo a me ka puka.
  • La pihi au ʻo 25mA ke hana ia ma ke ʻano he puka (poho, ke kahe o kēia manawa i PCF8574) a me 300 µA (kumuwaiwai, kahe kahe mai PCF8574).
  • La ka pilikia ʻO 2.5 a me 6v ka lako mana. He haʻahaʻa loa ke kū ʻana o ka kū, 10 mau wale nō.
  • Nā huahana āpau loaʻa nā latch, e mālama i ka mokuʻāina me ka ʻole o ka hana o waho. Pono ʻoe e hana ke makemake ʻoe e hoʻololi i ka mokuʻāina.
  • Hiki iā ʻoe ke loaʻa iā 8 hiki i nā ʻōkuhi, ʻo ia, a i 8 mau hāmeʻa e launa pū me ka hoʻohana ʻana i nā modula 8 e hoʻonui ai a i nā hāmeʻa 64. ʻO nā helu (pin A0, A1, A2) ʻo ia:
    • 000: helu wahi 0x20
    • 001: helu wahi 0x21
    • 010: helu wahi 0x22
    • 011: helu wahi 0x23
    • 100: helu wahi 0x24
    • 101: helu wahi 0x25
    • 110: helu wahi 0x26
    • 111: helu wahi 0x27
  • ʻAe hoʻōki wale (INT) e kahi laina kūikawā e ʻike i ka ʻikepili me ka nānā mau ʻole ʻia.

Hoʻohui pū me Arduino

Kiʻi kiʻi o Arduino IDE

He mea maʻalahi ka pilina me Arduino, pono ʻoe e hoʻopili iā Vcc me ka pine 5v o ka papa Arduino, a me GND me GND o Arduino. Ma ka lima ʻē aʻe, hiki i nā mākia o ka PCF8574 SDA a me SCL module i hoʻohui me nā pin 14 (A5 SCL) a me 15 (A4 SDA). Me ia wale nō e hoʻomaka ai ka hana, maopopo leʻa hiki iā ʻoe ke hoʻohana i ka Px e hoʻohui i nā hāmeʻa āu e makemake ai e kamaʻilio ...

A laila e nalo wale ana nō ia e hoʻomaka me kahi sketch laʻana i ka Arduino IDE. Hiki iā ʻoe ke hana me ka hoʻohana ʻole ʻana i kahi waihona hou e like me ...

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

As hoʻokomo:

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

A i ʻole kekahi hoʻohana hale waihona puke, e like me ka PCF8574 i hiki iā ʻoe ʻike maʻaneʻi a hoʻohana i ke code e like me kēia mai ka laʻana ponoʻī e hele pū me kēia waihona:

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


Hoʻopili ka ʻike o ka ʻatikala i kā mākou kumumanaʻo o ka hoʻoponopono hoʻoponopono. E hōʻike i kahi kaomi hemahema ʻaneʻi.

E lilo i mea mua e wehewehe

E waiho i kāu manaʻo

Kāu leka uila aae? E,ʻaʻole e paʻiʻia. i hāliu aku i koi 'ia kula *

*

*

  1. He kuleana no ka ʻikepili: Miguel Ángel Gatón
  2. Ke kumu o ka ʻikepili: kaohi SPAM, hoʻokele ʻōlelo.
  3. Legitimation: Kou ʻae
  4. Ka kamaʻilio ʻana o ka ʻikepili: ʻaʻole e hōʻike ʻia ka ʻikepili i nā ʻaoʻao ʻekolu koe ka mana o ke kānāwai.
  5. Pūnaewele mālama: Pūnaewele i mālama ʻia e Occentus Networks (EU)
  6. Nā Kuleana: I kēlā me kēia manawa hiki iā ʻoe ke palena, hoʻōla a kāpae i kāu ʻike.