This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| en:iot-open:practical:hardware:taltech:arduino:scenarios:lcd [2025/06/25 08:55] – created raivo.sell | en:iot-open:practical:hardware:taltech:arduino:scenarios:lcd [2025/09/02 11:42] (current) – raivo.sell | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== LCD ====== | + | < |
| + | ====== | ||
| + | {{: | ||
| + | |||
| + | An alphanumeric LCD is a straightforward and widely used output device in embedded systems and IoT applications. The LCD used here has a fixed organization of 2 lines and 16 characters per line (2x16). | ||
| + | |||
| + | This scenario guides you through displaying text on the LCD using Arduino. | ||
| + | |||
| + | ===== Prerequisites ===== | ||
| + | * Familiarize yourself with the Arduino hardware reference. | ||
| + | * Install the LiquidCrystal library (built-in Arduino library). | ||
| + | |||
| + | ===== Hardware Connections ===== | ||
| + | ^ LCD Pin ^ Arduino Pin ^ | ||
| + | | RS | 8 | | ||
| + | | EN | 9 | | ||
| + | | D4 | 4 | | ||
| + | | D5 | 5 | | ||
| + | | D6 | 6 | | ||
| + | | D7 | 7 | | ||
| + | | Buttons Input | A0 | | ||
| + | |||
| + | |||
| + | ===== Task ===== | ||
| + | Display the text "Hello World" on the first line and "Hello IoT" on the second line of the LCD. | ||
| + | |||
| + | ===== Steps ===== | ||
| + | |||
| + | === Step 1: Include Library === | ||
| + | Add the LCD library to your Arduino sketch: | ||
| + | <code c> | ||
| + | #include < | ||
| + | </ | ||
| + | |||
| + | === Step 2: Declare GPIO Pins === | ||
| + | Define GPIO pins connected to LCD control lines: | ||
| + | <code c> | ||
| + | const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7; | ||
| + | </ | ||
| + | |||
| + | === Step 3: Initialize LCD === | ||
| + | Create an instance of the LCD: | ||
| + | <code c> | ||
| + | LiquidCrystal lcd(rs, en, d4, d5, d6, d7); | ||
| + | </ | ||
| + | |||
| + | Set up the display dimensions (2 rows, 16 columns): | ||
| + | <code c> | ||
| + | lcd.begin(16, | ||
| + | </ | ||
| + | |||
| + | === Step 4: Display Text === | ||
| + | Write text to the LCD screen: | ||
| + | <code c> | ||
| + | lcd.setCursor(0, | ||
| + | lcd.print(" | ||
| + | |||
| + | lcd.setCursor(0, | ||
| + | lcd.print(" | ||
| + | </ | ||
| + | |||
| + | ===== Validation ===== | ||
| + | The LCD should clearly display "Hello World" on line 1 and "Hello IoT" on line 2. | ||
| + | |||
| + | ===== Useful Methods ===== | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | ===== Troubleshooting ===== | ||
| + | If the LCD shows incorrect characters or nothing: | ||
| + | - Double-check wiring and pin assignments. | ||
| + | - Verify correct initialization (`lcd.begin(16, | ||
| + | - Adjust the contrast potentiometer on the LCD, if available. | ||