Day 4 : 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
List Title
The Raspberry Pi Pico is a small, affordable, and powerful device that you can use to learn about programming and electronics. It's like a tiny computer that you can hold in your hand. The Pico is designed to help you create all sorts of cool projects and learn about how computers work.
List Title
This is a Paragraph. Click on "Edit Text" or double click on the text box to start editing the content.
List Title
This is a Paragraph. Click on "Edit Text" or double click on the text box to start editing the content.
Day 4 Quiz: Please take in order to gauge your understanding of Day 3 concepts
Based on the questions you get incorrect, please review the material from Day 1 to ensure your understanding before proceeding
Constant Power
1. Low-level programming language
-
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.
2. High-level programming language
-
High-level programming language (HLL) is designed for developing user-friendly software programs and websites. This programming language requires a compiler or interpreter to translate the program into machine language (execute the program).
-
The main advantage of a high-level language is that it is easy to read, write, and maintain.
-
High-level programming language includes Python, Java, JavaScript, PHP, C#, C++, Objective C, Cobol, Perl, Pascal, LISP, FORTRAN, and Swift programming language.
Python is one of the most widely used user-friendly programming languages. It is an open-source and easy to learn programming language developed in the 1990s. It is mostly used in Machine learning, Artificial intelligence, Big Data, GUI based desktop applications, and Robotics.
Advantages
-
Python is easy to read, easy to understand, and easy to write.
-
It integrates with other programming languages like C, C++, and Java.
-
Python executes code line-by-line, so it is easy for the programmer to find the error that occurred in the code.
-
Python is platform-independent means you can write code once and run it anywhere.
Disadvantages
-
Python is not suitable for developing mobile applications and games.
-
Python works with the interpreter. That's why it is slower than other programming languages like C and C++.
Powering a motor
Steps:
1. Prepare the Breadboard:
Place your Raspberry Pi Pico on the breadboard. Ensure it's securely inserted into the breadboard's rows, with all pins accessible.
3. Connect Power to Breadboard:
- Take a jumper wire and connect one end to the 3V3 (3.3 volts) pin of the Raspberry Pi Pico.
- Connect the other end of this jumper wire to row 34 on the breadboard. This row will act as your power supply line for the motor.
4. Connect Ground to Breadboard:
- Take another jumper wire and connect one end to one of the GND (ground) pins on the Raspberry Pi Pico.
- Connect the other end of this wire to row 39 on the breadboard. This row will be your ground line.
5. Connect Motor to Breadboard:
- Identify the power and ground wires of the motor. Typically, the red wire is for power, and the black wire is for ground, but this can vary.
- Connect the motor's power wire to the same row (34) as the 3V3 power line from the Raspberry Pi Pico.
- Connect the motor's ground wire to the same row (39) as the ground line from the Raspberry Pi Pico.
- Make sure raspberry pi pico is connected to the computer as a power source
6. Double-Check Connections:
Ensure all connections are secure and correctly placed. The motor should now be connected in parallel with the Raspberry Pi Pico's power supply.
7. Testing:
Power up your Raspberry Pi Pico by running an empty Thonny program. The motor should receive power and start operating, assuming your control mechanism is set up correctly. The axil on the top of the motor will start spinning.
8. Safety and Precautions:
Be cautious when working with electronics. Double-check connections and ensure there are no short circuits.
*Use Figure 17 on the left to double check for reference while building your circuit!
Figure 17
Components Needed:
1. Raspberry Pi Pico
2. Small DC Motor
3. Breadboard
4. 2 Jumper Wires
Potentiometer
Components Needed:
- Rasberry Pi Pico
- LED
- Potentimoeter
- Breadboard
- 4 Jumper Wires
Steps:
1. Raspberry Pi Pico Pinout:
Refer to the Raspberry Pi Pico pinout diagram to locate the GPIO pins, 3V3 (3 volts) pin, and Ground pins. This is crucial for correct connections.
2. Setting Up the Breadboard:
- Place the Raspberry Pi Pico on the breadboard in a position where you can easily access its pins.
- Insert the LED into the breadboard. Connect the longer leg (anode) of the LED to row 34 on the breadboard.
- Insert the potentiometer into the breadboard. Ensure that its leftmost leg (as you face the knob) is on the same row as the LED's anode.
3. Wiring the Circuit:
- Connect a jumper wire from GPIO pin 15 of the Raspberry Pi Pico to the row where the LED's anode is placed (row 34).
- Connect another jumper wire from the leftmost leg of the potentiometer to any Ground pin on the Raspberry Pi Pico.
- Connect a jumper wire from the middle leg of the potentiometer to GPIO pin 26 of the Raspberry Pi Pico.
- Finally, connect the rightmost leg of the potentiometer to the 3V3 (3 volts) pin of the Raspberry Pi Pico.
4. Final Checks:
- Ensure all connections are secure and correct according to the pinout diagram.
- The shorter leg (cathode) of the LED should be connected to a ground row on the breadboard, and this row should be linked to a Ground pin on the Raspberry Pi Pico using another jumper wire.
Figure 18
Great Job! Now let's add code to have our circuit start working!
Figure 19
Programming the Circuit
-
Connect the Pico to Your Computer:
-
Use a micro USB cable to connect the Pico to your computer.
-
-
Access the Pico through Thonny Python IDE
-
Write the Code:
-
In your Python editor, write the following script in Figure 19.
-
-
Run the Code:
-
Run this script on your Raspberry Pi Pico. The LED connected to GPIO pin 16 should turn on for 5 seconds and then turn off, with the ability to turn control. the LED brightness from the potentiometer!.
-
Button Circuit
Figure 20
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 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 21
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 22
11. This will cause your LED circuit
to turn off after 5 seconds
Figure 22
Challenges
Challenge 1: Connect a motor to any GPIO pin, and program the motor to turn on and off in 5 second intervals exactly 100 times.
Challenge 2: Design a circuit that uses a potentiometer to control the pitch of a buzzer.
Challenge 3: Build a circuit that uses a potentiometer to control the brightness of an LED when a button is getting pressed down at the same time.
Challenge 4: Control the motor using user input. When your run the program, you should be able to type "yes" or "no" to determine whether the motor will spin. PS: You will have to self learn about user input functions in python in order to complete this challenge!
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.