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 diff --git a/RPLCD/i2c.py b/RPLCD/i2c.py index 6ff5de8..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']: + 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,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 == 'JHD1804': + 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 == 'JHD1804': + 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..97fb8f9 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 != 'JHD1804': + 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)