Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: GreenEllipsis/DFRobot_RGBLCD1602
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.0
Choose a base ref
...
head repository: GreenEllipsis/DFRobot_RGBLCD1602
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 16 commits
  • 6 files changed
  • 2 contributors

Commits on Mar 13, 2023

  1. Copy the full SHA
    b2ddb6b View commit details

Commits on Jun 8, 2023

  1. Create README.md

    GreenEllipsis authored Jun 8, 2023
    Copy the full SHA
    63525e0 View commit details
  2. Merge pull request #1 from GreenEllipsis/main

    update to release 1.0.0 plus readme
    Bad-Assumptions authored Jun 8, 2023
    Copy the full SHA
    8e970c0 View commit details

Commits on Jun 15, 2023

  1. Copy the full SHA
    986f623 View commit details

Commits on Jun 19, 2023

  1. Copy the full SHA
    42fc6e0 View commit details

Commits on Jun 20, 2023

  1. cleanup

    Bad-Assumptions committed Jun 20, 2023
    Copy the full SHA
    510bea7 View commit details

Commits on Sep 28, 2023

  1. Copy the full SHA
    79009bc View commit details
  2. Copy the full SHA
    412963f View commit details
  3. Merge pull request #3 from Kentucky-Fried-Circuits/main

    merge KFC updates
    GreenEllipsis authored Sep 28, 2023
    Copy the full SHA
    3179da5 View commit details
  4. Copy the full SHA
    fe7c2a3 View commit details
  5. Merge pull request #2 from Bad-Assumptions/main

    readme and LiquidCrystal stub
    GreenEllipsis authored Sep 28, 2023
    Copy the full SHA
    9c8ff46 View commit details
  6. Copy the full SHA
    c30e599 View commit details
  7. typos in README

    Bad-Assumptions committed Sep 28, 2023
    Copy the full SHA
    5340cfd View commit details
  8. Merge pull request #1 from GreenEllipsis/main

    Merge pull request #2 from Bad-Assumptions/main
    Bad-Assumptions authored Sep 28, 2023
    Copy the full SHA
    1a98261 View commit details

Commits on Sep 29, 2023

  1. Merge pull request #4 from Bad-Assumptions/main

    support for RGBLCD1602 v1.1
    GreenEllipsis authored Sep 29, 2023
    Copy the full SHA
    b702afa View commit details
  2. added REQUIRES arduino

    added REQUIRES arduino to compile more better
    GreenEllipsis authored Sep 29, 2023
    Copy the full SHA
    262dcc4 View commit details
Showing with 151 additions and 131 deletions.
  1. +2 −2 CMakeLists.txt
  2. +97 −58 DFRobot_RGBLCD1602.cpp
  3. +30 −7 DFRobot_RGBLCD1602.h
  4. 0 LiquidCrystal.h
  5. +9 −64 LiquidCrystal_I2C.h
  6. +13 −0 README.md
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
idf_component_register(
SRCS DFRobot_RGBLCD1602.cpp LiquidCrystal_I2C.cpp
INCLUDE_DIRS .
REQUIRES driver
)
REQUIRES driver arduino
)
155 changes: 97 additions & 58 deletions DFRobot_RGBLCD1602.cpp
Original file line number Diff line number Diff line change
@@ -27,25 +27,25 @@
#define LIB_TAG "DFRobot_RGBLCD1602"

