Testing / Displays / 03
LCD Instrument Panel
Turn raw ADC counts into a stable, unit-labeled instrument display.
All 3 stages compiled 2026-10-19 (historical) · hardware review required
What you'll build
Read a potentiometer wiper as raw ADC counts and mirror to Serial.
First result after hardware review: Counts vary across the Mega’s 0..1023 range.
What you need
Check availability and exact module markings before starting.
Connections / current hardware gate
Before connecting power. Confirm the LCD backpack supply/pull-ups and the potentiometer connections before power. The nominal 5 V ADC reference is an estimate, not a measurement.
- Complete the LCD backpack checks from Hello World.
- Verify the potentiometer end rails and A0 wiper connection against the conditional wiring reference.
- Compare any voltage estimate with a meter; leave the electrical-review gate closed until the physical checks are complete.
Start building
- 1
Read A0
Read a potentiometer wiper as raw ADC counts and mirror to Serial.
- 2
Present relative position
Map counts into a rounded percentage.
- 3
Estimate voltage
Display a voltage estimate using an explicitly nominal 5 V reference.
Download complete PlatformIO project
Each stage has its exact environment, complete source and expected result. Editor and tools setup →
Troubleshooting
Constant zero or full scale
Verify the wiper and outer terminals with resistance/continuity checks, then measure the wiper voltage without exceeding the ADC input rail.
Readout jitters
Compare the raw Serial counts first. Shorten connections and stabilize reference/ground before adding a filter that could hide the fault.
Estimate disagrees with meter
Measure the actual reference and compare endpoint behavior. Explain model assumptions before adjusting the display to look correct.
More detail
Foundations, safety and learning objectives
145 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.
- Turn raw ADC counts into a stable, unit-labeled instrument display.
- The potentiometer ends form a divider across the board’s reference supply, and the wiper selects an intermediate voltage.
System diagram and electrical boundaries
Show the meaningful subsystem and signal/power boundary for LCD Instrument Panel. Conceptual system view; physical connections remain conditional.
- ELEGOO Mega 2560 R3 boardClub-owned
- LCD1602 16×2 Character Display with I²C BackpackClub-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
Power and common reference boundary
- display/peripheralSignal referencecontrollerConditional reference
- display/peripheralPeripheral powerverified supplyConditional reference
Interfaces: GPIO · I2C · ADC
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
- 10 kΩ potentiometerClub-owned
product family verified · preflight required
Compatibility and unresolved details
- Taper/wiper power: Unverified
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. |
10 kΩ potentiometerwiper | ELEGOO Mega 2560 R3 boardA0 | ADC 5 V | Conditional reference Identify terminals; outer ends to reviewed Mega reference supply and ground; nominal estimate is not calibration. |
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-instrument-panel
Open the extracted folder containing platformio.ini and keep the complete supporting files.
duinoWitchery/hd44780@1.3.2
workspaces/lcd-instrument-panel/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;uint32_t now=millis();if(!displaylab::elapsed(now,lastUpdate,250))return;lastUpdate=now;
const int raw=analogRead(A0);Serial.println(raw);char line[17];
#if DISPLAY_STAGE == 1
row(0,"A0 raw ADC");snprintf(line,sizeof(line),"Count:%4d",raw);
#elif DISPLAY_STAGE == 2
row(0,"Pot position");snprintf(line,sizeof(line),"Scale:%3d %%",int((raw*100L+511)/1023));
#else
row(0,"A0 estimate");const unsigned millivolts=(uint32_t(raw)*5000U+511U)/1023U;snprintf(line,sizeof(line),"%u.%03u V",millivolts/1000,millivolts%1000);
#endif
row(1,line);}
Source integrity · SHA-256
2a1ac9dd3b7c4e434162492220927ed95d420883e685206b8e3e56600b6ec293Raw 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.
Turn raw ADC counts into a stable, unit-labeled instrument display.
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 potentiometer ends form a divider across the board’s reference supply, and the wiper selects an intermediate voltage. A ten-bit conversion yields 1024 possible codes. The supplied scaling uses the 0..1023 endpoint convention, not a claim that the ADC is a calibrated voltmeter. Supply/reference tolerance, input loading, noise and converter error limit agreement. A full-scale code does not independently establish that the reference is exactly 5.000 V.
Before you start
Estimated learning time: 145 minutes, excluding unresolved hardware/port work. Required prerequisites: display-i2c-detective, display-lcd-hello-world. 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 |
| club:potentiometer-10k | CLUB_OWNED | 2 | 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. |
| club:potentiometer-10k / wiper | club:elegoo-mega-2560-compatible-board / A0 | ADC | 5 / CONDITIONAL_REFERENCE | Identify terminals; outer ends to reviewed Mega reference supply and ground; nominal estimate is not calibration. |
| 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-instrument-panel in VS Code/PlatformIO. Configuration: workspaces/lcd-instrument-panel/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 |
|---|---|---|---|
| Read A0 | Read a potentiometer wiper as raw ADC counts and mirror to Serial. | checkpoint1 | Counts vary across the Mega’s 0..1023 range. |
| Present relative position | Map counts into a rounded percentage. | checkpoint2 | Near the ends the displayed position approaches 0% and 100%. |
| Estimate voltage | Display a voltage estimate using an explicitly nominal 5 V reference. | checkpoint3 | The voltage estimate is labeled approximate; compare against a meter. |
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 raw count is captured once per update and reused for calculation, display and Serial evidence. Integer arithmetic promotes the product before multiplying by 5000, avoiding a narrow intermediate. The display samples at 250 ms, so it does not flicker or waste bus traffic. The LCD row helper keeps old digits from surviving when a new number is shorter. An instrument needs a raw observation path as well as a formatted presentation; otherwise formatting can conceal a sensor or wiring fault.
Start with the raw stage and rotate the shaft slowly. Do not debug the percentage formula until the counts respond correctly. The middle checkpoint teaches mapping, and the last deliberately distinguishes a calculation from a calibrated measurement. A0 is an analog input on this Mega; it is not interchangeable with an ESP32 ADC pin or the Pi header, which lacks a general-purpose analog converter. The potentiometer’s outer terminals and wiper must be identified with power off before connecting.
Source review precision: The screen heading is A0 estimate; the calculation uses a nominal 5000 mV reference. It does not print an approximation symbol on the numeric line. Compare the model with an actual meter reading before treating the result as measured volts.
Canonical code reading map
| Real file | Source landmarks (1-based) | Lines |
|---|---|---|
| workspaces/lcd-instrument-panel/include/board_profile.h | Supporting declarations / portable helpers | 5 |
| workspaces/lcd-instrument-panel/src/main.cpp | 11: void setup(){Serial.begin(115200); if(!kElectricalReviewComplete){Serial.println("STOP: complete wir; 13: void loop(){if(!ready)return;uint32_t now=millis();if(!displaylab::elapsed(now,lastUpdate,250))retur | 22 |
| 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
Constant zero or full scale
Verify the wiper and outer terminals with resistance/continuity checks, then measure the wiper voltage without exceeding the ADC input rail.
Readout jitters
Compare the raw Serial counts first. Shorten connections and stabilize reference/ground before adding a filter that could hide the fault.
Estimate disagrees with meter
Measure the actual reference and compare endpoint behavior. Explain model assumptions before adjusting the display to look correct.
Experiments after the baseline
Add a moving average and measure its response delay.
Use the measured reference value while keeping the approximate label.
Add peak/minimum tracking with an explicit reset event.
Challenge
Add a bar representation using custom character cells without replacing the raw measurement path.
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; 4 warnings recorded. The supplied electrical-review flag is false.
- Stage 2: successful compile recorded 2026-10-19; 4 warnings recorded. The supplied electrical-review flag is false.
- Stage 3: successful compile recorded 2026-10-19; 4 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