Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
command does not work
#1
command does not work, it was supposed to give a command that if button 1 was LOW, it would activate output P0, what did i do wrong to make it not work?

#include "Arduino.h"
#include "PCF8574.h"

// Define o endereço de entrada do i2c
PCF8574 pcf8574_1(0x22,4,5); // canal 1-8 endereço: 100010
PCF8574 pcf8574_2(0x21,4,5); // endereço do canal 9-16: 100001
PCF8574 pcf8574_3(0x25,4,5);


unsigned long timeElapsed;
void setup()
{
    Serial.begin(115200);
    atraso(1000);


pcf8574_3.pinMode(P5, OUTPUT);

pcf8574_1.pinMode(P0, ENTRADA);
pcf8574_1.pinMode(P1, ENTRADA);
pcf8574_1.pinMode(P2, ENTRADA);
pcf8574_1.pinMode(P3, ENTRADA);
pcf8574_1.pinMode(P4, INPUT);
pcf8574_1.pinMode(P5, ENTRADA);
pcf8574_1.pinMode(P6, INPUT);
pcf8574_1.pinMode(P7, ENTRADA);

pcf8574_2.pinMode(P0, ENTRADA);
pcf8574_2.pinMode(P1, ENTRADA);
pcf8574_2.pinMode(P2, ENTRADA);
pcf8574_2.pinMode(P3, ENTRADA);
pcf8574_2.pinMode(P4, INPUT);
pcf8574_2.pinMode(P5, ENTRADA);
pcf8574_2.pinMode(P6, INPUT);
pcf8574_2.pinMode(P7, ENTRADA);

    Serial.print("Iniciar pcf8574...");
    if (pcf8574_1.begin()){
        Serial.println("pcf8574_1_OK");
    }outro{
        Serial.println("pcf8574_1_KO");
    }

  Serial.print("Iniciar pcf8574...");
  if (pcf8574_2.begin()){
    Serial.println("pcf8574_2_OK");
  }outro{
    Serial.println("pcf8574_2_KO");
  }
Serial.print("Iniciar pcf8574...");
    if (pcf8574_3.begin()){
        Serial.println("pcf8574_3_OK");
    }outro{
        Serial.println("pcf8574_3_KO");
    }

}

laço vazio()
{
uint8_t val1 = pcf8574_1.digitalRead(P0);
uint8_t val2 = pcf8574_1.digitalRead(P1);
uint8_t val3 = pcf8574_1.digitalRead(P2);
uint8_t val4 = pcf8574_1.digitalRead(P3);
uint8_t val5 = pcf8574_1.digitalRead(P4);
uint8_t val6 = pcf8574_1.digitalRead(P5);
uint8_t val7 = pcf8574_1.digitalRead(P6);
uint8_t val8 = pcf8574_1.digitalRead(P7);

uint8_t val9 = pcf8574_2.digitalRead(P0);
uint8_t val10 = pcf8574_2.digitalRead(P1);
uint8_t val11 = pcf8574_2.digitalRead(P2);
uint8_t val12 = pcf8574_2.digitalRead(P3);
uint8_t val13 = pcf8574_2.digitalRead(P4);
uint8_t val14 = pcf8574_2.digitalRead(P5);
uint8_t val15 = pcf8574_2.digitalRead(P6);
uint8_t val16 = pcf8574_2.digitalRead(P7);

if (val1==BAIXO) {pcf8574_3.digitalWrite(P0, ALTO);}


if (val1==BAIXO) Serial.println("TECLA 1 PRESSIONADA");
if (val2==BAIXO) Serial.println("TECLA 2 PRESSIONADA");
if (val3==BAIXO) Serial.println("TECLA 3 PRESSIONADA");
if (val4==BAIXO) Serial.println("TECLA 4 PRESSIONADA");
if (val5==BAIXO) Serial.println("TECLA 5 PRESSIONADA");
if (val6==BAIXO) Serial.println("TECLA 6 PRESSIONADA");
if (val7==BAIXO) Serial.println("TECLA 7 PRESSIONADA");
if (val8==BAIXO) Serial.println("TECLA8 PRESSIONADA");

if (val9==BAIXO) Serial.println("TECLA 1 PRESSIONADA");
if (val10==BAIXO) Serial.println("TECLA 2 PRESSIONADA");
if (val11==BAIXO) Serial.println("TECLA 3 PRESSIONADA");
if (val12==BAIXO) Serial.println("TECLA 4 PRESSIONADA");
if (val13==BAIXO) Serial.println("TECLA 5 PRESSIONADA");
if (val14==BAIXO) Serial.println("TECLA 6 PRESSIONADA");
if (val15==BAIXO) Serial.println("TECLA 7 PRESSIONADA");
if (val16==BAIXO) Serial.println("TECLA8 PRESSIONADA");
atraso(300);
}
Reply
#2
you can use these code (input trigger output) :

