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

LCD Menu System / Stage 1 of 3

Observe one event

Log a debounced stable press from a button to ground.

Compiled 2026-10-19 (historical) · electrical review required

Download stage 1 PlatformIO projectRead code & run steps ↓

What changes now?

Initial isolated observation

Expected 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.
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 / 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.

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

Use this complete project

Target: megaatmega2560 · Environment: checkpoint1 · Stage branch: DISPLAY_STAGE=1

  1. Open the complete project. Download the stage ZIP, extract it and open the folder containing platformio.ini and src in VS Code. Keep its supporting headers and libraries together.
  2. Build stage 1. Select checkpoint1 in PlatformIO Project Tasks → General → Build, or use a PlatformIO terminal:
    pio run -e checkpoint1
    A successful Build compiles the program; it does not upload it or approve electrical connections.
  3. 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 checkpoint1 -t upload

Open the matching Monitor at 115200 baud, then compare the expected result with what actually happens.

pio device monitor -b 115200

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

Check the result

One press produces one event; holding does not repeatedly fire.

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
  1. Build the exact selected environment; distinguish dependency resolution from source compilation.
  2. Observe the stated output and record actual behavior; expected result is not an observed transcript.
  3. Test the named failure mode before proceeding.

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.

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

Log a debounced stable press from a button to ground.

Open workspaces/lcd-menu-system in VS Code/PlatformIO. Select checkpoint1 and run pio run -e checkpoint1. This is FIRMWARE_SOURCE_AUTHORED with embedded compilation unverified. Review the electrical flag and canonical conditional wiring before any upload.

Understand it

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.

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.

Expected result and verification

One press produces one event; holding does not repeatedly fire.

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

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.

Build evidence, target and remaining verification

Original status: unverified.

Successful checkpoint1 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