<h2>I2C connection</h2>
<p>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.</p>
<h3>G-code</h3>
<p><em>This seems experimental, and possibly suffering from a lack of documentation</em>.</p>
<p>There are two G-code commands, <a href="https://M260%20-%20I2C%20Send" rel="nofollow noreferrer"><code>M260</code> - I2C Send</a> and <a href="https://marlinfw.org/docs/gcode/M261.html" rel="nofollow noreferrer"><code>M261</code> - I2C Request</a> that require <code>EXPERIMENTAL_I2CBUS</code>. 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).</p>
<h3>configuration.h</h3>
<p><em>This seems to be most promising option</em>.</p>
<p>The Marlin configuration page, <a href="https://marlinfw.org/docs/configuration/configuration.html" rel="nofollow noreferrer">Configuring Marlin</a>, shows two interesting tables for I2C displays:</p>
<p><a href="https://i.sstatic.net/gIQFp.png" rel="nofollow noreferrer" title="I2C LED display tables"><img src="https://i.sstatic.net/gIQFp.png" alt="I2C LED display tables" title="I2C LED display tables" /></a></p>
<p>This is the <a href="https://github.com/kiyoshigawa/LiquidCrystal_I2C" rel="nofollow noreferrer">LiquidCrystal I2C library</a> that is referred to above each table.</p>
<h3>A Marlin issue on Github</h3>
<p><em>This also seems hopeful</em>.</p>
<p>This <a href="https://github.com/MarlinFirmware/Marlin/issues/10399" rel="nofollow noreferrer">post</a> on <a href="https://github.com/MarlinFirmware/Marlin/issues/10399" rel="nofollow noreferrer">I2C in Arduino for Marlin #10399</a>,</p>
<blockquote>
<ol>
<li><p>It's not too intensive. Many peripherals use i2c.</p>
</li>
<li><p>Marlin uses Wire on most platforms. Enable <code>EXPERIMENTAL_I2CBUS</code> for a simplified interface in Marlin, and check out this thread (<a href="https://github.com/MarlinFirmware/Marlin/issues/4776#issuecomment-246262879" rel="nofollow noreferrer">Dual Serial Port #4776 (comment)</a>) for insights into using i2c to talk to a second board.</p>
</li>
<li><p>Yes, you can send data over i2c anytime. See the aforementioned thread for more insights into using the <code>EXPERIMENTAL_I2CBUS</code> to test i2c communication.</p>
</li>
</ol>
</blockquote>
<h3>A working example</h3>
<p><em>This option might be overkill</em>.</p>
<p>This blog, <a href="http://blog.think3dprint3d.com/2013/01/i2c-and-marlin.html" rel="nofollow noreferrer">I2C Port Expander &amp; LCD working with Marlin</a>, actually has a working example of an I2C 2004 LCD. It also lists the changes required for <code>configuration.h</code></p>
<p>However, unfortunately, it requires an additional DIY I2C port expander PCB, which employs a MCP23017, which is detailed here, <a href="http://blog.think3dprint3d.com/2012/12/mcp23017-i2c.html" rel="nofollow noreferrer">I2C port expander driving an LCD screen, click encoder and more</a>.</p>
<p><a href="https://i.sstatic.net/skCox.png" rel="nofollow noreferrer" title="Schematic"><img src="https://i.sstatic.net/skCox.png" alt="Schematic" title="Schematic" /></a></p>
<p>An example of the revised v2.1 PCB is shown in a subsequent blog, <a href="http://blog.think3dprint3d.com/2013/02/panelolu2.html" rel="nofollow noreferrer">Panelolu2</a></p>
<p><a href="https://i.sstatic.net/239mK.jpg" rel="nofollow noreferrer" title="Photo of PCB"><img src="https://i.sstatic.net/239mK.jpg" alt="Photo of PCB" title="Photo of PCB" /></a></p>
<p>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).</p>
<h2>Non-I2C connection</h2>
<p>According to <a href="https://reprap.org/forum/read.php?146,189158,189787#msg-189787" rel="nofollow noreferrer">this post</a> on the RepRap forums, <a href="https://reprap.org/forum/read.php?146,189158" rel="nofollow noreferrer">MARLIN - generic LCD 16x2 (Megatronics 2 board)</a>, the pins are defined in <a href="https://github.com/MarlinFirmware/Marlin/blob/bugfix-2.1.x/Marlin/src/pins/pins.h" rel="nofollow noreferrer"><code>../Marlin/src/pins/pins.h</code></a> (the name of the file is a bit of a giveaway).</p>
<hr />
<p>The following <em>might</em> 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.</p>
<p>For the Megatronics 2 board the lines and pin numbers seem to be as follows (from the <a href="https://reprap.org/forum/read.php?146,189158,190062#msg-190062" rel="nofollow noreferrer">final post</a>):</p>
<blockquote>
<p>what it is now in Marlin:</p>
<pre><code>#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
*/ 
</code></pre>
<p>what it should be:</p>
<pre><code>#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  
</code></pre>
</blockquote>
<p>Worth noting from <a href="https://reprap.org/forum/read.php?146,189158,189229#msg-189229" rel="nofollow noreferrer">this post</a>:</p>
<blockquote>
<p>I think the ULTRA_LCD is not the same as a generic 16x2 lcd without buttons.</p>
</blockquote>
<hr />
<h3>Additional reading</h3>
<p>Another link (on the same forum) that may be useful is <a href="https://reprap.org/forum/read.php?415,885957" rel="nofollow noreferrer">How Do I Configure Pinouts For A LCD</a>.</p>