#include "Arduino.h"
#include "PCF8574.h"


TwoWire I2Cone = TwoWire(0);
//TwoWire I2Ctwo = TwoWire(1);

// Set i2c address
PCF8574 pcf8574_I1(&I2Cone, 0x21, 4, 5);
PCF8574 pcf8574_I2(&I2Cone, 0x22, 4, 5);

PCF8574 pcf8574_R1(&I2Cone, 0x24, 4, 5);
PCF8574 pcf8574_R2(&I2Cone, 0x25, 4, 5);

void setup()
{
// Set pinMode to OUTPUT
pcf8574_R1.pinMode(P0, OUTPUT);
pcf8574_R1.pinMode(P1, OUTPUT);
pcf8574_R1.pinMode(P2, OUTPUT);
pcf8574_R1.pinMode(P3, OUTPUT);
pcf8574_R1.pinMode(P4, OUTPUT);
pcf8574_R1.pinMode(P5, OUTPUT);
pcf8574_R1.pinMode(P6, OUTPUT);
pcf8574_R1.pinMode(P7, OUTPUT);

pcf8574_R2.pinMode(P0, OUTPUT);
pcf8574_R2.pinMode(P1, OUTPUT);
pcf8574_R2.pinMode(P2, OUTPUT);
pcf8574_R2.pinMode(P3, OUTPUT);
pcf8574_R2.pinMode(P4, OUTPUT);
pcf8574_R2.pinMode(P5, OUTPUT);
pcf8574_R2.pinMode(P6, OUTPUT);
pcf8574_R2.pinMode(P7, OUTPUT);

pcf8574_I1.pinMode(P0, INPUT);
pcf8574_I1.pinMode(P1, INPUT);
pcf8574_I1.pinMode(P2, INPUT);
pcf8574_I1.pinMode(P3, INPUT);
pcf8574_I1.pinMode(P4, INPUT);
pcf8574_I1.pinMode(P5, INPUT);
pcf8574_I1.pinMode(P6, INPUT);
pcf8574_I1.pinMode(P7, INPUT);

pcf8574_I2.pinMode(P0, INPUT);
pcf8574_I2.pinMode(P1, INPUT);
pcf8574_I2.pinMode(P2, INPUT);
pcf8574_I2.pinMode(P3, INPUT);
pcf8574_I2.pinMode(P4, INPUT);
pcf8574_I2.pinMode(P5, INPUT);
pcf8574_I2.pinMode(P6, INPUT);
pcf8574_I2.pinMode(P7, INPUT);


Serial.print("Init pcf8574_R1...");
if (pcf8574_R1.begin()){
Serial.println("PCF8574_R1_OK");
}else{
Serial.println("PCF8574_R1_KO");
}

Serial.print("Init pcf8574_R2...");
if (pcf8574_R2.begin()){
Serial.println("PCF8574_R2_OK");
}else{
Serial.println("PCF8574_R2_KO");
}


Serial.print("Init pcf8574...");
if (pcf8574_I1.begin()){
Serial.println("pcf8574_I1_OK");
}else{
Serial.println("pcf8574_I1_KO");
}

Serial.print("Init pcf8574...");
if (pcf8574_I2.begin()){
Serial.println("pcf8574_I2_OK");
}else{
Serial.println("pcf8574_I2_KO");
}


pcf8574_R1.digitalWrite(P0, HIGH);
pcf8574_R1.digitalWrite(P1, HIGH);
pcf8574_R1.digitalWrite(P2, HIGH);
pcf8574_R1.digitalWrite(P3, HIGH);
pcf8574_R1.digitalWrite(P4, HIGH);
pcf8574_R1.digitalWrite(P5, HIGH);
pcf8574_R1.digitalWrite(P6, HIGH);
pcf8574_R1.digitalWrite(P7, HIGH);


pcf8574_R2.digitalWrite(P0, HIGH);
pcf8574_R2.digitalWrite(P1, HIGH);
pcf8574_R2.digitalWrite(P2, HIGH);
pcf8574_R2.digitalWrite(P3, HIGH);
pcf8574_R2.digitalWrite(P4, HIGH);
pcf8574_R2.digitalWrite(P5, HIGH);
pcf8574_R2.digitalWrite(P6, HIGH);
pcf8574_R2.digitalWrite(P7, HIGH);

}

void loop()
{
uint8_t val1 = pcf8574_I1.digitalRead(P0);
uint8_t val2 = pcf8574_I1.digitalRead(P1);
uint8_t val3 = pcf8574_I1.digitalRead(P2);
uint8_t val4 = pcf8574_I1.digitalRead(P3);
uint8_t val5 = pcf8574_I1.digitalRead(P4);
uint8_t val6 = pcf8574_I1.digitalRead(P5);
uint8_t val7 = pcf8574_I1.digitalRead(P6);
uint8_t val8 = pcf8574_I1.digitalRead(P7);

uint8_t val9 = pcf8574_I2.digitalRead(P0);
uint8_t val10 = pcf8574_I2.digitalRead(P1);
uint8_t val11 = pcf8574_I2.digitalRead(P2);
uint8_t val12 = pcf8574_I2.digitalRead(P3);
uint8_t val13 = pcf8574_I2.digitalRead(P4);
uint8_t val14 = pcf8574_I2.digitalRead(P5);
uint8_t val15 = pcf8574_I2.digitalRead(P6);
uint8_t val16 = pcf8574_I2.digitalRead(P7);

//------------------------------------
if (val1==LOW) pcf8574_R1.digitalWrite(P0, LOW); else pcf8574_R1.digitalWrite(P0, HIGH);
if (val2==LOW) pcf8574_R1.digitalWrite(P1, LOW); else pcf8574_R1.digitalWrite(P1, HIGH);
if (val3==LOW) pcf8574_R1.digitalWrite(P2, LOW); else pcf8574_R1.digitalWrite(P2, HIGH);
if (val4==LOW) pcf8574_R1.digitalWrite(P3, LOW); else pcf8574_R1.digitalWrite(P3, HIGH);
if (val5==LOW) pcf8574_R1.digitalWrite(P4, LOW); else pcf8574_R1.digitalWrite(P4, HIGH);
if (val6==LOW) pcf8574_R1.digitalWrite(P5, LOW); else pcf8574_R1.digitalWrite(P5, HIGH);
if (val7==LOW) pcf8574_R1.digitalWrite(P6, LOW); else pcf8574_R1.digitalWrite(P6, HIGH);
if (val8==LOW) pcf8574_R1.digitalWrite(P7, LOW); else pcf8574_R1.digitalWrite(P7, HIGH);

if (val9==LOW) pcf8574_R2.digitalWrite(P0, LOW); else pcf8574_R2.digitalWrite(P0, HIGH);
if (val10==LOW) pcf8574_R2.digitalWrite(P1, LOW); else pcf8574_R2.digitalWrite(P1, HIGH);
if (val11==LOW) pcf8574_R2.digitalWrite(P2, LOW); else pcf8574_R2.digitalWrite(P2, HIGH);
if (val12==LOW) pcf8574_R2.digitalWrite(P3, LOW); else pcf8574_R2.digitalWrite(P3, HIGH);
if (val13==LOW) pcf8574_R2.digitalWrite(P4, LOW); else pcf8574_R2.digitalWrite(P4, HIGH);
if (val14==LOW) pcf8574_R2.digitalWrite(P5, LOW); else pcf8574_R2.digitalWrite(P5, HIGH);
if (val15==LOW) pcf8574_R2.digitalWrite(P6, LOW); else pcf8574_R2.digitalWrite(P6, HIGH);
if (val16==LOW) pcf8574_R2.digitalWrite(P7, LOW); else pcf8574_R2.digitalWrite(P7, HIGH);
//-------------------------------------

delay(30);

}
Reply
#3
every time I load this error, how do I fix it?

Arduino: 1.8.19 (Windows 7), Placa:"NodeMCU-32S, 80MHz, 921600"

O sketch usa 213294 bytes (16%) de espaço de armazenamento para programas. O máximo são 1310720 bytes.

Variáveis globais usam 15120 bytes (4%) de memória dinâmica, deixando 312560 bytes para variáveis locais. O máximo são 327680 bytes.

esptool.py v3.0-dev

Serial port COM4

Connecting....

Chip is ESP32-D0WD-V3 (revision 3)

Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None

Crystal is 40MHz

MAC: 90:38:0c:a4:30:08

Uploading stub...

Running stub...

Stub running...

Changing baud rate to 921600

Changed.

Configuring flash size...

Warning: Could not auto-detect Flash size (FlashID=0x0, SizeID=0x0), defaulting to 4MB

Compressed 8192 bytes to 47...

Writing at 0x0000e000... (100 %)

Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.0 seconds (effective 8192.1 kbit/s)...



A fatal error occurred: Timed out waiting for packet header

A fatal error occurred: Timed out waiting for packet header





Este relatório teria mais informações com
"Mostrar a saida detalhada durante a compilação"
opção pode ser ativada em "Arquivo -> Preferências"
Reply
#4
arduino IDE "board" chose "NodeMcu-32s"
Reply
#5
it´s already there, the time is right, the time will not go. which one is right?
Reply
#6
can you replace a dc12v power supply and USB-C cable for a test.
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)