Initial Release

This commit is contained in:
graham sanderson
2021-01-20 10:49:34 -06:00
commit 46078742c7
245 changed files with 21157 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
add_executable(hello_7segment
hello_7segment.c
)
# Pull in our pico_stdlib which pulls in commonly used features
target_link_libraries(hello_7segment pico_stdlib)
# create map/bin/hex file etc.
pico_add_extra_outputs(hello_7segment)
# add url via pico_set_program_url
example_auto_set_url(hello_7segment)

View File

@@ -0,0 +1,50 @@
= Attaching a 7 segment LED via GPIO
This example code shows how to interface the Raspberry Pi Pico to a generic 7 segment LED device. It uses the LED to count from 0 to 9 and then repeat. If the button is pressed, then the numbers will count down instead of up.
== Wiring information
Our 7 Segment display has pins as follows.
----
--A--
F B
--G--
E C
--D--
----
By default we are allocating GPIO 2 to A, 3 to B etc.
So, connect GPIO 2 to pin A on the 7 segment LED display and so on. You will need the appropriate resistors (68 ohm should be fine) for each segment.
The LED device used here is common anode, so the anode pin is connected to the 3.3v supply, and the GPIO's need to pull low (to ground) to complete the circuit.
The pull direction of the GPIO's is specified in the code itself.
Connect the switch to connect on pressing. One side should be connected to ground, the other to GPIO 9.
[[hello_7segment_wiring]]
[pdfwidth=75%]
.Wiring Diagram for 7 segment LED.
image::hello_7segment_bb.png[]
== List of Files
CMakeLists.txt:: CMake file to incorporate the example in to the examples build tree.
hello_7segment.c:: The example code.
== Bill of Materials
.A list of materials required for the example
[[hello_7segment-bom-table]]
[cols=3]
|===
| *Item* | *Quantity* | Details
| Breadboard | 1 | generic part
| Raspberry Pi Pico | 1 | http://raspberrypi.org/
| 7 segment LED module | 1 | generic part
| 68 ohm resistor | 7 | generic part
| DIL push to make switch | 1 | generic switch
| M/M Jumper wires | 10 | generic part
|===

View File

@@ -0,0 +1,95 @@
/**
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
/*
Our 7 Segment display has pins as follows:
--A--
F B
--G--
E C
--D--
By default we are allocating GPIO 2 to A, 3 to B etc.
So, connect GOIP 2 to pin A on the 7 segment LED display etc. Don't forget
the appropriate resistors, best to use one for each segment!
Connect button so that pressing the switch connects the GPIO 9 (default) to
ground (pull down)
*/
#define FIRST_GPIO 2
#define BUTTON_GPIO (FIRST_GPIO+7)
// This array converts a number 0-9 to a bit pattern to send to the GPIO's
int bits[10] = {
0x3f, // 0
0x06, // 1
0x5b, // 2
0x4f, // 3
0x66, // 4
0x6d, // 5
0x7d, // 6
0x07, // 7
0x7f, // 8
0x67 // 9
};
// tag::hello_gpio[]
int main() {
stdio_init_all();
printf("Hello, 7segment - press button to count down!\n");
// We could use gpio_set_dir_out_masked() here
for (int gpio = FIRST_GPIO; gpio < FIRST_GPIO + 7; gpio++) {
gpio_init(gpio);
gpio_set_dir(gpio, GPIO_OUT);
// Our bitmap above has a bit set where we need an LED on, BUT, we are pulling low to light
// so invert our output
gpio_set_outover(gpio, GPIO_OVERRIDE_INVERT);
}
gpio_init(BUTTON_GPIO);
gpio_set_dir(BUTTON_GPIO, GPIO_IN);
// We are using the button to pull down to 0v when pressed, so ensure that when
// unpressed, it uses internal pull ups. Otherwise when unpressed, the input will
// be floating.
gpio_pull_up(BUTTON_GPIO);
int val = 0;
while (true) {
// Count upwards or downwards depending on button input
// We are pulling down on switch active, so invert the get to make
// a press count downwards
if (!gpio_get(BUTTON_GPIO)) {
if (val == 9) {
val = 0;
} else {
val++;
}
} else if (val == 0) {
val = 9;
} else {
val--;
}
// We are starting with GPIO 2, our bitmap starts at bit 0 so shift to start at 2.
int32_t mask = bits[val] << FIRST_GPIO;
// Set all our GPIO's in one go!
// If something else is using GPIO, we might want to use gpio_put_masked()
gpio_set_mask(mask);
sleep_ms(250);
gpio_clr_mask(mask);
}
return 0;
}
// end::hello_gpio[]

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 KiB