Day 3 : Creating Circuits
In order to continue this course, please have a Raspberry Pi Pico and electronic components available:
Raspberry Pi Pico: Raspberry Pi Pico Amazon Link
Electronic Components: Electronic Components Amazon Link
Day 3 Quiz: Please take in order to gauge your understanding of Day 2 concepts
Based on the questions you get incorrect, please review the material from Day 1 to ensure your understanding before proceeding
Creating a LED circuit
1. Reviewing the Fundamentals
-
Low-level language is machine-dependent (0s and 1s) programming language. The processor runs low- level programs directly without the need of a compiler or interpreter, so the programs written in low-level language can be run very fast.
-
Low-level language is further divided into two parts -
-
i. Machine Language
-
-
Machine language is a type of low-level programming language. It is also called as machine code or object code. Machine language is easier to read because it is normally displayed in binary or hexadecimal form (base 16) form. It does not require a translator to convert the programs because computers directly understand the machine language programs.
-
The advantage of machine language is that it helps the programmer to execute the programs faster than the high-level programming language.
-
ii. Assembly Language
-
-
Assembly language (ASM) is also a type of low-level programming language that is designed for specific processors. It represents the set of instructions in a symbolic and human-understandable form. It uses an assembler to convert the assembly language to machine language.
-
The advantage of assembly language is that it requires less memory and less execution time to execute a program.
Please watch this video in order to understand how the flow of energy in a breadboard works! Make sure to open your electronic components box and remove your breadboard. Understand your breadboard while watching the video.
GPIO Pins
GPIO (General Purpose Input/Output) pins are a type of digital pin on a microcontroller or single-board computer, such as the Raspberry Pi Pico. These pins can be configured to either input or output mode, allowing them to interact with external devices and circuits.
-
General Purpose: GPIO pins are versatile and can be used for a variety of purposes. They can be configured as inputs to read the state of a connected device (like a button or sensor) or as outputs to send signals to other components (like LEDs or motors).
-
Numbering System: GPIO pins on the Raspberry Pi Pico are typically numbered. For example, on the Pico, the pins are labeled GP0, GP1, GP2, and so on. These labels correspond to the GPIO pin numbers.
First Circuit
Figure 6
The first two lines are called import statements. These lines allow us to access specific commands so we can control the LED for our circuit.
On line 4, we create the variable 'blueLED' which is going to run power to GPIO Pin 13 of our breadboard. Finally on line 6, we are turning on the LED through accessing the variable 'blueLED' and using .on() to turn it on.
5. Next you are going to assemble your circuit so have one LED, one jumper wire, and one resister available (these can all be found in your electronic components box)
6. Place on end of your jumper wire next to a Ground pin of the raspberry pi pico and place the other end to 5 spaces in front of the raspberry pi pico
7. Next place your LED pin on the same row as the end of the jumper wire
- Make sure to place the longer metal leg of the LED on the same side of the jumper wire and place the shorter leg across the other side of the bread board
8. Next grab your resister and place one leg on the same row as the LED and on the same side of the shorter leg of the LED
9. Place the other leg of the resister and place it next to Pin 13 on the breadboard
10. Hit the green run button and see your LED turn on!
Figure 7
Great Job! Now let's add a bit more to our code to have our LED start blinking!
10. Add the following lines that can be seen in Figure 8
11. This will cause your LED circuit to turn off after 5 seconds
Figure 8
Now let's incorporate a while loop into the code! If you forget what that is please review the previous day's lesson.
Figure 9
12. Add the following lines that can be seen in Figure 9
13. This will cause the LED to turn on and off with a 5 second interval 30 times!
Here is the same thing, but with a for loop!
Figure 10
Buzzer Circuit
Figure 11
The first two lines are called import statements. These lines allow us to access specific commands so we can control the buzzer for our circuit.
On line 4, we create the variable 'buzzer which is going to run power to Pin 13 of our breadboard. Finally on line 6, we are turning on the buzzer through accessing the variable 'buzzer' and using .on() to turn it on.
Great Job! Now let's add a bit more to our code to have our LED start blinking!
5. Next you are going to assemble your circuit so have one LED, one jumper wire, and one resister available (these can all be found in your electronic components box)
6. Place on end of your jumper wire next to a Ground pin of the raspberry pi pico and place the other end to 5 spaces in front of the raspberry pi pico
7. Next place your Buzzer pin on the same row as the end of the jumper wire
- Make sure to place the longer metal leg of the Buzzer on the same side of the jumper wire and place the shorter leg across the other side of the bread board
8. Next grab your resister and place one leg on the same row as the LED and on the same side of the shorter leg of the Buzzer
9. Place the other leg of the resister and place it next to Pin 13 on the breadboard
10. Hit the green run button and see your LED turn on!
Figure 12
10. Add the following lines that
can be seen in Figure 13
11. This will cause your LED circuit
to turn off after 5 seconds
Figure 13
Button Circuit
Figure 14
The first two lines are called import statements. These lines allow us to access specific commands so we can control the LED for our circuit.
On line 4, we create the variable 'led' which is going to run power to Pin 13 of our breadboard. Finally on line 6, we are turning on the LED through accessing the variable 'led' and using .on() to turn it on.
5. Next you are going to assemble your circuit so have one LED, one jumper wire, and one resister available (these can all be found in your electronic components box)
6. Place on end of your jumper wire next to a Ground pin of the raspberry pi pico and place the other end to 5 spaces in front of the raspberry pi pico
7. Next place your LED pin on the same row as the end of the jumper wire
- Make sure to place the longer metal leg of the LED on the same side of the jumper wire and place the shorter leg across the other side of the bread board
8. Next grab your resister and place one leg on the same row as the LED and on the same side of the shorter leg of the LED
9. Place the other leg of the resister and place it next to Pin 13 on the breadboard
10. Hit the green run button and see your LED turn on!
Figure 15
Great Job! Now let's add a bit more to our code to have our LED stay on by the button!
10. Add the following lines that
can be seen in Figure 16
11. This will cause your LED circuit
to turn off after 5 seconds
Figure 16
Play around, edit the code to perform what you want!
Challenges
Challenge 1: Create a circuit that makes three LED blink on and off at the same time using a GPIO pin on the Raspberry Pi Pico
Challenge 2: Create a circuit where an buzzer turns on/off based on the state of a push button. (make sure to use a resister)
Complete all of these challenges without looking at the solutions. If you are very stuck and have spent at least 1 hour in trying to get a challenge complete, then look at a solution. Use the solutions as a very last resort and if you are still confused email groundupcs@gmail.com with any questions you may have.