-
Notifications
You must be signed in to change notification settings - Fork 958
Add PIO 7-segment display example #714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mjcross
wants to merge
7
commits into
raspberrypi:develop
Choose a base branch
from
mjcross:pio_7_segment
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c89aa9b
add PIO seven segment display example
805ae87
add PIO seven segment display example
0c1355e
Incorporate review comments
447dcff
Add ascii art to show segment pattern
4542b5a
add simple bounds checking
0894a02
display negative numbers in pio_seven_segment example
ec9ef7b
link pio_seven_segment example into top level README
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <stdio.h> | ||
#include "pico/stdlib.h" | ||
#include "7_segment_lib.h" | ||
|
||
|
||
const PIO pio = pio0; | ||
const uint first_segment_pin = 8; // gpio 15-8 = segments E,D,B,G,A,C,F,dp | ||
const uint first_digit_pin = 16; // gpio 19-16 = common anodes 4,3,2,1 | ||
|
||
// EDBGACF. bit ordering depends on your display and wiring | ||
const uint32_t Pico = 0b10111010 << 24 | // 'P' | ||
0b10000000 << 16 | // 'i' | ||
0b11010000 << 8 | // 'c' | ||
0b11010100; // 'o' | ||
|
||
int main() { | ||
uint sm; | ||
stdio_init_all(); | ||
|
||
if (seven_segment_init (pio, &sm, first_segment_pin, first_digit_pin)) { | ||
puts ("running"); | ||
|
||
// display scrolling 'Pico' | ||
for (int shift = 24; shift >= 0; shift -= 8) { | ||
pio_sm_put (pio, sm, Pico >> shift); | ||
sleep_ms (1000); | ||
} | ||
|
||
// count to 9999 | ||
for (int i = 0; i < 10000; i += 1) { | ||
sleep_ms (100); | ||
pio_sm_put (pio, sm, int_to_seven_segment (i)); | ||
} | ||
} | ||
|
||
puts ("done"); | ||
while (true); | ||
} |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
add_executable(pio_seven_segment) | ||
|
||
target_sources(pio_seven_segment PRIVATE 7_segment.c) | ||
|
||
add_subdirectory_exclude_platforms(pio_7_segment_library) | ||
|
||
target_link_libraries(pio_seven_segment PRIVATE | ||
pico_stdlib | ||
hardware_pio | ||
pio_7_segment_library | ||
) | ||
|
||
pico_add_extra_outputs(pio_seven_segment) | ||
|
||
# add url via pico_set_program_url | ||
example_auto_set_url(pio_seven_segment) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
= Driving a 7 segment LED display | ||
This example demonstrates how a PIO state machine can be used to control a four digit multiplexed 7-segment display with the Raspberry Pi Pico (RP2040). | ||
|
||
Multiplexed displays work by rapidly displaying each digit in turn and the PIO provides an excellent way to relieve the CPU of this time-consuming task. | ||
|
||
The total current required is typically more than the GPIO pins can supply so you're likely to need an external drive circuit like the one below. | ||
|
||
The PIO code uses four `side-set` pins to control the digit multiplex lines and displays the segment patterns received on the FIFO. It uses a non-blocking PULL to keep showing the same segments until the CPU sends new data. | ||
|
||
The provided example uses spells out the word **Pico** and then counts from 0 to 9999. | ||
mjcross marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
== Wiring information | ||
Connect the display to your board using a circuit like the one below, making any changes for your display and transistors. | ||
|
||
Connect the circuit to an external 5V supply or power it via USB (in which case reconnect the _+5V_ rail to _VBUS_ instead of _VSYS_). | ||
|
||
TIP: this circuit is for a _common anode_ display that takes about 15mA per segment. | ||
|
||
[[pio_7_segment_wiring-diagram]] | ||
[pdfwidth=75%] | ||
.Wiring diagram | ||
image::7_segment_wiring_diagram.png[] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.