Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
KC868-A4S ESP32 I/O pin define
#1
#define ANALOG_A1  36
#define ANALOG_A2  39
#define ANALOG_A3  34
#define ANALOG_A4  35

IIC SDA:4
IIC SCL:16

Relay_IIC_address 0x24
P0--P3: for relay1-relay4
P4--P7: for DI9--DI12

Input_IIC_address 0x22  for DI1-DI8

PCA9685 IIC address: 0x00

DS18B20/DHT11/DHT21/LED strip -1: 5
DS18B20/DHT11/DHT21/LED strip -2: 14


Ethernet (LAN8720) I/O define:

#define ETH_ADDR        0
#define ETH_POWER_PIN  -1
#define ETH_MDC_PIN    23
#define ETH_MDIO_PIN  18
#define ETH_TYPE      ETH_PHY_LAN8720
#define ETH_CLK_MODE  ETH_CLOCK_GPIO17_OUT


RS485:
RXD:GPIO33
TXD:GPIO32

GSM:
RXD:GPIO13
TXD:GPIO15
Reply
#2
Hi, I am tried to use i2c (iic), with a bme 280 sensor, but it does not works, please caun you help to fix the problem or can you provide me a explication how to use the sensor. I used the netx programation:
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme; // I2C


unsigned long delayTime;

void setup() {
Serial.begin(9600);
while(!Serial); // time to get serial running
Serial.println(F("BME280 test"));

unsigned status;

// default settings
status = bme.begin();
// You can also pass in a Wire library object like &Wire2
status = bme.begin(0x76);
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
Serial.print(" ID of 0x60 represents a BME 280.\n");
Serial.print(" ID of 0x61 represents a BME 680.\n");
while (1) delay(10);
}

Serial.println("-- Default Test --");
delayTime = 1000;

Serial.println();
}


void loop() {
printValues();
delay(delayTime);
}


void printValues() {
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" °C");

Serial.print("Pressure = ");

Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");

Serial.print("Approx. Altitude = ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m");

Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");

Serial.println();
}
Reply
#3
you need to check where to define I2C bus GPIO pins, SCL and SDA pins.
Reply
#4
(10-11-2023, 10:30 PM)admin Wrote: you need to check where to define I2C bus GPIO pins, SCL and SDA pins.

okay, but, please, how  can I do it ?
Reply
#5
set SDA,SCL pin define as this photo.
   
Reply
#6
(10-11-2023, 11:54 PM)admin Wrote: set SDA,SCL pin define as this photo.

so, like this ? ....

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>



#define SEALEVELPRESSURE_HPA (1013.25)
#define SDA  4
#define SCL  16

Adafruit_BME280 bme; // I2C

unsigned long delayTime;

void setup() {
    Serial.begin(9600);
    while(!Serial);    // time to get serial running
    Serial.println(F("BME280 test"));

    unsigned status;
 
    status = bme.begin(); 
 
    status = bme.begin(0x76);
    if (!status) {
        Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
        Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
        Serial.print("        ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
        Serial.print("  ID of 0x56-0x58 represents a BMP 280,\n");
        Serial.print("        ID of 0x60 represents a BME 280.\n");
        Serial.print("        ID of 0x61 represents a BME 680.\n");
        while (1) delay(10);
    }
   
    Serial.println("-- Default Test --");
    delayTime = 1000;

    Serial.println();
}


void loop() {
    printValues();
    delay(delayTime);
}


void printValues() {
    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" °C");

    Serial.print("Pressure = ");

    Serial.print(bme.readPressure() / 100.0F);
    Serial.println(" hPa");

    Serial.print("Approx. Altitude = ");
    Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
    Serial.println(" m");

    Serial.print("Humidity = ");
    Serial.print(bme.readHumidity());
    Serial.println(" %");

    Serial.println();
}
Reply
#7
(10-12-2023, 03:09 AM)DanielGuerrero Wrote:
(10-11-2023, 11:54 PM)admin Wrote: set SDA,SCL pin define as this photo.

so, like this ? ....

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>



#define SEALEVELPRESSURE_HPA (1013.25)
//delet these two command
#define SDA  4
#define SCL  16


Adafruit_BME280 bme; // I2C

unsigned long delayTime;

void setup() {
    Serial.begin(9600);
    wire.begin(4,16);//add this command
    while(!Serial);    // time to get serial running
    Serial.println(F("BME280 test"));

    unsigned status;
 
    status = bme.begin(); 
 
    status = bme.begin(0x76);
    if (!status) {
        Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
        Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
        Serial.print("        ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
        Serial.print("  ID of 0x56-0x58 represents a BMP 280,\n");
        Serial.print("        ID of 0x60 represents a BME 280.\n");
        Serial.print("        ID of 0x61 represents a BME 680.\n");
        while (1) delay(10);
    }
   
    Serial.println("-- Default Test --");
    delayTime = 1000;

    Serial.println();
}


void loop() {
    printValues();
    delay(delayTime);
}


void printValues() {
    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" °C");

    Serial.print("Pressure = ");

    Serial.print(bme.readPressure() / 100.0F);
    Serial.println(" hPa");

    Serial.print("Approx. Altitude = ");
    Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
    Serial.println(" m");

    Serial.print("Humidity = ");
    Serial.print(bme.readHumidity());
    Serial.println(" %");

    Serial.println();
}
Reply
#8
Good morning . I have a problem with the definition of the pins that you sent on the KC868-A4S can I have some clarification with an example of code using two ds18b20 two between digital switches and I use a current sensor and another sensor power outage detection


