Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PROGRAM KC868 A16 DI, DO AND LIQUID CRYSTAL FROM ARDUINO IDE
#12
(01-27-2025, 05:43 PM)Cesarcardca Wrote: I NEED PROGRAM KC868 A16 DI, DO AND LIQUID CRYSTAL I2C FROM ARDUINO IDE. Or if your recommendation is through esphome, I could also try it, I need the syntax, or the devices for inputs and outputs so I can manipulate my program since I also need to interrupt a sensor.

Just add this code to your code for input/output controls.

Code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// I2C address of the LCD
#define LCD_ADDR 0x3f
//Some models may use 0x27 address
// Initialize the LCD
LiquidCrystal_I2C lcd(LCD_ADDR, 20, 20);
void setup() {
  Wire.begin(4, 5);  // SDA pin = 4, SCL pin = 5 on the ESP32
  Serial.begin(115200);
 
  lcd.init();       // Initialize the LCD
  lcd.backlight();  // Turn on the LCD backlight
  lcd.setCursor(0, 0);
  lcd.print("LCD example");
}
void loop() {
  // Update the LCD content
  lcd.setCursor(0, 1); // Second line
  lcd.print(millis() / 1000); // Display the elapsed time in seconds
  delay(1000);
}

If you don't know the address of your display's I2C adapter, try finding it with the code below. Most use address 0x3F or 0x27.

Code:
#include <Wire.h>

void setup() {
  Wire.begin(4, 5); // Initialize I2C
  Serial.begin(115200);
  while (!Serial); // Wait for the serial monitor to initialize
  Serial.println("\nI2C Scanner");
}

void loop() {
  byte error, address;
  int nDevices = 0;

  Serial.println("Scanning...");

  for (address = 1; address < 127; address++) {
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0) {
      Serial.print("Device found at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.print(address, HEX);
      Serial.println(" !");
      nDevices++;
    }
    else if (error == 4) {
      Serial.print("Unknown error at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.println(address, HEX);
    }
  }
 
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("Scan complete\n");

  delay(5000); // Wait 5 seconds before scanning again
}
Reply


Messages In This Thread
RE: PROGRAM KC868 A16 DI, DO AND LIQUID CRYSTAL FROM ARDUINO IDE - by andrecaetano - 02-05-2025, 08:41 PM

Forum Jump:


Users browsing this thread:
1 Guest(s)