/ html / wiki / microcontroller / codesnippets / esp32-i2c-lcd.html
esp32-i2c-lcd.html
  1  <!DOCTYPE html>
  2  <html lang="de">
  3     <head>
  4        <meta charset="UTF-8" />
  5        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6        <meta http-equiv="onion-location" content="http://bopbopl6lohkl2rts3ltesjnag4hzs4jrx2h6k6etgq5xasbpqekzlqd.onion" />
  7        <title>BOP Wiki: ESP32 I2C LCD Display (16x2 / 20x4)</title>
  8        <link rel="stylesheet" href="/assets/stylesheet.css" />
  9        <link rel="icon" type="image/x-icon" href="/assets/img/favicon.png">
 10     </head>
 11     <body>
 12         <header>
 13            <!-- --------------------------------------------------------------------------------------------------------------------------------- -->
 14            <script src="/assets/js/navbar-OpenClose.js"></script>
 15            <script src="/assets/js/lightbox.js"></script>
 16            <script src="/assets/js/copyCodeButton.js"></script>
 17            <link rel="stylesheet" href="/resources/js-libraries/highlightJS/atom-one-dark.min.css">
 18            <script src="/resources/js-libraries/highlightJS/highlight.min.js"></script>
 19            <script src="/resources/js-libraries/highlightJS/highlightjs-line-numbers.min.js"></script>
 20            <script>hljs.highlightAll();</script>
 21            <script>hljs.initLineNumbersOnLoad();</script>
 22            <!-- --------------------------------------------------------------------------------------------------------------------------------- -->
 23            <div class="branding">
 24               <button class="toggle-btn-navbar" id="navbarOpenButton">☰</button>
 25               <a href="/">
 26               <img class="logo" src="/assets/img/logo.png">
 27               </a>
 28               <div class="typing-animation">BytesOfProgress</div>
 29            </div>
 30         </header>
 31         <div id="navbarContainer" class="navbar-container">
 32            <iframe class="navbar-iframe" src="/assets/navbar/navbar.html" frameBorder= "0"></iframe>
 33         </div>
 34        <main>
 35  <!-- --------------------------------------------------------------------------------------------------------------------------------- -->
 36  
 37  <article class="site-post">
 38     <header class="post-header">
 39        <h1 class="post-title">ESP32 I2C LCD Display (16x2 / 20x4)</h1>
 40        <div class="post-meta">
 41        </div>
 42     </header>
 43  </article>
 44  
 45  <nav class="breadcrumb">
 46     <a href="/">Home</a>
 47     <span class="divider">›</span>
 48     <a href="/wiki/">Wiki</a>
 49     <span class="divider">›</span>
 50     <a href="/wiki/microcontroller/A1-microcontroller.html">Microcontroller</a>
 51     <span class="divider">›</span>
 52     <a href="/wiki/microcontroller/codesnippets/codesnippets.html">Code-Snippets</a>
 53     <span class="divider">›</span>
 54     <span class="current">ESP32 I2C LCD Display (16x2 / 20x4)</span>
 55  
 56  </nav>
 57  
 58  <section class="post-content">
 59  
 60  <!-- --------------------------------------------------------------------------------------------------------------------------------- -->
 61  
 62  <!-- --------------------------------------------------------------------------------------------------------------------------------- -->
 63  
 64  <p>
 65    Generally, the coordinate you want to print your string to, in its code form, is always n-1.
 66    That means if you want to display something on the 3rd cell of the second row,
 67    you declare cell 2 of row 1 in the code.
 68  </p>
 69  
 70  <p>
 71    This example uses a 20x4 display with the I2C address "0x27". The I2C address
 72    might vary depending on the display your are using. The most common ones are
 73    "0x27" and 0x3F".
 74  </p>
 75  
 76  <p>
 77    When using a 16x2 LCD, you have to change "LiquidCrystal_I2C lcd(0x27,20,4)"
 78    to "LiquidCrystal_I2C lcd(0x27,16,2)". This is also where you correct the
 79    I2C address if needed.
 80  </p>
 81  
 82  
 83  <div class="code-box">
 84    <pre><code>// Libraries
 85  #include &lt;Wire.h&gt;
 86  #include &lt;LiquidCrystal_I2C.h&gt;
 87  
 88  // Display data
 89  LiquidCrystal_I2C lcd(0x27,20,4);
 90  
 91  void setup() {
 92    lcd.init();
 93    lcd.backlight();
 94    lcd.clear();
 95  }
 96  
 97  void loop() {
 98    lcd.setCursor(4, 1);
 99    lcd.print(&quot;Hello World!&quot;);
100  }</code></pre>
101  </div>
102  
103  
104  
105  
106  
107  
108  <!-- --------------------------------------------------------------------------------------------------------------------------------- -->
109  
110  </section>
111  <footer class="post-footer">
112  <a href="/wiki/microcontroller/codesnippets/codesnippets.html" class="cta-button">← Back</a>
113  </footer>
114  </main>
115  </body>
116  </html>