How to Display Numbers on 4-Digit 7-Segment Display with Raspberry Pi Pico in Wokwi - Complete Step-by-Step Tutorial
Project Overview
This comprehensive guide demonstrates how to interface a 4-digit 7-segment display with a Raspberry Pi Pico microcontroller using the Wokwi online simulator. Learn to display numbers, create counters, show time, temperature readings, and build digital dashboard projects without any physical hardware.
What You'll Learn
- 7-segment display operation principles
- Multiplexing technique for multi-digit displays
- Raspberry Pi Pico GPIO control
- MicroPython programming for displays
- Counter and timer applications
- Wokwi simulator for display projects
Components Required in Wokwi
Hardware (Virtual):
Diagram.json:
- 1x Raspberry Pi Pico board
- 1x 4-Digit 7-Segment Display (Common Cathode)
- 4x Current-limiting resistors (220Ω-330Ω) - optional in simulation
- Jumper wires (automatic in Wokwi)
Software:
- MicroPython firmware
- 7-segment display library
Understanding 7-Segment Displays
What is a 7-Segment Display?
A 7-segment display uses seven LED segments (labeled A-G) plus a decimal point to show digits 0-9 and some letters.
Segment Mapping:
- A = Top horizontal
- B = Top right vertical
- C = Bottom right vertical
- D = Bottom horizontal
- E = Bottom left vertical
- F = Top left vertical
- G = Middle horizontal
- DP = Decimal point
Common Cathode vs Common Anode
Common Cathode (this tutorial uses this type):
- All cathodes connected together to GND
- Segments light up when pin is HIGH (3.3V)
- More common and easier to use
Common Anode:
- All anodes connected together to VCC
- Segments light up when pin is LOW (0V)
4-Digit Display Multiplexing
A 4-digit display has:
- 8 segment pins (A, B, C, D, E, F, G, DP)
- 4 digit select pins (D1, D2, D3, D4)
Multiplexing Concept: Only one digit is active at a time, but switching happens so fast (>50 Hz) that all digits appear to be on simultaneously due to persistence of vision.
How it works:
- Enable Digit 1, display its segments, disable
- Enable Digit 2, display its segments, disable
- Enable Digit 3, display its segments, disable
- Enable Digit 4, display its segments, disable
- Repeat cycle continuously
Step-by-Step Wokwi Setup Instructions
Step 1: Create New Raspberry Pi Pico Project
- Navigate to https://wokwi.com
- Click "New Project"
- Select "Raspberry Pi Pico"
- Pico board appears on canvas
Step 2: Add 4-Digit 7-Segment Display
- Click the blue "+" (Add Part) button
- Search for "7-segment" or "4-digit"
- Select "4-Digit 7-Segment Display" or "TM1637"
- Place it above the Pico board
Note: Wokwi may have different display modules. Look for common cathode 4-digit displays.
Step 3: Understanding Pin Configuration
4-Digit 7-Segment Display Pins:
Segment Pins (8 pins):
- A, B, C, D, E, F, G, DP (Decimal Point)
Digit Select Pins (4 pins):
- D1 (Digit 1 - leftmost)
- D2 (Digit 2)
- D3 (Digit 3)
- D4 (Digit 4 - rightmost)
Total: 12 pins (8 segment + 4 digit select)
Step 4: Pin Assignment Strategy
To control the display efficiently, we'll use:
Segment Pins → GPIO Pins:
| Segment | GPIO Pin | Description |
|---|---|---|
| A | GPIO 2 | Top segment |
| B | GPIO 3 | Top-right segment |
| C | GPIO 4 | Bottom-right segment |
| D | GPIO 5 | Bottom segment |
| E | GPIO 6 | Bottom-left segment |
| F | GPIO 7 | Top-left segment |
| G | GPIO 8 | Middle segment |
| DP | GPIO 9 | Decimal point |
Digit Select Pins → GPIO Pins:
| Digit | GPIO Pin | Position |
|---|---|---|
| D1 | GPIO 10 | Leftmost digit |
| D2 | GPIO 11 | Second digit |
| D3 | GPIO 12 | Third digit |
| D4 | GPIO 13 | Rightmost digit |
Common Connection:
- All digit cathodes → Pico GND (for common cathode)
Step 5: Wire the Circuit in Wokwi
Segment Connections (Blue/Green wires):
- Display A → Pico GPIO 2
- Display B → Pico GPIO 3
- Display C → Pico GPIO 4
- Display D → Pico GPIO 5
- Display E → Pico GPIO 6
- Display F → Pico GPIO 7
- Display G → Pico GPIO 8
- Display DP → Pico GPIO 9
Digit Select Connections (Blue wires):
- Display D1 → Pico GPIO 10
- Display D2 → Pico GPIO 11
- Display D3 → Pico GPIO 12
- Display D4 → Pico GPIO 13
Ground Connection:
- Display GND (common cathode) → Pico GND
Wokwi Tips:
- Click each display pin and drag to corresponding Pico GPIO
- Wokwi auto-assigns wire colors
- Hover over pins to see labels
- Use zoom controls for precision
Step 9: Run the Simulation
- Click green "Start Simulation" play button
- Watch all four digits light up showing "0000"
- See counter increment automatically
- Observe decimal point in demo 2
- Check Serial Monitor for demo progression
Expected Display Output:
First demo: 0000 → 0001 → 0002 → ... → 0099
Second demo: 00.0 → 01.0 → 02.0 → ... → 99.0Third demo: 0010 → 0009 → 0008 → ... → 0000Fourth demo: 1234 (static)Fifth demo: Continuous countingStep 10: Verify Display Operation
Visual Checks:
- All four digits should be visible simultaneously
- Numbers should be clear and bright
- No flickering (refresh rate is adequate)
- Decimal points work when enabled
- Transitions are smooth
Serial Monitor:
7-Segment Display Test Starting...
Demo 1: Counting 0-9999Demo 2: Decimal numbersDemo 3: Countdown from 10Demo 4: Display 1234Demo 5: Continuous counter
Comments
Post a Comment