Site Guide

Find your way around the Engineering Club.

Know what you need? Search for a component, concept or project.

Around the site

Start

Labs

TestingExperimental

Build

Club

LearnExperimental

Go a little deeper

Entry points to larger collections. Use Search for individual records.

Learning paths & reference

Inside PiCrawlerExperimental

Inside Inventory

Testing / Displays / 04

LCD Menu System

Use debounced input events and explicit page state instead of delay-heavy menu branches.

All 3 stages compiled 2026-10-19 (historical) · hardware review required

What you'll build

Log a debounced stable press from a button to ground.

First result after hardware review: One press produces one event; holding does not repeatedly fire.

What you need

Check availability and exact module markings before starting.

Connections / current hardware gate

Before connecting power. Confirm the LCD rails, potentiometer and button contacts before power. The button uses a pull-up input and a reviewed connection to ground.

  • Retain the reviewed LCD and potentiometer setup from the preceding projects.
  • Identify the actual button contact pairs and compare them with the conditional map.
  • Review the fail-closed electrical flag before any upload intended to operate hardware.

Start building

  1. 1

    Observe one event

    Log a debounced stable press from a button to ground.

  2. 2

    Advance page state

    Cycle Measurement, History and Status as a finite page domain.

  3. 3

    Render from state

    Update row content from current page and current measurement.

Download complete PlatformIO project

Each stage has its exact environment, complete source and expected result. Editor and tools setup →

Troubleshooting

Many page changes per press

Check that the event return is used, not the continuously true pressed level. Confirm state objects persist between loop calls.

No event

Verify the two switch terminals used are electrically different contact sides. Tactile buttons often have internally connected pairs.

Slow response

Remove blocking delays and repeated bus scans. Measure input polling cadence rather than assuming the loop runs instantly.

More detail

Foundations, safety and learning objectives

170 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.
  • Use debounced input events and explicit page state instead of delay-heavy menu branches.
  • A mechanical switch can bounce between electrical states during one human action.
System diagram and electrical boundaries
LCD Menu System · subsystem relationships

Show the meaningful subsystem and signal/power boundary for LCD Menu System. Conceptual system view; physical connections remain conditional.

  • ELEGOO Mega 2560 R3 boardClub-owned
  • LCD1602 16×2 Character Display with I²C BackpackClub-owned
  • Small tactile pushbuttonClub-owned
  • 10 kΩ potentiometerClub-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
  • 10 kΩ potentiometerADCELEGOO Mega 2560 R3 boardConditional reference
  • Small tactile pushbuttonActive-low buttonELEGOO 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
  • product family verified · preflight required

  • product family verified · preflight required

    Compatibility and unresolved details
    • Taper/wiper power: Unverified
  • product family verified · preflight required

    Compatibility and unresolved details
    • Contact/header current rating: Unverified; use as signal input

Electrical review is incomplete. Conditional references require confirmation; unresolved pins or rails are not wiring instructions. Power off before changing connections.

From device / pinTo device / pinSignal / voltageConnection status and notes
LCD1602 16×2 Character Display with I²C Backpack
SDA
ELEGOO Mega 2560 R3 board
D20 / 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 Backpack
SCL
ELEGOO Mega 2560 R3 board
D21 / SCL
I2C SCL
Voltage unresolved
Conditional reference

Mega mapping; not Uno A4/A5.

10 kΩ potentiometer
wiper
ELEGOO Mega 2560 R3 board
A0
ADC
5 V
Conditional reference

Identify terminals; outer ends to reviewed Mega reference supply and ground; nominal estimate is not calibration.

Small tactile pushbutton
contact side A
ELEGOO Mega 2560 R3 board
D2
Active-low button
5 V
Conditional reference

Other contact side to GND; INPUT_PULLUP. Avoid same-side terminal pairs.

display/peripheral
GND
controller
GND
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/peripheral
VCC
verified supply
Pin 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-menu-system

Open the extracted folder containing platformio.ini and keep the complete supporting files.

  • duinoWitchery/hd44780@1.3.2

workspaces/lcd-menu-system/src/main.cpp

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);}
#include "ui.h"
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;}beginInput();ready=true;}

 void loop(){if(!ready)return;uint32_t now=millis();const bool event=readPageEvent(now);
 #if DISPLAY_STAGE == 1
 if(event)Serial.println("One debounced press");
 #elif DISPLAY_STAGE == 2
 if(event)Serial.println((unsigned)currentPage());
 #endif
 if(!event&&!displaylab::elapsed(now,lastUpdate,250))return;lastUpdate=now;
 const auto page=currentPage();row(0,page==displaylab::Page::measurement?"Measurement":page==displaylab::Page::history?"History":"Status");
 char text[17];snprintf(text,sizeof(text),"A0:%4d",analogRead(A0));row(1,text);
 }
Source integrity · SHA-256b23c895650905d780924ad993a2e1378731c4e7d2a42fcb3bffe48c62a39d051

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

Use debounced input events and explicit page state instead of delay-heavy menu branches.

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

