From 03252fb00a513524862de69b970d94c5dcbeb83a Mon Sep 17 00:00:00 2001 From: Kamil Dybka Date: Thu, 11 Jul 2024 13:20:51 +0200 Subject: [PATCH 1/3] enabling Grove - 16x2 LCD (JHD1804) --- RPLCD/i2c.py | 8 +++++++- RPLCD/lcd.py | 37 +++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/RPLCD/i2c.py b/RPLCD/i2c.py index 6ff5de8..a2ff78b 100644 --- a/RPLCD/i2c.py +++ b/RPLCD/i2c.py @@ -128,7 +128,7 @@ def __init__(self, i2c_expander, address, expander_params=None, port=1, self._port = port # Set i2c expander, 'PCF8574', 'MCP23008' and 'MCP23017' are supported. - if i2c_expander in ['PCF8574', 'MCP23008', 'MCP23017']: + if i2c_expander in ['PCF8574', 'MCP23008', 'MCP23017', "JHD1802"]: self._i2c_expander = i2c_expander else: raise NotImplementedError('I2C expander "%s" is not supported.' % i2c_expander) @@ -230,6 +230,9 @@ def _send_data(self, value): self._mcp_data |= MCP230XX_RS self._pulse_data(value >> 4) self._pulse_data(value & 0x0F) + elif self._i2c_expander == 'JHD1802': + self.bus.write_byte_data(self._address, 0xC0, value) + c.usleep(100) def _send_instruction(self, value): if self._i2c_expander == 'PCF8574': @@ -243,6 +246,9 @@ def _send_instruction(self, value): self._mcp_data &= ~MCP230XX_RS self._pulse_data(value >> 4) self._pulse_data(value & 0x0F) + elif self._i2c_expander == 'JHD1802': + self.bus.write_byte_data(self._address, 0x80, value) + c.usleep(100) def _pulse_data(self, value): """Pulse the `enable` flag to process value.""" diff --git a/RPLCD/lcd.py b/RPLCD/lcd.py index 83f8b95..f6228aa 100644 --- a/RPLCD/lcd.py +++ b/RPLCD/lcd.py @@ -94,24 +94,25 @@ def __init__(self, cols=20, rows=4, dotsize=8, charmap='A02', auto_linebreaks=Tr self._init_connection() # Choose 4 or 8 bit mode - if self.data_bus_mode == c.LCD_4BITMODE: - # Hitachi manual page 46 - self.command(0x03) - c.msleep(4.5) - self.command(0x03) - c.msleep(4.5) - self.command(0x03) - c.usleep(100) - self.command(0x02) - elif self.data_bus_mode == c.LCD_8BITMODE: - # Hitachi manual page 45 - self.command(0x30) - c.msleep(4.5) - self.command(0x30) - c.usleep(100) - self.command(0x30) - else: - raise ValueError('Invalid data bus mode: {}'.format(self.data_bus_mode)) + if self._i2c_expander != 'JHD1802': + if self.data_bus_mode == c.LCD_4BITMODE: + # Hitachi manual page 46 + self.command(0x03) + c.msleep(4.5) + self.command(0x03) + c.msleep(4.5) + self.command(0x03) + c.usleep(100) + self.command(0x02) + elif self.data_bus_mode == c.LCD_8BITMODE: + # Hitachi manual page 45 + self.command(0x30) + c.msleep(4.5) + self.command(0x30) + c.usleep(100) + self.command(0x30) + else: + raise ValueError('Invalid data bus mode: {}'.format(self.data_bus_mode)) # Write configuration to display self.command(c.LCD_FUNCTIONSET | displayfunction) From 0343f86275838aa9b93440accb1be5726aed3dd7 Mon Sep 17 00:00:00 2001 From: Kamil Dybka Date: Thu, 11 Jul 2024 13:30:48 +0200 Subject: [PATCH 2/3] update readme --- README.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.rst b/README.rst index 13d7e1a..ff07739 100644 --- a/README.rst +++ b/README.rst @@ -92,6 +92,7 @@ Supported I²C Port Expanders - PCF8574 (used by a lot of I²C LCD adapters on Ali Express) - MCP23008 (used in Adafruit I²C LCD backpack) - MCP23017 +- JHD1804 (with AIP31068L controller, used in Grove - 16x2 LCD) Documentation @@ -147,6 +148,8 @@ Resources - TC2004A-01 Data Sheet: http://www.adafruit.com/datasheets/TC2004A-01.pdf - HD44780U Data Sheet: http://www.adafruit.com/datasheets/HD44780.pdf - ST7066 Data Sheet: https://www.sparkfun.com/datasheets/LCD/st7066.pdf +- JHD1804 Data Sheet: https://raw.githubusercontent.com/SeeedDocument/Grove-16x2_LCD_Series/master/res/JDH_1804_Datasheet.pdf +- AIP31068L Data Sheet: https://www.orientdisplay.com/wp-content/uploads/2022/08/AIP31068L.pdf License From a6e331fe12e2865a77fb3c6db1c488544f2f6eda Mon Sep 17 00:00:00 2001 From: Kamil Dybka Date: Thu, 11 Jul 2024 13:38:17 +0200 Subject: [PATCH 3/3] fix typo --- RPLCD/i2c.py | 6 +++--- RPLCD/lcd.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/RPLCD/i2c.py b/RPLCD/i2c.py index a2ff78b..08cf249 100644 --- a/RPLCD/i2c.py +++ b/RPLCD/i2c.py @@ -128,7 +128,7 @@ def __init__(self, i2c_expander, address, expander_params=None, port=1, self._port = port # Set i2c expander, 'PCF8574', 'MCP23008' and 'MCP23017' are supported. - if i2c_expander in ['PCF8574', 'MCP23008', 'MCP23017', "JHD1802"]: + if i2c_expander in ['PCF8574', 'MCP23008', 'MCP23017', "JHD1804"]: self._i2c_expander = i2c_expander else: raise NotImplementedError('I2C expander "%s" is not supported.' % i2c_expander) @@ -230,7 +230,7 @@ def _send_data(self, value): self._mcp_data |= MCP230XX_RS self._pulse_data(value >> 4) self._pulse_data(value & 0x0F) - elif self._i2c_expander == 'JHD1802': + elif self._i2c_expander == 'JHD1804': self.bus.write_byte_data(self._address, 0xC0, value) c.usleep(100) @@ -246,7 +246,7 @@ def _send_instruction(self, value): self._mcp_data &= ~MCP230XX_RS self._pulse_data(value >> 4) self._pulse_data(value & 0x0F) - elif self._i2c_expander == 'JHD1802': + elif self._i2c_expander == 'JHD1804': self.bus.write_byte_data(self._address, 0x80, value) c.usleep(100) diff --git a/RPLCD/lcd.py b/RPLCD/lcd.py index f6228aa..97fb8f9 100644 --- a/RPLCD/lcd.py +++ b/RPLCD/lcd.py @@ -94,7 +94,7 @@ def __init__(self, cols=20, rows=4, dotsize=8, charmap='A02', auto_linebreaks=Tr self._init_connection() # Choose 4 or 8 bit mode - if self._i2c_expander != 'JHD1802': + if self._i2c_expander != 'JHD1804': if self.data_bus_mode == c.LCD_4BITMODE: # Hitachi manual page 46 self.command(0x03)