Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enabling Grove - 16x2 LCD (JHD1804) #136

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion RPLCD/i2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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':
Expand All @@ -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."""
Expand Down
37 changes: 19 additions & 18 deletions RPLCD/lcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not applicable to the JHD1804? The way I understand it, a port expander only forwards the commands to the hitachi chip.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this line doesn't work, see tests

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not an ordinary i2c expander, but a full driver with built-in i2c, a replacement for the hitachi chip, usually compatible, but the initialization looks different because you do not need to set the 4 or 8 bit communication function:
obraz

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line doesn't work in tests, but it works in reality. the value of _i2c_expander comes from the CharLCD class, the same as e.g. in the next line if self.data_bus_mode == c.LCD_4BITMODE:, with the difference that data_bus_mode is always defined self.data_bus_mode = c.LCD_4BITMODE (line 153 in i2c.py) while the expander must be defined when creating the object:

if i2c_expander in ['PCF8574', 'MCP23008', 'MCP23017', 'JHD1802']:
 self._i2c_expander = i2c_expander
 else:
 raise NotImplementedError('I2C expander "%s" is not supported.' % i2c_expander)

(i2c.py 131 to 134)
I don't see an expander defined anywhere in the tests, but the object creation still goes through?

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)
Expand Down
Loading