A mechanical switch can bounce between electrical states during one human action. INPUT_PULLUP establishes a released high state and a ground-connected pressed low state. The portable Button model tracks raw and stable values plus the most recent transition time. It emits a press only after the new value remains stable for 25 ms. That delay is an authored policy to test with this button, not a measured bounce duration for every switch.

Before you start

Estimated learning time: 170 minutes, excluding unresolved hardware/port work. Required prerequisites: display-lcd-instrument-panel. 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 IDAccess scopeExpected snapshot quantityPreflight
club:elegoo-mega-2560-compatible-boardCLUB_OWNED3PREFLIGHT_REQUIRED
club:lcd1602-with-i2c-backpackCLUB_OWNED1PREFLIGHT_REQUIRED
club:pushbutton-smallCLUB_OWNED20PREFLIGHT_REQUIRED
club:potentiometer-10kCLUB_OWNED2PREFLIGHT_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.

FromToSignalVoltage / gateCondition
club:lcd1602-with-i2c-backpack / SDAclub:elegoo-mega-2560-compatible-board / D20 / SDAI2C SDANone / CONDITIONAL_REFERENCEVerify backpack IC, carrier supply and pull-up rail before enabling.
club:lcd1602-with-i2c-backpack / SCLclub:elegoo-mega-2560-compatible-board / D21 / SCLI2C SCLNone / CONDITIONAL_REFERENCEMega mapping; not Uno A4/A5.
club:potentiometer-10k / wiperclub:elegoo-mega-2560-compatible-board / A0ADC5 / CONDITIONAL_REFERENCEIdentify terminals; outer ends to reviewed Mega reference supply and ground; nominal estimate is not calibration.
club:pushbutton-small / contact side Aclub:elegoo-mega-2560-compatible-board / D2Active-low button5 / CONDITIONAL_REFERENCEOther contact side to GND; INPUT_PULLUP. Avoid same-side terminal pairs.
display/peripheral / GNDcontroller / GNDSignal reference0 / CONDITIONAL_REFERENCEUnpowered wiring check; use correct common-ground topology and keep high-current panel returns out of thin signal paths.
display/peripheral / VCCverified supply / NonePeripheral powerNone / CONDITIONAL_REFERENCESupply voltage/current unknown at carrier level until reviewed; no assumed 5 V or 3.3 V instruction.

Software setup and dependencies

Open workspaces/lcd-menu-system in VS Code/PlatformIO. Configuration: workspaces/lcd-menu-system/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

StageGoalEnvironmentExpected / gate
Observe one eventLog a debounced stable press from a button to ground.checkpoint1One press produces one event; holding does not repeatedly fire.
Advance page stateCycle Measurement, History and Status as a finite page domain.checkpoint2Three presses return to the first page.
Render from stateUpdate row content from current page and current measurement.checkpoint3Page labels and the A0 count render independently of input polling. All checkpoints already render the page; stage1 adds press logs and stage2 logs the page index.

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

ui.cpp owns the page and button state, while main reads a page query and renders. This is the first justified subsystem boundary: input handling has an independent contract. The scoped Page enum prevents treating arbitrary unrelated integers as page identities. A transition changes page once; a renderer can run many times without changing page. No nested menu loop waits for a button or stops measurement updates.

The input model starts released, so a button held during startup is detected as a newly stable press after the debounce interval. Decide if that is the product behavior you want. Page wrap is explicit modulo three. The checkpoint names represent growing understanding even though one canonical workspace contains complete source controlled by DISPLAY_STAGE. Open ui.h beside ui.cpp and identify declaration, definition and caller; including a header does not compile the implementation into the caller twice.

Source review precision: All three source environments already read A0 and render the selected page. Checkpoint1 additionally logs a stable press; checkpoint2 additionally logs the numeric page; checkpoint3 removes those diagnostic prints. The stages isolate reading tasks rather than pretending the earlier renderer is absent. A 10 kΩ potentiometer is required for a meaningful A0 input.

Canonical code reading map

Real fileSource landmarks (1-based)Lines
workspaces/lcd-menu-system/include/board_profile.hSupporting declarations / portable helpers5
workspaces/lcd-menu-system/include/ui.hSupporting declarations / portable helpers5
workspaces/lcd-menu-system/src/main.cpp12: void setup(){Serial.begin(115200); if(!kElectricalReviewComplete){Serial.println("STOP: complete wir; 14: void loop(){if(!ready)return;uint32_t now=millis();const bool event=readPageEvent(now);23
workspaces/lcd-menu-system/src/ui.cppSupporting declarations / portable helpers6
common-libs/DisplayCore/src/DisplayCore.h30: 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

Many page changes per press

Check that the event return is used, not the continuously true pressed level. Confirm state objects persist between loop calls.

No event

Verify the two switch terminals used are electrically different contact sides. Tactile buttons often have internally connected pairs.

Slow response

Remove blocking delays and repeated bus scans. Measure input polling cadence rather than assuming the loop runs instantly.

Experiments after the baseline

Add a Back button with its own independent debounce state.

Create a parameter-editing page with distinct selection and editing modes.

Replace button input with an encoder only after its signal/pulse contract is verified.

Challenge

Implement an inactivity return-to-home timer that does not fire while editing a value.

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

Technical sources and references