CC BY-SA 4.0
2022-11-29T06:06:28.753Z
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.
CryptoAlgorithm
CC BY-SA 4.0
2022-11-29T16:41:58.190Z
I've updated my answer with some I2C stuff that I found, but you've probably seen them already.
Greenonline
CC BY-SA 4.0
2022-11-28T21:21:03.693Z
2022-12-01T18:43:47.057Z
2022-12-01T18:43:47.057Z
Greenonline
<p>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.</p>
<p>In <code>Configuration.h</code>, there's an option for a &quot;Generic LCM1602 LCD adapter&quot;, 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.</p>
<p>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!</p>

CC BY-SA 4.0
2022-12-01T15:08:45.660Z
If you do find a solution, please post the answer here, as it will probably help others with a similar issue.
Greenonline
<marlin><lcd-screen>
Configuring HD44780 LCD with I2C backpack in Marlin
CryptoAlgorithm
# Configuring HD44780 LCD with I2C backpack in Marlin

(Asked by: username_0 on 2022-11-28)

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!

**Tags:** marlin, lcd-screen

> **Comments:**
> **username_1**: If you do find a solution, please post the answer here, as it will probably help others with a similar issue.  

---

## 1 answers

### Answer by username_1 on 2022-11-28. Score: 3

## 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.

### G-code

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

There are two G-code commands, [`M260` - I2C Send](https://M260%20-%20I2C%20Send) and [`M261` - I2C Request](https://marlinfw.org/docs/gcode/M261.html) 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).

### configuration.h

*This seems to be most promising option*.

The Marlin configuration page, [Configuring Marlin](https://marlinfw.org/docs/configuration/configuration.html), shows two interesting tables for I2C displays:

[![I2C LED display tables](https://i.sstatic.net/gIQFp.png "I2C LED display tables")](https://i.sstatic.net/gIQFp.png "I2C LED display tables")

This is the [LiquidCrystal I2C library](https://github.com/kiyoshigawa/LiquidCrystal_I2C) that is referred to above each table.

### A Marlin issue on Github

*This also seems hopeful*.

This [post](https://github.com/MarlinFirmware/Marlin/issues/10399) on [I2C in Arduino for Marlin #10399](https://github.com/MarlinFirmware/Marlin/issues/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)](https://github.com/MarlinFirmware/Marlin/issues/4776#issuecomment-246262879)) 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](http://blog.think3dprint3d.com/2013/01/i2c-and-marlin.html), 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](http://blog.think3dprint3d.com/2012/12/mcp23017-i2c.html).

[![Schematic](https://i.sstatic.net/skCox.png "Schematic")](https://i.sstatic.net/skCox.png "Schematic")

An example of the revised v2.1 PCB is shown in a subsequent blog, [Panelolu2](http://blog.think3dprint3d.com/2013/02/panelolu2.html)

[![Photo of PCB](https://i.sstatic.net/239mK.jpg "Photo of PCB")](https://i.sstatic.net/239mK.jpg "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](https://reprap.org/forum/read.php?146,189158,189787#msg-189787) on the RepRap forums, [MARLIN - generic LCD 16x2 (Megatronics 2 board)](https://reprap.org/forum/read.php?146,189158), the pins are defined in [`../Marlin/src/pins/pins.h`](https://github.com/MarlinFirmware/Marlin/blob/bugfix-2.1.x/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](https://reprap.org/forum/read.php?146,189158,190062#msg-190062)):

> 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](https://reprap.org/forum/read.php?146,189158,189229#msg-189229):

> 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](https://reprap.org/forum/read.php?415,885957).

> **Comments:**
> **username_0**: 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.  
> **username_1**: I've updated my answer with some I2C stuff that I found, but you've probably seen them already.  

---

