// #include <LiquidCrystal_I2C.h>
// LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x3F for a 16 chars and 2 line display
// void setup() {
// lcd.init();
// lcd.clear();
// lcd.backlight(); // Make sure backlight is on
// // Print a message on both lines of the LCD.
// lcd.setCursor(2,0); //Set cursor to character 2 on line 0
// lcd.print("Hello world!");
// lcd.setCursor(2,1); //Move cursor to character 2 on line 1
// lcd.print("LCD Tutorial");
// }
// void loop() {
// }
//---------------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/i2c.h"
#include "esp_err.h"
#include "sdkconfig.h"
#include "LiquidCrystal_I2C.h"
#define I2C_MASTER_SCL_IO 22 // I2C clock pin
#define I2C_MASTER_SDA_IO 21 // I2C data pin
#define I2C_MASTER_NUM I2C_NUM_0 // I2C port number
#define I2C_MASTER_TX_BUF_DISABLE 0 // I2C transmit buffer disabled
#define I2C_MASTER_RX_BUF_DISABLE 0 // I2C receive buffer disabled
#define LCD_ADDR 0x27 // LCD I2C address
#define LCD_COLS 20 // LCD columns
#define LCD_ROWS 4 // LCD rows
LiquidCrystal_I2C lcd(LCD_ADDR, LCD_COLS, LCD_ROWS); // set the LCD address and dimensions
void i2c_master_init() {
i2c_config_t conf;
conf.mode = I2C_MODE_MASTER;
conf.sda_io_num = I2C_MASTER_SDA_IO;
conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
conf.scl_io_num = I2C_MASTER_SCL_IO;
conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
conf.master.clk_speed = 100000;
i2c_param_config(I2C_MASTER_NUM, &conf);
i2c_driver_install(I2C_MASTER_NUM, conf.mode,
I2C_MASTER_RX_BUF_DISABLE,
I2C_MASTER_TX_BUF_DISABLE, 0);
}
extern "C"{
void my_app_main() {
i2c_master_init();
lcd.init();
lcd.clear();
lcd.backlight(); // make sure backlight is on
// Print a message on both lines of the LCD.
lcd.setCursor(2,0); // set cursor to character 2 on line 0
lcd.print("Hello world!");
lcd.setCursor(2,1); // move cursor to character 2 on line 1
lcd.print("LCD Tutorial");
while (1) {
// your code here
}
}
}