#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <PCF8574.h>  // Pour le contrôle des relais via I2C (adresse 0x24)
// Pin DS18B20
#define ONE_WIRE_BUS_1 5  // DS18B20 - 1er capteur (bande de DEL - 1)
#define ONE_WIRE_BUS_2 14 // DS18B20 - 2ème capteur (bande de DEL - 2)
OneWire oneWire1(ONE_WIRE_BUS_1);
OneWire oneWire2(ONE_WIRE_BUS_2);
DallasTemperature sensors1(&oneWire1);
DallasTemperature sensors2(&oneWire2);
// Relais I2C Adresse 0x24
PCF8574 pcf8574(0x24);
// Entrées de détection (interrupteurs)
#define INTERRUPT_PIN1 2  // Interrupteur 1
#define INTERRUPT_PIN2 3  // Interrupteur 2
// Capteur de courant (ACS712)
#define CURRENT_SENSOR_PIN A0
// Capteur de coupure de courant
#define POWER_FAILURE_PIN 7
// Variables pour stocker les températures
float temp1 = 0.0;
float temp2 = 0.0;
void setup() {
  // Initialisation de la communication série
  Serial.begin(115200);
  // Initialisation du bus I2C
  Wire.begin();
  // Initialisation des capteurs de température DS18B20
  sensors1.begin();
  sensors2.begin();
  // Initialisation des relais via I2C
  pcf8574.begin();
  pcf8574.pinMode(P0, OUTPUT);
  pcf8574.pinMode(P1, OUTPUT);
  pcf8574.pinMode(P2, OUTPUT);
  pcf8574.pinMode(P3, OUTPUT);
  // Initialisation des interrupteurs
  pinMode(INTERRUPT_PIN1, INPUT_PULLUP);  // Interrupteur 1
  pinMode(INTERRUPT_PIN2, INPUT_PULLUP);  // Interrupteur 2
  // Initialisation du capteur de courant (ACS712)
  pinMode(CURRENT_SENSOR_PIN, INPUT);
  // Initialisation du capteur de coupure de courant
  pinMode(POWER_FAILURE_PIN, INPUT_PULLUP);
  // Attacher les interruptions aux pins des interrupteurs
  attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN1), handleInterrupt1, FALLING);  // Déclenchement sur INT1
  attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN2), handleInterrupt2, FALLING);  // Déclenchement sur INT2
}
void loop() {
  // Lire les températures des capteurs DS18B20
  sensors1.requestTemperatures();
  sensors2.requestTemperatures();
  temp1 = sensors1.getTempCByIndex(0);  // Température du premier DS18B20
  temp2 = sensors2.getTempCByIndex(0);  // Température du deuxième DS18B20
  // Lire le capteur de courant (ACS712)
  int sensorValue = analogRead(CURRENT_SENSOR_PIN);
  float voltage = sensorValue * (5.0 / 1023.0);  // Conversion de la valeur analogique en tension
  float current = (voltage - 2.5) / 0.185;  // Conversion de la tension en courant (en fonction de votre capteur)
  // Vérifier si une coupure de courant a été détectée
  bool powerFailure = digitalRead(POWER_FAILURE_PIN) == LOW;  // Si le pin est bas, coupure de courant détectée
  // Affichage des résultats sur le moniteur série
  Serial.print("Température 1 : ");
  Serial.print(temp1);
  Serial.print(" °C, Température 2 : ");
  Serial.print(temp2);
  Serial.print(" °C, Courant : ");
  Serial.print(current);
  Serial.print(" A, Coupure de courant : ");
  if (powerFailure) {
    Serial.println("Oui");
  } else {
    Serial.println("Non");
  }
  // Activation des relais (P0 à P3 sur I2C via PCF8574)
  // Exemple d'activation des relais 1 à 4
  pcf8574.digitalWrite(P0, HIGH);  // Relais 1 ON
  delay(1000);  // Délai d'une seconde
  pcf8574.digitalWrite(P1, HIGH);  // Relais 2 ON
  delay(1000);
  pcf8574.digitalWrite(P2, HIGH);  // Relais 3 ON
  delay(1000);
  pcf8574.digitalWrite(P3, HIGH);  // Relais 4 ON
  delay(1000);
  // Désactivation des relais
  pcf8574.digitalWrite(P0, LOW);  // Relais 1 OFF
  pcf8574.digitalWrite(P1, LOW);  // Relais 2 OFF
  pcf8574.digitalWrite(P2, LOW);  // Relais 3 OFF
  pcf8574.digitalWrite(P3, LOW);  // Relais 4 OFF
  delay(1000);  // Délai de 1 seconde
}
// Fonction pour gérer l'interruption 1
void handleInterrupt1() {
  Serial.println("Interrupteur 1 activé!");
  // Ajoutez ici votre logique pour réagir à l'interruption
}
// Fonction pour gérer l'interruption 2
void handleInterrupt2() {
  Serial.println("Interrupteur 2 activé!");
  // Ajoutez ici votre logique pour réagir à l'interruption
}
Reply
#9
which pin define have issue?
Reply
#10
(01-05-2025, 01:09 AM)admin Wrote: which pin define have issue?

none of the pins respond to relay activation or data collection I ask if I have respected the rules for using pins
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)