I'm making a custom control board based on an ESP32, and I'm currently stuck at trying to configure a 16x2 LCD in Marlin.

In Configuration.h, there's an option for a "Generic LCM1602 LCD adapter", which I've commented out. However, after searching thru everywhere in the source that came to my mind, I've yet to find any option for specifying the I2C pins or address the LCD backpack/adapter is connected to.

Could someone point me in the right direction, or where the LCD is instantiating, so I can modify the respective lines to make it work with my LCD? Any help would be greatly appreciated!

  • $\begingroup$ If you do find a solution, please post the answer here, as it will probably help others with a similar issue. $\endgroup$
    – Greenonline
    Dec 1, 2022 at 15:08

1 Answer 1


I2C connection

I may have not researched enough, or maybe I've mis-read various articles, but using I2C would seem to be (much) more tricky that a straightforward non-I2C connection, and might be a project unto itself. Unless you have a lot of time on your hands - or a need to minimise the number of pins used - it might not be worth the bother, and using a regular 1602 display instead probably makes more sense.


This seems experimental, and possibly suffering from a lack of documentation.

There are two G-code commands, M260 - I2C Send and M261 - I2C Request that require EXPERIMENTAL_I2CBUS. The second link refers to an I2C master/slave article, by unfortunately, no link is provided (Ed. - if someone knows the link, then please edit it in).


This seems to be most promising option.

The Marlin configuration page, Configuring Marlin, shows two interesting tables for I2C displays:

I2C LED display tables

This is the LiquidCrystal I2C library that is referred to above each table.

A Marlin issue on Github

This also seems hopeful.

This post on I2C in Arduino for Marlin #10399,

  1. It's not too intensive. Many peripherals use i2c.

  2. Marlin uses Wire on most platforms. Enable EXPERIMENTAL_I2CBUS for a simplified interface in Marlin, and check out this thread (Dual Serial Port #4776 (comment)) for insights into using i2c to talk to a second board.

  3. Yes, you can send data over i2c anytime. See the aforementioned thread for more insights into using the EXPERIMENTAL_I2CBUS to test i2c communication.

A working example

This option might be overkill.

This blog, I2C Port Expander & LCD working with Marlin, actually has a working example of an I2C 2004 LCD. It also lists the changes required for configuration.h

However, unfortunately, it requires an additional DIY I2C port expander PCB, which employs a MCP23017, which is detailed here, I2C port expander driving an LCD screen, click encoder and more.


An example of the revised v2.1 PCB is shown in a subsequent blog, Panelolu2

Photo of PCB

This requirement of additional hardware maybe more that you had expected. However, you could just use a breadboard to make this interface board (port expander).

Non-I2C connection

According to this post on the RepRap forums, MARLIN - generic LCD 16x2 (Megatronics 2 board), the pins are defined in ../Marlin/src/pins/pins.h (the name of the file is a bit of a giveaway).

The following might be useful as it shows the lines to change... but it obviously depends upon your board and upon whether your 1602 LCD has buttons or not.

For the Megatronics 2 board the lines and pin numbers seem to be as follows (from the final post):

what it is now in Marlin:

#define SHIFT_CLK 38
#define SHIFT_LD 42
#define SHIFT_OUT 40
#define SHIFT_EN 17

#define LCD_PINS_RS 16
#define LCD_PINS_ENABLE 17
#define LCD_PINS_D4 23
#define LCD_PINS_D5 25
#define LCD_PINS_D6 27
#define LCD_PINS_D7 29

what it should be:

#define SHIFT_CLK 63
#define SHIFT_LD 42
#define SHIFT_OUT 17
#define SHIFT_EN 7

#define LCD_PINS_RS 14
#define LCD_PINS_ENABLE 15
#define LCD_PINS_D4 30
#define LCD_PINS_D5 31
#define LCD_PINS_D6 32
#define LCD_PINS_D7 33  

Worth noting from this post:

I think the ULTRA_LCD is not the same as a generic 16x2 lcd without buttons.

Additional reading

Another link (on the same forum) that may be useful is How Do I Configure Pinouts For A LCD.

  • 2
    $\begingroup$ Thanks for the answer! However, those instructions are for a standard 16x2 LCD without the I2C adapter. They don't work with the I2C adapter as a completely different library would need to be used, and the "Generic LCM1602 LCD adapter" option was the only one remotely close to what I was using. $\endgroup$ Nov 29, 2022 at 6:06
  • 1
    $\begingroup$ I've updated my answer with some I2C stuff that I found, but you've probably seen them already. $\endgroup$
    – Greenonline
    Nov 29, 2022 at 16:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .