Cov txheej txheem:

PCF8591 (i2c Analog I/O Expander) Kev Siv Yooj Yim Yooj Yim: 9 Kauj Ruam
PCF8591 (i2c Analog I/O Expander) Kev Siv Yooj Yim Yooj Yim: 9 Kauj Ruam

Video: PCF8591 (i2c Analog I/O Expander) Kev Siv Yooj Yim Yooj Yim: 9 Kauj Ruam

Video: PCF8591 (i2c Analog I/O Expander) Kev Siv Yooj Yim Yooj Yim: 9 Kauj Ruam
Video: Кратенький обзор PCF8591 2024, Hlis ntuj nqeg
Anonim
PCF8591 (i2c Analog I/O Expander) Kev Siv Yooj Yim Yooj Yim
PCF8591 (i2c Analog I/O Expander) Kev Siv Yooj Yim Yooj Yim

Lub tsev qiv ntawv siv i2c pcf8591 IC nrog arduino thiab esp8266.

Qhov IC no tuaj yeem tswj hwm (txog 4) cov tswv yim sib piv thiab/lossis 1 qhov tso tawm zoo ib yam li ntsuas qhov ntsuas hluav taws xob, nyeem tus nqi ntsuas hluav taws xob lossis ploj ib qho coj mus.

Muaj peev xwm nyeem tus nqi sib piv thiab sau tus nqi sib piv nrog tsuas yog 2 xaim (zoo meej rau ESP-01).

Kuv sim ua kom yooj yim siv IC no, nrog kev ua haujlwm tsawg kawg nkaus.

Koj tuaj yeem pom qhov hloov kho tshiab ntawm kuv qhov chaw

Kauj Ruam 1: Yuav Ua Li Cas I2c Ua Haujlwm

Yuav ua li cas I2c Ua Haujlwm
Yuav ua li cas I2c Ua Haujlwm

I2C ua haujlwm nrog nws ob lub xov hlau, SDA (kab ntawv cov ntaub ntawv) thiab SCL (kab kab ntawv).

Ob txoj kab no tau qhib-ntws, tab sis raug rub nrog cov neeg tawm tsam.

Feem ntau muaj ib tus tswv thiab ib lossis ntau tus qhev ntawm kab, txawm hais tias tuaj yeem muaj ntau tus tswv, tab sis peb yuav tham txog qhov ntawd tom qab.

Ob tus tswv thiab qhev tuaj yeem xa lossis txais cov ntaub ntawv, yog li ntawd, cov cuab yeej tuaj yeem nyob hauv ib ntawm plaub lub xeev no: tus tswv xa, tus tswv tau txais, tus xa tus qhev, tus qhev tau txais.

Kauj ruam 2:

Koj tuaj yeem nrhiav kuv lub tsev qiv ntawv ntawm no.

Txhawm rau rub tawm.

Nyem rau DOWNLOADS khawm nyob rau hauv kaum sab xis saum toj, hloov lub npe uas tsis tau nyem PCF8591.

Txheeb xyuas tias PCF8591 nplaub tshev muaj PCF8591.cpp thiab PCF8591.h.

Muab lub PCF8591 lub tsev qiv ntawv tais ceev tseg koj / tsev qiv ntawv / ntawv tais ceev tseg.

Koj yuav xav tsim lub tsev qiv ntawv subfolder yog nws yog koj thawj lub tsev qiv ntawv.

Rov pib dua IDE.

Kauj ruam 3: Siv

Tus tsim: koj yuav tsum hla qhov chaw nyob ntawm i2c (txhawm rau txheeb xyuas qhov chaw nyob siv phau ntawv qhia no I2cScanner)

PCF8591 (uint8_t chaw nyob);

rau esp8266 yog tias koj xav tau qhia SDA e SCL tus pin siv qhov no:

PCF8591 (uint8_t chaw nyob, uint8_t sda, uint8_t scl);

Kauj Ruam 4: Nyeem Tus Nqi

Nyeem Tus Nqi
Nyeem Tus Nqi

IC raws li koj tuaj yeem pom hauv daim duab muaj 4 analog input thiab 1 analog output.

Yog li txhawm rau nyeem tag nrho cov lus sib piv hauv ib qho kev thauj koj tuaj yeem ua tau (tus nqi yog 0 txog 255):

PCF8591:: AnalogInput ai = pcf8591.analogReadAll ();

Serial.print (ai.ain0); Serial.print (" -"); Serial.print (ai.ain1); Serial.print (" -"); Serial.print (ai.ain2); Serial.print (" -"); Serial.println (ai.ain3);

yog tias koj xav nyeem ib qho analog input lossis channel:

int ana = pcf8591.analogRead (AIN0); // nyeem analog 0

Kauj Ruam 5: Nyeem Vale Los Ntawm Channel

Nyeem Vale Los Ntawm Channel
Nyeem Vale Los Ntawm Channel

IC no muaj ntau hom kev nyeem thiab koj tuaj yeem siv Analog input lossis analog channel (thaum koj siv ib leeg nyeem cov lus sib piv thiab cov channel nyob hauv cov duab).

Piv txwv li txhawm rau nyeem tus nqi ntawm channel 0 hauv Ob qhov kev nkag siab sib txawv koj yuav tsum ua:

int ana = pcf8591.analogRead (CHANNEL0, TWO_DIFFERENTIAL_INPUT); // nyeem analog 0

Kauj Ruam 6: Sau Tus Nqi

Yog tias koj xav sau tus nqi sib piv koj yuav tsum ua (tus nqi yog 0 txog 255):

pcf8591.analogWrite (128);

Kauj Ruam 7: Nta Ntxiv

Cov yam ntxwv ntxiv yog nyeem qhov ntsuas hluav taws xob: Rau kev suav ntawm qhov hluav taws xob koj yuav tsum dhau qee qhov ntsuas:

  • microcontrollerReferenceVoltage: tau txais qhov hluav taws xob los ntawm microcontroller voltage (tsuas yog AVR tsis muaj esp8266 rau esp 3.3v tsau)
  • referenceVoltage: yog microcontrollerReferenceVoltage cuav coj tus nqi no Cov lus txib yog:

void voltageWrite (ntab tus nqi, bool microcontrollerReferenceVoltage = muaj tseeb, ntab referenceVoltage = 5.0);

Ntab voltageRead (uint8_t analogPin, bool microcontrollerReferenceVoltage = muaj tseeb, ntab referenceVoltage = 5.0);

Piv txwv yog:

pcf8591.voltageWrite (2.7); // 2.7Volts tso tawm

ncua (3000);

ntab ana0V = pcf8591.voltageRead (AIN0); // Nyeem qhov hluav taws xob los ntawm analog 0

Serial.println (ana0V);

Kauj Ruam 8: Piv Txwv Daim Duab Txuas

Piv txwv Daim Duab Txuas
Piv txwv Daim Duab Txuas

Kauj ruam 9: Ua tsaug

i2c project series (Sau):

  • Kub ntsuas qhov ntsuas kub
  • Analog nthuav dav
  • Cov nthuav dav
  • Zaub Zaub

Pom zoo: