Testing / Displays / 01
LCD Hello World
Bring a 16×2 character display to life, then replace text without clearing the screen.
All 3 stages compiled 2026-10-19 (historical) · hardware review required
What you'll build
Initialize a verified backpack and show a two-line greeting.
First result after hardware review: Engineering Club / Hello, LCD after successful initialization.
What you need
Check availability and exact module markings before starting.
Connections / current hardware gate
Before connecting power. The LCD backpack supply and pull-up rail are unresolved. Confirm its expander and pin mapping before powering it; the program stops until electrical review is complete.
- Read the backpack IC marking and confirm compatibility with hd44780_I2Cexp.
- Verify VCC, ground and the SDA/SCL pull-up rail. The conditional Mega reference uses D20/SDA and D21/SCL; it does not approve a supply voltage.
- Keep kElectricalReviewComplete false until the actual wiring and power review is recorded.
Start building
- 1
First characters
Initialize a verified backpack and show a two-line greeting.
- 2
Changing values
Replace the second row with an elapsed-seconds counter.
- 3
Stable page updates
Alternate complete fixed-width messages without repeated clear.
Download complete PlatformIO project
Each stage has its exact environment, complete source and expected result. Editor and tools setup →
Troubleshooting
Backlight, no text
Check the contrast adjustment and startup Serial status separately. A lit backlight proves neither bus traffic nor LCD initialization. Run the I²C diagnostic before changing application formatting.
Library cannot initialize
Record the error code, scan address and backpack IC marking. A successful ACK with unsupported expander mapping still cannot establish a working LCD.
Old characters remain
Confirm the fixed-width row helper is used rather than printing a shorter replacement onto existing characters. Check the zero-based row selection and sixteen-cell limit.
More detail
Foundations, safety and learning objectives
110 minutes · Editorial learning estimate excluding unresolved procurement/driver-port time
Three actual PlatformIO firmware environments; embedded compile and bench verification unestablished.
- Keep electrical review false until the exact wiring/power/logic checklist is completed.
- No power budget is inferred from successful compilation.
- Bring a 16×2 character display to life, then replace text without clearing the screen.
- The LCD has character cells rather than a freely addressable pixel canvas.
No earlier Displays project is required.
System diagram and electrical boundaries
Show the meaningful subsystem and signal/power boundary for LCD Hello World. Conceptual system view; physical connections remain conditional.
- ELEGOO Mega 2560 R3 boardClub-owned
- LCD1602 16×2 Character Display with I²C BackpackClub-owned
Signals and interfaces
- LCD1602 16×2 Character Display with I²C BackpackI2C SDAELEGOO Mega 2560 R3 boardConditional reference
- LCD1602 16×2 Character Display with I²C BackpackI2C SCLELEGOO Mega 2560 R3 boardConditional reference
Power and common reference boundary
- display/peripheralSignal referencecontrollerConditional reference
- display/peripheralPeripheral powerverified supplyConditional reference
Interfaces: GPIO · I2C
Electrical boundaries and interpretation
- Use conditional wiring records; null pin/voltage means unresolved, not permission to choose a value.
- Draw power and logic paths separately.
- Do not turn a reference signal label into a guessed connector position.
- Keep member, club and campus access labels distinct.
- Include explicit port gate for unresolved driver/identity.
- Access scopes: CLUB_OWNED.
- Firmware source is not bench evidence.
Full hardware facts and conditional wiring reference
Access describes the source of a requirement. Check availability, the exact revision and the complete power/driver/harness system before starting. Inventory quantities are expected purchase/BOM quantities, not live stock.
product family verified · preflight required
Compatibility and unresolved details
- Display: 16 × 2 characters
- Interface: I²C backpack; exact expander revision not asserted
- ELEGOO Mega 2560 R3 boardClub-owned
product family verified · preflight required
Electrical review is incomplete. Conditional references require confirmation; unresolved pins or rails are not wiring instructions. Power off before changing connections.
| From device / pin | To device / pin | Signal / voltage | Connection status and notes |
|---|---|---|---|
LCD1602 16×2 Character Display with I²C BackpackSDA | ELEGOO Mega 2560 R3 boardD20 / SDA | I2C SDA Voltage unresolved | Conditional reference Verify backpack IC, carrier supply and pull-up rail before enabling. |
LCD1602 16×2 Character Display with I²C BackpackSCL | ELEGOO Mega 2560 R3 boardD21 / SCL | I2C SCL Voltage unresolved | Conditional reference Mega mapping; not Uno A4/A5. |
display/peripheralGND | controllerGND | Signal reference 0 V | Conditional reference Unpowered wiring check; use correct common-ground topology and keep high-current panel returns out of thin signal paths. |
display/peripheralVCC | verified supplyPin unresolved | Peripheral power Voltage unresolved | Conditional reference Supply voltage/current unknown at carrier level until reviewed; no assumed 5 V or 3.3 V instruction. |
All source files, supporting libraries and project download
Download complete project · workspaces/lcd-hello-world
Open the extracted folder containing platformio.ini and keep the complete supporting files.
duinoWitchery/hd44780@1.3.2
workspaces/lcd-hello-world/src/main.cpp
#include <Arduino.h>
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
#include <DisplayCore.h>
#include "board_profile.h"
hd44780_I2Cexp lcd;
bool ready=false;
uint32_t lastUpdate=0;
void row(uint8_t r,const char* text){lcd.setCursor(0,r);char padded[17];uint8_t i=0;for(;i<16&&text[i];++i)padded[i]=text[i];for(;i<16;++i)padded[i]=' ';padded[16]='\0';lcd.print(padded);}
void setup(){Serial.begin(115200); if(!kElectricalReviewComplete){Serial.println("STOP: complete wiring/power review in guide before enabling hardware.");return;}Wire.begin();const int status=lcd.begin(16,2);if(status){Serial.print("LCD initialization error: ");Serial.println(status);return;}ready=true;}
void loop(){if(!ready)return;const uint32_t now=millis();
if(!displaylab::elapsed(now,lastUpdate,1000))return;lastUpdate=now;
row(0,"Engineering Club");
#if DISPLAY_STAGE == 1
row(1,"Hello, LCD");
#elif DISPLAY_STAGE == 2
char line[17];snprintf(line,sizeof(line),"Seconds:%lu",(unsigned long)(now/1000));row(1,line);
#else
const bool page=((now/3000)%2)!=0;row(1,page?"16 cols, 2 rows":"No clear flicker");
#endif
}
Source integrity · SHA-256
3848f848671ff0237ba4ff9c96068793b8ccd6ba8493032b166a18ca8ec1fa91Raw downloads and standalone ZIPs retain the canonical bytes and supporting files. Copy follows the selected Comments setting.
Original engineering guide
Original research wording is preserved. Use the stage-specific dated build evidence for later compile results; it does not establish physical behavior.
Bring a 16×2 character display to life, then replace text without clearing the screen.
Status: FIRMWARE_AUTHORED_UNVERIFIED. FIRMWARE_SOURCE_AUTHORED; embedded build UNVERIFIED; hardware NOT_TESTED. Three actual PlatformIO firmware environments; embedded compile and bench verification unestablished.
What you are building
The LCD has character cells rather than a freely addressable pixel canvas. Its controller selects glyphs; a backlight makes the liquid-crystal modulation visible. The I²C backpack translates two-wire transactions into the controller’s parallel control/data signals. The LCD controller and the backpack expander are different chips. An address identifies a responder on the bus, not its screen dimensions or glyph repertoire.
Before you start
Estimated learning time: 110 minutes, excluding unresolved hardware/port work. Required prerequisites: orientation only. See PLATFORMIO_ORIENTATION.md and the hardware identity/access records. Current main inventory IDs and expected quantities were compared read-only at a406480e1e13807983f1c03b8a531c2dcd310ddb; expected quantities are not live stock. Member and campus access remain separate from club ownership.
Hardware and conditional wiring
| Component ID | Access scope | Expected snapshot quantity | Preflight |
|---|---|---|---|
| club:elegoo-mega-2560-compatible-board | CLUB_OWNED | 3 | PREFLIGHT_REQUIRED |
| club:lcd1602-with-i2c-backpack | CLUB_OWNED | 1 | PREFLIGHT_REQUIRED |
Breadboard, appropriately rated jumpers/data cables and a computer are shared setup requirements. Review supply, signal levels and ground separately; power off before changing connections. Null pins/rails remain unresolved.
| From | To | Signal | Voltage / gate | Condition |
|---|---|---|---|---|
| club:lcd1602-with-i2c-backpack / SDA | club:elegoo-mega-2560-compatible-board / D20 / SDA | I2C SDA | None / CONDITIONAL_REFERENCE | Verify backpack IC, carrier supply and pull-up rail before enabling. |
| club:lcd1602-with-i2c-backpack / SCL | club:elegoo-mega-2560-compatible-board / D21 / SCL | I2C SCL | None / CONDITIONAL_REFERENCE | Mega mapping; not Uno A4/A5. |
| display/peripheral / GND | controller / GND | Signal reference | 0 / CONDITIONAL_REFERENCE | Unpowered wiring check; use correct common-ground topology and keep high-current panel returns out of thin signal paths. |
| display/peripheral / VCC | verified supply / None | Peripheral power | None / CONDITIONAL_REFERENCE | Supply voltage/current unknown at carrier level until reviewed; no assumed 5 V or 3.3 V instruction. |
Software setup and dependencies
Open workspaces/lcd-hello-world in VS Code/PlatformIO. Configuration: workspaces/lcd-hello-world/platformio.ini. Platform: atmelavr@5.1.0. Board/framework: megaatmega2560 / arduino. Dependencies: duinoWitchery/hd44780@1.3.2. Dependency resolution occurs during build; an include is not an installation. See LIBRARY_MATRIX.md and COMPILATION_AUDIT.md for exact verification limits. The default electrical-review flag remains false. Review the matching pins, power and logic before changing it; a build cannot complete that physical review.
Build it: checkpoint path
| Stage | Goal | Environment | Expected / gate |
|---|---|---|---|
| First characters | Initialize a verified backpack and show a two-line greeting. | checkpoint1 | Engineering Club / Hello, LCD after successful initialization. |
| Changing values | Replace the second row with an elapsed-seconds counter. | checkpoint2 | Counter changes once per second; the first row remains stable. |
| Stable page updates | Alternate complete fixed-width messages without repeated clear. | checkpoint3 | Long and short messages leave no stale trailing characters. |
Choose a stage deliberately. Project downloads include all authored environments; model-only project downloads include checkpoints1/2 and explicitly exclude the unfinished physical checkpoint. Stage3 for a port-gated project refuses download as finished firmware.
Understand it: software and physical model
The chosen hd44780_I2Cexp class can discover compatible PCF8574/MCP23008 backpack address and mapping, and begin returns a status. That avoids hard-coding 0x27 from an unrelated tutorial. It cannot make an arbitrary expander compatible. The object declaration creates library-managed state; setup configures communication once; loop revisits time-driven work. The row helper copies at most sixteen characters into a seventeen-byte buffer and appends a terminator. It then pads the remaining cells with spaces, replacing the old visible row without a clear-screen flash.
A #include makes declarations available to the compiler; it does not install a library or run the display. PlatformIO resolves lib_deps during dependency processing/build, then the compiler checks calls and the linker joins their implementations. lcd is an object; begin and print are methods invoked on it. The arguments 16 and 2 describe columns and rows. A zero begin result means the library’s initialization routine succeeded, while a physical observation is still needed. const prevents reassignment of a value in that scope. A uint32_t clock represents unsigned milliseconds. Subtracting the previous timestamp uses defined unsigned arithmetic across rollover for intervals shorter than the wrap period.
Canonical code reading map
| Real file | Source landmarks (1-based) | Lines |
|---|---|---|
| workspaces/lcd-hello-world/include/board_profile.h | Supporting declarations / portable helpers | 5 |
| workspaces/lcd-hello-world/src/main.cpp | 11: void setup(){Serial.begin(115200); if(!kElectricalReviewComplete){Serial.println("STOP: complete wir; 13: void loop(){if(!ready)return;const uint32_t now=millis(); | 23 |
| common-libs/DisplayCore/src/DisplayCore.h | 30: inline bool parsePacket(const char* text,Packet& result){; 40: bool accept(const Packet& p,uint32_t now){ | 60 |
Read initialization and failure guards first, then the selected DISPLAY_STAGE region and its supporting modules. Source hashes, owners and roles are in code-assets.json. Shared software tests establish portable invariants only. No model substitutes for a physical driver.
Troubleshooting with evidence
Backlight, no text
Check the contrast adjustment and startup Serial status separately. A lit backlight proves neither bus traffic nor LCD initialization. Run the I²C diagnostic before changing application formatting.
Library cannot initialize
Record the error code, scan address and backpack IC marking. A successful ACK with unsupported expander mapping still cannot establish a working LCD.
Old characters remain
Confirm the fixed-width row helper is used rather than printing a shorter replacement onto existing characters. Check the zero-based row selection and sixteen-cell limit.
Experiments after the baseline
Replace the counter with two measurements while maintaining fixed-width columns.
Add a custom glyph only after ordinary characters work.
Measure the visible difference between clearing every update and overwriting a complete row.
Challenge
Add a third logical page while still updating only two physical rows and preserving the no-stale-tail invariant.
Verification and next work
No physical upload or bench observation occurred. Expected device results are targets. Native test output is recorded separately in validation/host-results.json. Current bounded build attempts are in validation/repair-compile-results.json; historical attempts remain under validation/history/. Embedded compile/link and hardware behavior remain unverified until actual evidence is recorded.
Source records: inventory-club-v3, inventory-member-v14, pio-deps, lcd-lib, pio-mega, mega-doc, pio-ide. Verified repository destinations are recorded in repository-integration.json; only resolved IDs are exposed in relatedLabs/relatedLearnConcepts.
Build evidence and diagnostic references
Current compile attempts: not performed in this pass. Physical Upload and bench observation: not tested.
- Stage 1: successful compile recorded 2026-10-19; 5 warnings recorded. The supplied electrical-review flag is false.
- Stage 2: successful compile recorded 2026-10-19; 5 warnings recorded. The supplied electrical-review flag is false.
- Stage 3: successful compile recorded 2026-10-19; 5 warnings recorded. The supplied electrical-review flag is false.
Historical compile evidence is separate from the original guide's earlier unverified status and does not establish today's build or hardware behavior.
Diagnostics before integration
- ACK/NACK bus scan Environment: checkpoint1
Technical sources and references
- PlatformIO Mega board
megaatmega2560, Arduino framework and target memory
- PlatformIO dependencies
Dependency installation occurs during package/build processing
- Arduino Mega hardware
Board pinout, voltage and ADC family
- hd44780 source/API
Compatible backpack classes, initialization status, GPL-3.0 license
- Official PlatformIO IDE installation
Official VS Code extension includes Core and project environment tasks