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

← Mega Components

ELEGOO MEGA · LESSON 28

Four Digital Seven Segment Display

Show the same changing hexadecimal glyph on all four digits.

Separate a shared segment pattern from digit selection and multiplexing.

Parts List

  • ELEGOO Mega 2560 R3 is a 5 V ATmega2560 AVR board with many I/O pins and four hardware UARTs for control systems with several peripherals. Long ELEGOO-branded Mega PCB with USB-B and barrel connector, ATmega2560 marking, extended side headers and a large double-row digital header at the end. Read printed Mega labels; its SPI hardware placement is not the same numeric pins as an Uno.
  • A USB-A to USB-B cable carries USB power and, when its data conductors are present, a host/device data link. USB-A plug and square USB-B plug. Inspect the plug shape; micro-USB is not USB-C, and USB-B is the squarer device connector.
  • An 830-contact solderless breadboard joins inserted leads through hidden spring strips so circuits can be rebuilt without solder. Full-size rectangular board, center channel, numbered five-hole terminal groups and side power rails. Counted contact holes are not component units.
  • 74HC595 accepts eight bits serially and latches them onto eight parallel logic outputs, expanding output control with a few GPIO lines. 16-pin DIP marked 74HC595/74HC595N with notch or pin-one dot. HC and HCT variants have different input thresholds.
  • A bare 4-digit seven-segment LED package shows numeric values using shaped LED segments. Black four-numeral package without a driver PCB.
  • A nominal 5.1 kΩ resistor for biasing, divider networks and suitable pull-up circuits; its AliExpress source label is 5K1. Axial resistor with two end leads; use labeled storage and an isolated meter reading.
  • 100 nF nonpolar ceramic capacitor stores electric-field energy. Local IC decoupling and short high-frequency supply disturbances are appropriate uses when voltage and circuit requirements are checked. Small non-polar disc, often marked 104; 104 means 100 nF, not 104 pF. Read the value and rating rather than estimating from body size.
  • Male-to-male jumper leads make removable point-to-point connections for low-current prototype signals. Pins at both ends; count individual leads rather than ribbon groups. Check intact insulation and snug contacts before use.

Assembly

  1. Disconnect USB and identify the exact common-cathode pin map.
  2. Use the original all-four-commons arrangement, replacing its four 220 Ω common resistors with 5.1 kΩ; add 100 nF at the IC.
  3. Verify IC MR pin 10 is tied to 5 V, as in the breadboard image; do not leave it floating as in the simplified schematic.
Illustration © ELEGOO. All rights reserved.
Illustration © ELEGOO. All rights reserved. Open full-size ↗

Reviewed connections

FromToNote
Mega D8,D9,D1074HC595 14 DS,12 ST_CP,11 SH_CPMSBFIRST; bit 0 reaches Q0
Q0..Q7 → display a,b,c,d,e,f,g,dpDisplay pins 11,7,4,2,1,10,5,3IC output pins 15,1,2,3,4,5,6,7
Display DIG1..DIG4 pins 12,9,8,6Each through its own 5.1 kΩ to GNDAll digits enabled together; no digit-select GPIO
IC 16/10 → 5 V; 8/13 → GND; 100 nF 16↔8Pin 9 Q7′ openDo not leave MR floating

Source-reviewed wiring. Hardware not bench-tested; firmware uploads have not been performed.

Code

PlatformIO configuration
platformio.ini
[env:mega]
platform = atmelavr@5.3.0
board = megaatmega2560
framework = arduino
monitor_speed = 9600
main.cpp
#include <Arduino.h>
const uint8_t LATCH_PIN = 9;   // MCU pin, not the 74HC595 latch terminal number (12).
const uint8_t CLOCK_PIN = 10;  // IC clock terminal is 11.
const uint8_t DATA_PIN = 8;    // IC data terminal is 14.
// MSBFIRST places bit 0 at Q0. Here bit 0=a, 1=b, ..., 6=g, 7=decimal point.
const uint8_t GLYPHS[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
                         0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};
void displayGlyph(uint8_t number) {
  digitalWrite(LATCH_PIN, LOW);
  shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, GLYPHS[number]);
  digitalWrite(LATCH_PIN, HIGH);
}
void setup() {
  pinMode(LATCH_PIN, OUTPUT); pinMode(CLOCK_PIN, OUTPUT); pinMode(DATA_PIN, OUTPUT);
}
void loop() {
  // The supplied wiring grounds all four digit commons through separate resistors.
  // It shows the SAME glyph on every digit; this sketch does not select or multiplex digits.
  for (uint8_t number = 1; number <= 15; ++number) {
    displayGlyph(number); delay(500);  // 1..9,A,b,C,d,E,F; the supplied loop does not show zero.
  }
}

Source: SOURCE_RECONCILED. Compile: COMPILE_VERIFIED. Hardware: NOT_TESTED. Upload: NOT_PERFORMED.

Expected behavior

All four digits repeat 1111,2222,…,9999,AAAA,bbbb,CCCC,dddd,EEEE,FFFF at 500 ms per glyph. The artwork’s APLO lettering is illustrative, not this sketch’s output. Brightness varies with segment count; there is no independent digit scan.

Experiments & Challenges

  • Add displayGlyph(0) and a delay before the loop to include 0000.

Troubleshooting

  • One/all digits dark: check its common-resistor path, MR/OE and the exact 5641AS polarity; this is not a driver-equipped display.