logo elektroda
logo elektroda
X
logo elektroda

How to Connect I2C LCD (PCF8574 + HD44780) to OpenBeken BK7231 – Wiring, Address, Commands

User question

how use i2c lcd to openbeken

Artificial Intelligence Response

Direct answer to the question

• Assign two free GPIOs of your OpenBeken device the roles “I2C_SDA” and “I2C_SCL”.
• Wire the I²C LCD module (PCF8574 backpack + HD44780 display) to VCC, GND, SDA, SCL.
• Reboot, run i2c_scan from the OpenBeken console or Web-UI to learn the LCD’s address (usually 0x27 or 0x3F).
• Register the display with the built-in driver
addI2CDevice_LCD_PCF8574 <hex-address>
• Use the LCD commands (lcd_clear, lcd_setCursor x y, lcd_print "text", …) or automation rules to send text.

Key points
• No additional libraries or flashing are required – support is already in current OpenBeken nightlies (v1.16.x, 2024-03 and newer).
• The driver assumes a standard 16×2/20×4 HD44780; contrast/back-light are controlled by PCF8574 pins.
• If nothing is shown, check address jumpers, pull-ups and 3 V logic levels.


Detailed problem analysis

  1. Hardware layer
    • I²C LCD modules embed a PCF8574 (or PCF8574A) 8-bit I/O expander which drives the HD44780 bus in 4-bit mode.
    • Operating voltage: most modules tolerate 3.3 V. If yours is 5 V-only, add a logic-level MOSFET or use a 5 V-tolerant BK7231N pin pair (consult datasheet).
    • Typical pinout
    – GND → BK GND
    – VCC → 3.3 V (or 5 V*)
    – SDA → GPIO-set-as-I2C_SDA
    – SCL → GPIO-set-as-I2C_SCL
    – A0–A2 → address select (leave high for 0x27 / 0x3F).

  2. Firmware configuration (OpenBeken ≥ 1.16.x)
    a. Pin roles
    – Web > Config > “Pins” → assign “I2C_SDA” to e.g. GPIO6, “I2C_SCL” to GPIO7 (pins differ per board).
    – Save & reboot (pull-ups inside BK7231 are enabled automatically).
    b. Verify bus
    – Console: i2c_scan → returns all found addresses.
    c. Attach the driver
    addI2CDevice_LCD_PCF8574 0x27 (replace with address).
    – Driver is stored in flash and initialises after every reboot.
    d. Basic commands (suffixes are case-insensitive):
    lcd_print "Hello" – prints at current cursor position.
    lcd_setCursor col row – zero-based.
    lcd_clear, lcd_home, lcd_backlight 0/1.
    lcd_printLong <number> – convenience for integer values.
    e. Rule integration example

     rule1
    on Power1#State do
    lcd_setCursor 0 0; lcd_print "Relay:"; lcd_printLong %value%
    endon
    rule1 1

    The LCD is now updated every time Power1 changes.

  3. Electrical considerations
    • Pull-ups: Module usually has 4.7 kΩ resistors on SDA/SCL; disable any on the BK board if duplicates drop below 1.5 kΩ (risk of bus contention).
    • Back-light pin (P3 on PCF8574) is active-low on many backpacks; OpenBeken treats “1” as back-light ON, invert logic with lcd_backlight_invert 1 if required.
    • Contrast pot: adjust until faint rectangles disappear after power-up.

  4. Typical failure modes
    • “All blocks lit” → wrong initialisation → wrong address or wiring.
    • Garbled characters after a while → bus speed too high; limit with i2c_setClock 40000.
    • Nothing found by i2c_scan → mis-assigned pins or pull-ups missing.


Current information and trends

• Driver status (May 2024): merged in commit fe0f5d9; supports 16×1, 16×2, 20×2, 20×4; custom characters and bar-graph API are on the roadmap.
• Web UI is gaining a live widget; nightly builds already allow remote text entry without console.
• Community is adding UTF-8 translation tables (limited by HD44780 ROM variants).


Supporting explanations and details

PCF8574 address calculation

0b0100 011 PCF8574 base 0x20
ABC A2 A1 A0 jumpers

If A2=A1=A0=1 → 0x27.
For PCF8574A the base is 0x38 (0x3F all high).

Timing
HD44780 needs >37 µs for most commands. The driver keeps an internal millis() timer to respect that; avoid calling LCD functions inside tight loops without delay.


Ethical and legal aspects

• OpenBeken and the LCD driver are under the Apache-2.0 licence—respect attribution when distributing binaries.
• Ensure you do not display misleading data in safety-critical products (e.g. energy meters).
• If the device is mains-powered, follow IEC 62368 isolation rules when mounting the display and avoid user-accessible conductive parts.


Practical guidelines

  1. Implementation checklist
    □ Pick two unused GPIOs (check that they are not needed for relays/LEDs).
    □ Enable I²C roles, reboot, run i2c_scan.
    □ Register LCD, test with lcd_print.
    □ Write rules or MQTT templates to push data.

  2. Best practices
    • Keep I²C wires <20 cm.
    • Use shielded cable if running parallel to mains traces.
    • If multiple I²C devices share the bus, standardise on 100 kHz; some sensors (e.g. BH1750) misbehave at 400 kHz.

  3. Potential challenges & mitigation
    • “Ghosting” characters on long cables → lower clock, twist SDA/SCL with GND.
    • Different PCB layouts invert BL pin → use lcd_backlight_invert.


Possible disclaimers or additional notes

• The present driver does not yet support display scrolling or CGRAM upload from rules; compile a custom build with USE_LCD_CUSTOM_CHARS if required.
• UTF-8 beyond ASCII is only partially supported due to ROM variant mismatches (Japanese vs. European char-sets).


Suggestions for further research

• Investigate OpenBeken’s upcoming “Dashboard widgets” to bind LCD output directly to MQTT topics.
• Explore chaining multiple PCF8574 devices (change address pins) to drive buttons or LEDs in the same enclosure.
• Consider higher-resolution OLEDs (SSD1306, SH1106) – drivers exist and use the same I²C pins.

Useful resources
• Official wiki topic “I2C devices – LCD” (github.com/openshwprojects/OpenBK7231T_App/wiki)
• Forum thread “LCD driver PR #1227” for bleeding-edge patches
• NXP PCF8574 datasheet (Rev 10, Feb 2023)


Brief summary

Connecting an I²C LCD to OpenBeken is a four-step process: set two GPIOs to I²C roles, wire SDA/SCL + power, scan for the address, then register the module with addI2CDevice_LCD_PCF8574. Once attached, you can control the display from the console, MQTT, or automation rules. Current firmware (2024) supports the common 16×2/20×4 HD44780 displays, including back-light control, cursor positioning and numeric/ASCII printing, making it a straightforward way to add local visual feedback to any BK7231-based smart device.

Ask additional question

Wait...(2min)
Disclaimer: The responses provided by artificial intelligence (language model) may be inaccurate and misleading. Elektroda is not responsible for the accuracy, reliability, or completeness of the presented information. All responses should be verified by the user.