LCD Hello World / Stage 2 of 3
Changing values
Replace the second row with an elapsed-seconds counter.
Compiled 2026-10-19 (historical) · electrical review required
Download stage 2 PlatformIO projectRead code & run steps ↓
What changes now?
Replace the second row with an elapsed-seconds counter.
Expected after hardware review: Counter changes once per second; the first row remains stable.
Builds on stage 1: First characters.
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.
Conditional connection table and full module facts
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. |
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
Use this complete project
Target: megaatmega2560 · Environment: checkpoint2 · Stage branch: DISPLAY_STAGE=2
- Open the complete project. Download the stage ZIP, extract it and open the folder containing
platformio.iniandsrcin VS Code. Keep its supporting headers and libraries together. - Build stage 2. Select
checkpoint2in PlatformIO Project Tasks → General → Build, or use a PlatformIO terminal:
A successful Build compiles the program; it does not upload it or approve electrical connections.pio run -e checkpoint2 - Stop at the hardware gate. The supplied electrical-review flag remains false. Have a qualified reviewer complete the actual module, wiring and power checks before using an approved configuration for hardware operation.
As supplied, Serial at 115200 baud reports
STOP: complete wiring/power review in guide before enabling hardware.and initialization stops.
After electrical review: Upload and Monitor
Only with the actual setup reviewed and the configuration explicitly approved, choose this stage's Upload task. Close any monitor using the board first.
pio run -e checkpoint2 -t uploadOpen the matching Monitor at 115200 baud, then compare the expected result with what actually happens.
pio device monitor -b 115200Record Build, Upload and physical observations separately.
Complete source
The viewer starts at src/main.cpp. Use Source file for the board profile, PlatformIO configuration and supporting code. Keep the complete ZIP together.
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.
Check the result
Counter changes once per second; the first row remains stable.
As supplied, the false electrical-review flag prevents this hardware result. After qualified review, record what actually happens; the text above is an expected result, not a bench transcript.
Original verification checklist
- Build the exact selected environment; distinguish dependency resolution from source compilation.
- Observe the stated output and record actual behavior; expected result is not an observed transcript.
- Test the named failure mode before proceeding.
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.
Technical explanation / original guide
Read the complete original stage guide
Original source/research wording is preserved. The stage's dated build evidence above supersedes earlier blanket compile-status wording; no physical results are implied.
Build it
Replace the second row with an elapsed-seconds counter.
Open workspaces/lcd-hello-world in VS Code/PlatformIO. Select checkpoint2 and run pio run -e checkpoint2. This is FIRMWARE_SOURCE_AUTHORED with embedded compilation unverified. Review the electrical flag and canonical conditional wiring before any upload.
Understand it
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.
Expected result and verification
Counter changes once per second; the first row remains stable.
This is expected after a correct build and electrical review, not a captured bench transcript.
Check the selected source branch and named failure conditions. Record actual build or software output separately from future physical observations.
Likely failures
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.
Build evidence, target and remaining verification
Original status: unverified.
Successful checkpoint2 build recorded 2026-10-19 for megaatmega2560; 5 warnings recorded.
No compile was attempted in this pass under the user's testing limit. Upload and physical bench observation remain untested.
atmelavr@5.1.0 · arduino
Diagnostics before integration
- ACK/NACK bus scan Environment: checkpoint1