const uint8_t color_define[4][3] =
{
{255, 255, 255}, // white
{255, 0, 0}, // red
{0, 255, 0}, // green
{0, 0, 255}, // blue, also monochrome
{
{255, 255, 255}, // white
{255, 0, 0}, // red
{0, 255, 0}, // green
{0, 0, 255}, // blue, also monochrome
};

// /*******************************public*******************************/
DFRobot_RGBLCD1602::DFRobot_RGBLCD1602(uint8_t lcdCols, uint8_t lcdRows, i2c_port_t i2c_num, uint8_t lcdAddr, uint8_t RGBAddr)
{
_lcdAddr = lcdAddr;
_RGBAddr = RGBAddr;
_cols = lcdCols;
_rows = lcdRows;
_i2c_num = i2c_num;
DFRobot_RGBLCD1602::DFRobot_RGBLCD1602(uint8_t lcdCols, uint8_t lcdRows, i2c_port_t i2c_num, uint8_t lcdAddr, uint8_t RGBAddr)
{
_lcdAddr = lcdAddr;
_RGBAddr = RGBAddr;
_cols = lcdCols;
_rows = lcdRows;
_i2c_num = i2c_num;
}
/**
* @brief scan an I2C address
*
*
*/
esp_err_t DFRobot_RGBLCD1602::i2c_scan(const uint8_t addr)
{
@@ -78,48 +78,59 @@ esp_err_t DFRobot_RGBLCD1602::init()
_RGBAddr = LCD_RGB_ADDRESS;
REG_RED = 0x04;
REG_GREEN = 0x03;
REG_BLUE = 0x02;
REG_BLUE = 0x02;
}
else
{
ret = i2c_scan(LCD_RGB_ADDRESS_ALT);
ret = i2c_scan(LCD_RGB_ADDRESS_ALT2);
if (ret == ESP_OK) // found it
{
_RGBAddr = LCD_RGB_ADDRESS_ALT;
_RGBAddr = LCD_RGB_ADDRESS_ALT2;
REG_RED = 0x06; // pwm2
REG_GREEN = 0x07; // pwm1
REG_BLUE = 0x08; // pwm0
REG_GREEN = 0x05; // pwm1
REG_BLUE = 0x04; // pwm0
}
else
{
ret = i2c_scan(LCD_RGB_ADDRESS_ALT);
if (ret == ESP_OK) // found it
{
_RGBAddr = LCD_RGB_ADDRESS_ALT;
REG_RED = 0x06; // pwm2
REG_GREEN = 0x07; // pwm1
REG_BLUE = 0x08; // pwm0
}
}
}
ESP_LOGD(_TAG, "backlight assigned to 0%02x", _RGBAddr);


_showFunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
begin(_rows);
_showFunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
begin(_rows);
return ret;
}

esp_err_t DFRobot_RGBLCD1602::clear()
{
esp_err_t ret = command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero
vTaskDelay(pdMS_TO_TICKS(12)); // this command takes a long time!
esp_err_t ret = command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero
vTaskDelay(pdMS_TO_TICKS(12)); // this command takes a long time!
home();
return ret;
}

esp_err_t DFRobot_RGBLCD1602::home()
{
esp_err_t ret = command(LCD_RETURNHOME); // set cursor position to zero
vTaskDelay(pdMS_TO_TICKS(12)); // this command takes a long time!
return ret;
}
esp_err_t DFRobot_RGBLCD1602::home()
{
esp_err_t ret = command(LCD_RETURNHOME); // set cursor position to zero
vTaskDelay(pdMS_TO_TICKS(12)); // this command takes a long time!
return ret;
}

esp_err_t DFRobot_RGBLCD1602::noDisplay()
{
_showControl &= ~LCD_DISPLAYON;
return command(LCD_DISPLAYCONTROL | _showControl);
}
esp_err_t DFRobot_RGBLCD1602::noDisplay()
{
_showControl &= ~LCD_DISPLAYON;
return command(LCD_DISPLAYCONTROL | _showControl);
}

esp_err_t DFRobot_RGBLCD1602::display()
esp_err_t DFRobot_RGBLCD1602::display()
{
_showControl |= LCD_DISPLAYON;
return command(LCD_DISPLAYCONTROL | _showControl);
@@ -192,9 +203,9 @@ esp_err_t DFRobot_RGBLCD1602::customSymbol(uint8_t location, uint8_t charmap[])

uint8_t data[9];
data[0] = 0x40;
for(int i=0; i<8; i++)
for (int i = 0; i < 8; i++)
{
data[i+1] = charmap[i];
data[i + 1] = charmap[i];
}
return i2c_master_write_to_device(_i2c_num, _lcdAddr,
data, 9,
@@ -203,18 +214,32 @@ esp_err_t DFRobot_RGBLCD1602::customSymbol(uint8_t location, uint8_t charmap[])
esp_err_t DFRobot_RGBLCD1602::setCursor(uint8_t col, uint8_t row)
{

col = (row == 0 ? col|0x80 : col|0xc0);
col = (row == 0 ? col | 0x80 : col | 0xc0);
const uint8_t data[] = {0x80, col};
return i2c_master_write_to_device(_i2c_num, _lcdAddr,
data, 2,
LCD_COMMAND_DELAY_MS / portTICK_PERIOD_MS);
data, 2,
LCD_COMMAND_DELAY_MS / portTICK_PERIOD_MS);
}

// this function generally doesn't work as expected. Better to use setRGB().
void DFRobot_RGBLCD1602::setPWM(uint8_t color, uint8_t pwm)
{
setReg(color, pwm);
if (_RGBAddr == 0x6b)
{
setReg(0x07, pwm);
}
}

esp_err_t DFRobot_RGBLCD1602::setRGB(uint8_t r, uint8_t g, uint8_t b)
{
ESP_RETURN_ON_ERROR(setReg(REG_RED, r), _TAG, "setReg(0x%2x, 0x%2x)", REG_RED, r);
ESP_RETURN_ON_ERROR(setReg(REG_GREEN, g), _TAG, "setReg(0x%2x, 0x%2x)", REG_GREEN, g);
ESP_RETURN_ON_ERROR(setReg(REG_BLUE, b), _TAG, "setReg(0x%2x, 0x%2x)", REG_BLUE, b);
if (_RGBAddr == 0x6b)
{
setReg(0x07, 0xFF);
}
return ESP_OK;
}

@@ -228,8 +253,8 @@ esp_err_t DFRobot_RGBLCD1602::blinkLED(void)
{
///< blink period in seconds = (<reg 7> + 1) / 24
///< on/off ratio = <reg 6> / 256
setReg(0x07, 0x17); // blink every second
return setReg(0x06, 0x7f); // half on, half off
setReg(0x07, 0x17); // blink every second
return setReg(0x06, 0x7f); // half on, half off
}

esp_err_t DFRobot_RGBLCD1602::noBlinkLED(void)
@@ -260,10 +285,11 @@ inline esp_err_t DFRobot_RGBLCD1602::command(uint8_t value)
{
const uint8_t data[] = {0x80, value};
return i2c_master_write_to_device(_i2c_num, _lcdAddr,
data, 2,
LCD_COMMAND_DELAY_MS / portTICK_PERIOD_MS);
data, 2,
LCD_COMMAND_DELAY_MS / portTICK_PERIOD_MS);
}

#ifndef ARDUINO // roll our own print functions
void DFRobot_RGBLCD1602::print(const char chr)
{
write(chr);
@@ -288,7 +314,7 @@ void DFRobot_RGBLCD1602::print(const float f, uint8_t decimalPlaces)
sprintf(str, "%.2f", f);
print(str);
}

#endif //ARDUINO
// void DFRobot_RGBLCD1602::setBacklight(bool mode){
// if(mode){
// setColorWhite(); // turn backlight on
@@ -298,15 +324,17 @@ void DFRobot_RGBLCD1602::print(const float f, uint8_t decimalPlaces)
// }

// /*******************************private*******************************/
esp_err_t DFRobot_RGBLCD1602::begin( uint8_t rows, uint8_t charSize)
esp_err_t DFRobot_RGBLCD1602::begin(uint8_t rows, uint8_t charSize)
{
if (rows > 1) {
if (rows > 1)
{
_showFunction |= LCD_2LINE;
}
_numLines = rows;
_currLine = 0;
///< for some 1 line displays you can select a 10 pixel high font
if ((charSize != 0) && (rows == 1)) {
if ((charSize != 0) && (rows == 1))
{
_showFunction |= LCD_5x10DOTS;
}

@@ -320,9 +348,9 @@ esp_err_t DFRobot_RGBLCD1602::begin( uint8_t rows, uint8_t charSize)

///< Send function set command sequence
command(LCD_FUNCTIONSET | _showFunction);
vTaskDelay(pdMS_TO_TICKS(5)); // wait more than 4.1ms
///< second try
vTaskDelay(pdMS_TO_TICKS(5)); // wait more than 4.1ms

///< second try
command(LCD_FUNCTIONSET | _showFunction);
vTaskDelay(pdMS_TO_TICKS(5));

@@ -340,17 +368,28 @@ esp_err_t DFRobot_RGBLCD1602::begin( uint8_t rows, uint8_t charSize)
_showMode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
///< set the entry mode
command(LCD_ENTRYMODESET | _showMode);

if(_RGBAddr == LCD_RGB_ADDRESS){
///< backlight init

if (_RGBAddr == LCD_RGB_ADDRESS)
{
///< backlight init
setReg(LCD_REG_MODE1, 0);
///< set LEDs controllable by both PWM and GRPPWM registers
setReg(LCD_REG_OUTPUT, 0xFF);
///< set MODE2 values
///< 0010 0000 -> 0x20 (DMBLNK to 1, ie blinky mode)
setReg(LCD_REG_MODE2, 0x20);
}else{
setReg(0x04, 0x15);
}
else if (_RGBAddr == 0x6B)
{
setReg(0x2F, 0x00);
setReg(0x00, 0x20);
setReg(0x01, 0x00);
setReg(0x02, 0x01);
setReg(0x03, 4);
}
else
{
setReg(0x04, 0x15);
}
setColorWhite();
return ESP_OK;
@@ -374,6 +413,6 @@ esp_err_t DFRobot_RGBLCD1602::setReg(uint8_t addr, uint8_t data)
ESP_LOGD(_TAG, "i2c_master_write_to_device(port:%i, addr:0x%02x, reg:0x%02x, data:0x%02x)", _i2c_num, _RGBAddr, addr, data);
const uint8_t write_buffer[] = {addr, data};
return i2c_master_write_to_device(_i2c_num, _RGBAddr,
write_buffer, 2,
LCD_COMMAND_DELAY_MS / portTICK_PERIOD_MS);
write_buffer, 2,
LCD_COMMAND_DELAY_MS / portTICK_PERIOD_MS);
}
37 changes: 30 additions & 7 deletions DFRobot_RGBLCD1602.h
Original file line number Diff line number Diff line change
@@ -10,6 +10,15 @@
*/

#pragma once
#ifdef ARDUINO
// #warning ARDIUNO defined
#if (ARDUINO >= 100)
// #warning ARDIUNO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#endif

// /*
// #include <inttypes.h>
@@ -24,7 +33,8 @@
*/
#define LCD_LCD_ADDRESS (0x7c >> 1)
#define LCD_RGB_ADDRESS_ALT (0x60 >> 1)
#define LCD_RGB_ADDRESS (0xc0 >> 1)
#define LCD_RGB_ADDRESS_ALT2 (0x6b ) // LCD1602 module V1.1
#define LCD_RGB_ADDRESS (0xc0 >> 1) // = 0x60. LCD1602 module V1.0 and LCD1602 RGB Module V1.0

/*!
* @brief color define
@@ -87,7 +97,11 @@
#define LCD_5x10DOTS 0x04
#define LCD_5x8DOTS 0x00

class DFRobot_RGBLCD1602 // : public Print --yeah don't know if I'll be able to extend Arduino's print
#ifdef ARDUINO
class DFRobot_RGBLCD1602 : public Print // TODO instead of this conditional , put my print() in it's own class
#else
class DFRobot_RGBLCD1602 // : public Print print implemented internally to class
#endif
{
private:
static constexpr const char *_TAG = "DFRobot_RGBLCD1602";
@@ -222,12 +236,20 @@ class DFRobot_RGBLCD1602 // : public Print --yeah don't know if I'll be able to
*/
esp_err_t setRGB(uint8_t r, uint8_t g, uint8_t b);

// /**
// * @brief set backlight PWM output
// * @param color backlight color Preferences:REG_RED\REG_GREEN\REG_BLUE
// * @param pwm color intensity range(0-255)
// */
// esp_err_t setPWM(uint8_t color, uint8_t pwm) {return setReg(color, pwm);} // set pwm

/**
* @brief set backlight PWM output
* @param color backlight color Preferences:REG_RED\REG_GREEN\REG_BLUE
* @param pwm color intensity range(0-255)
* @fn setPWM
* @brief set backlight PWM output
* @param color backlight color Preferences:REG_RED\REG_GREEN\REG_BLUE
* @param pwm color intensity range(0-255)
*/
esp_err_t setPWM(uint8_t color, uint8_t pwm) {return setReg(color, pwm);} // set pwm
void setPWM(uint8_t color, uint8_t pwm);

/**
* @brief backlight color
@@ -273,6 +295,7 @@ class DFRobot_RGBLCD1602 // : public Print --yeah don't know if I'll be able to
*/
esp_err_t setBacklight(bool mode);

#ifndef ARDUINO // roll our own print()
/**
* @brief write a single char
*
@@ -295,6 +318,7 @@ class DFRobot_RGBLCD1602 // : public Print --yeah don't know if I'll be able to
*
*/
void print(const float f, uint8_t decimalPlaces);
#endif // ARDUINO

private:
/**
@@ -319,5 +343,4 @@ class DFRobot_RGBLCD1602 // : public Print --yeah don't know if I'll be able to
uint8_t _RGBAddr;
uint8_t _cols;
uint8_t _rows;

};
Empty file added LiquidCrystal.h
Empty file.
Loading