Last active
February 9, 2024 18:59
-
-
Save SimedruF/d65e221104f234069d6bdc033a431c87 to your computer and use it in GitHub Desktop.
ESP32-C6 with LCD16x2 test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Florin Simedru | |
Project details at https://blog.automatic-house.ro | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files. | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
*/ | |
#include <Wire.h> | |
#include <LiquidCrystal_I2C.h> | |
#include <ESP32Time.h> | |
ESP32Time rtc; | |
// Adresa I2C a LCD-ului | |
#define I2C_ADDR 0x27 // Adresa I2C a LCD-ului (poate varia) | |
// Definirea numărului de coloane și rânduri ale LCD-ului | |
#define LCD_COLUMNS 16 | |
#define LCD_ROWS 2 | |
// Inițializarea LCD-ului cu adresa I2C | |
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_ROWS); | |
void setup() | |
{ | |
Wire.setPins(6, 7); | |
Wire.begin(); | |
Serial.begin(115200); | |
Serial.println("\nI2C Scanner .."); | |
// Inițializarea LCD-ului | |
lcd.init(); | |
// Activarea iluminării LCD-ului | |
lcd.backlight(); | |
// Afisarea unui mesaj initial | |
lcd.setCursor(0, 0); | |
lcd.print("LCD initialized!"); | |
Serial.println("Backpack init'd."); | |
lcd.setCursor(0, 0); | |
// Print a message to the LCD. | |
rtc.setTime(30, 49, 20, 9, 2, 2024); // 17th Jan 2021 15:24:30 | |
// initialize digital pin LED_BUILTIN as an output. | |
pinMode(LED_BUILTIN, OUTPUT); | |
blink(); | |
ScanI2C(); | |
} | |
void ScanI2C() { | |
byte error, address; | |
int nDevices; | |
Serial.println("Scanning..."); | |
nDevices = 0; | |
for(address = 1; address < 127; ++address) { | |
Wire.beginTransmission(address); | |
error = Wire.endTransmission(); | |
if (error == 0) { | |
Serial.print("Dispozitiv gasit la adresa 0x"); | |
if (address < 16) | |
Serial.print("0"); | |
Serial.print(address, HEX); | |
Serial.println(" !"); | |
++nDevices; | |
} | |
else if (error == 4) { | |
Serial.print("Eroare la adresa 0x"); | |
if (address < 16) | |
Serial.print("0"); | |
Serial.println(address, HEX); | |
} | |
} | |
if (nDevices == 0) | |
Serial.println("Niciun dispozitiv I2C găsit\n"); | |
else | |
Serial.println("Scanez de nou\n"); | |
delay(5000); // Scanează din nou după 5 secunde | |
} | |
// the loop function runs over and over again forever | |
void blink() { | |
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) | |
delay(100); // wait for a second | |
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW | |
delay(100); // wait for a second | |
} | |
String local_time() { | |
// Obținerea timpului curent | |
return rtc.getTime("%H:%M:%S"); | |
} | |
void loop() | |
{ | |
// set cursor to first column, first row | |
lcd.setCursor(0, 0); | |
// print message | |
lcd.print("Hello, World!"); | |
delay(1000); | |
// clears the display to print new message | |
lcd.clear(); | |
// set cursor to first column, second row | |
lcd.setCursor(0,1); | |
lcd.print(local_time()); | |
delay(1000); | |
lcd.clear(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment