Catalog Preface ........................1 Unit 1 Getting started ..................6 Lesson 1 Introduction to Hardware ............8 Lesson 2 Introduction to Software ............13 Unit 2 Hardware and Programming ..............22 Lesson 3 First Project: Light up LED ........... 24 Lesson 4 Hello World in Electronic Hardware Programming: Blink . 32 Lesson 5 Digital Signal in Circuit —...
Starter Guide of Raspberry Pi Pico Based on MicroPython. Through four chapters and a total of 16 lessons of study, this course can help you get started with Raspberry Pi Pico easily. With its help, you can learn MicroPython from scratch, and build some interesting projects.
Page 5
In the hardware portion, we need to understand the functions and features of Raspberry Pi Pico, and the basic functions of Grove Shield for Pi Pico and Grove modules. In software, we need to understand the concepts of Python and MicroPython, learn the installation and use of the Thonny integrated development environment or IDE, and write our first program to output characters through serial port: Hello World.
Page 8
Grove modules, which can enable quick project protyping without jumper wires and welding, and consolidate the learned knowledge in practice. Because the Grove Starter Kit does not include the Raspberry Pi Pico itself, we will need to prepare the following two kits before the start of the course.
Hello! Welcome to the starter guide of Raspberry Pi Pico based on MicroPython. This guide is a course based on the Starter Kit developed by Raspberry Pi Pico. In this course, we will use Raspberry Pi Pico as the controller, along with the Grove Starter Kit of Raspberry Pi Pico, to learn how to program Pico with MicroPython.
Page 12
Grove connectors on one compact expansion board, including 2 * I2C, 3 * ADC, 2 * UART, 3 * Digital ports, SWD debug interface and an SPI pin. When using Pico and Grove modules to build a prototype or project, you no longer need to do complicated wiring work.
Page 13
The Grove Starter Kit of Raspberry Pi Pico is a learning kit that can help you quickly start building projects with Raspberry Pi Pico. The kit contains 14 handpicked modules, including 5 sensors/ 5 actuators/ 2LED/ 1 LCD display/ 1 Grove Shield for Pi Pico. Let's take a look at these Grove modules one by one.
Page 14
Lesson 1 Introduction to Hardware Grove - Button Grove - Button is an independent “momentary on/off" button. “Momentary" means that the button rebounds on its own after it is released. The button outputs a high signal when pressed, and a low when released. Grove - LED Pack Grove - LED Pack includes LEDs in four different colours: red, green, blue and white.
Page 15
That's the basic information about the electronic modules included in the Raspberry Pi Pico and the Grove Starter Kits of Raspberry Pi Pico. More interesting information about them will be presented as we go along in the later courses.
Lesson 2 Introduction to Software Lesson 2 Introduction to Software To build interesting projects with Raspberry Pi Pico, you need to learn how to program it first. Raspberry Pi Pico supports two types of programming languages: C++ and MicroPython. C++ is a general-purpose language developed on the basis of the C language. It is often used in the development of ESP32 and Arduino, so most microcontroller users are familiar with this language.
Page 17
Beginner's Guide for Raspberry Pi Pico However, the powerful Python is not omnipotent. Although Python performs well on desktop computers, large terminals and servers, it cannot be deployed on microcontrollers with limited resources and small memory. As a result, MicroPython, a Python-based interpreted language specially designed for microcontrollers, was born.
Page 18
Lesson 2 Introduction to Software Practice & Operation In this lesson, we will write and run our first program on Pico: Hello World! But before we start, we will need to do some preparatory work. 1. Install Thonny The installation of Thonny is very simple. Since Python 3.7 is built into Thonny, all you need is a simple installer and you're ready to start learning to program.
Page 19
Pico itself.The MicroPython firmware download link is preloaded inside Pico, so we can directly use this link to enter the download interface. First, hold down the “BOOTSEL" button on Pico; then, while still holding it down, connect Pico to a computer using a USB cable.
Page 20
Open INDEX.HTM to be taken to the download page. Drop down and click on the MicroPython tab where you can find information about Pico and MicroPython. Click on the “Download UF2.file" button in this tab to download the MicroPython firmware.
Page 21
Now, let's take a look at how to write your first program. First, connect Pico to the computer using a USB cable; then, open Thonny, and click on the “restart back-end process" button on the toolbar. If you successfully connect Pico to your computer, you will see the MicroPython version information and device name returned by Pico in the Shell area.
Page 22
Lesson 2 Introduction to Software After connected, click on the Shell area and type the instruction: print() is a common function used as a printout. When you need to output some data to the Shell, you can use this function. When you press ENTER after you type the instruction, you’ll see the execution result of the input instruction is displayed in the Python Shell area, which means, the message “Hello, World!"...
Page 23
To be honest, there's no definitive answer. Where you save your program depends on your needs. If you want to show your program to your friends, you should save it to your Pico and take it with you. If you simply want to save the program for later use, just save it to your computer.
Page 24
Lesson 2 Introduction to Software Thinking Expanding Try using the print() function to print other information, such as your name, age, etc.
Beginner's Guide for Raspberry Pi Pico Lesson 3 First Project: Light up LED In the previous lesson, you've learned a little about how to work with Pico and write your very first program. However, we so far run the program on Pico without using any other external electronic hardware.
Page 28
Grove Shield for Pi Pico to connect Pico to other Grove electronics for more interesting projects. Upon observation, you might notice that Pico does not come with the metal pins to connect the Grove Shield for Pi Pico. To do so, you need to solder the headers for Pico.
Page 29
Beginner's Guide for Raspberry Pi Pico Put your soldering iron in its stand, and turn on the switch to heat it. It will take 3–5 minutes for the tip of the iron to get hot. Make sure the metal tip isn't resting up against anything when heating.During heating, dampen your cleaning sponge first and put it in a convenient place for...
Page 30
After soldering, slowly pull Pico out of the breadboard. If the pins and the breadboard are plugged too tightly, forcibly pulling Pico out will easily cause the pads to fall off. If this happens, you can shake Pico from side to side, and try to move Pico out bit by bit.
Page 31
Beginner's Guide for Raspberry Pi Pico When inserting, you can observe the screen print of pins on the back of Pico and the screen print on the Shield to check whether your inserting direction is correct. Then, connect the Grove - LED to the D16 port of the Shield using the Grove cables.
Page 32
In the development of hardware projects, it is not sufficient to simply connect the hardware to the Pico. For example, we have connected LED to D16 of the Shield, but Pico would not be aware of this unless we specifically informed it – you have to write a program to define the pins that control the electronic hardware.In the machine library, there is a class of functions called “Pin".
Page 33
Our first hardware program is finished. The complete program code is as follows: After we finish the program, use a USB cable to connect Pico to the computer, as shown in the following figure. In the following lessons, when we want to run a program, we always need to connect Pico and the computer with a USB cable.
Page 34
Lesson 3 First Project: Light up LED Thinking Expanding Try to turn off the LED using the program.
Beginner's Guide for Raspberry Pi Pico Lesson 4 Hello World in Electronic Hardware Programming: Blink When we try software programming with a certain language, “Hello World" is often the first program we write. Blink, which is the task of flashing an LED, is the Hello World in the electronic hardware world.
Page 36
Lesson 4 Hello World in Electronic Hardware Programming: Blink ·Note· What is a variable? Variables are values that have no fixed values and can be changed at any time. We use variables to store data so that they can be called in later portions of our code. In a program, a variable generally has two aspects: variable name and variable value.
Page 37
Beginner's Guide for Raspberry Pi Pico ·Note· Python is very strict on code indentation. The same level of code block indentation must be consistent. In general, we can use BACKSPACE or TAB to complete the indentation. However, whether we manually type multiple spaces or use TAB to indent, we usually define the length on an indentation as four spaces (by default, one tab is equal to four spaces).
Page 38
Hardware Connection In this project, we will use the following electronics hardware: • Raspberry Pi Pico • Grove Shield for Pi Pico • Grove - LED Pack Similar to before, we connect the LED to D16. In the last lesson, we have learned how to control the LED on and off. To realize the final Blink program, we only need to make some slight modifications.
Page 39
Beginner's Guide for Raspberry Pi Pico ·Note· Utime Function Library The utime function library is one of the standard libraries of MicroPython, and its functions provide us with time-related functions such as obtaining time and date, measuring time interval, setting delay and so on.
Page 40
Lesson 4 Hello World in Electronic Hardware Programming: Blink When we execute this program, we can find that the LED stops flashing after ten loops. This is because there are only 10 integers generated by using the range() function, so the for-loop only loops 10 times.
Page 41
Beginner's Guide for Raspberry Pi Pico Click the “run" button again, and the LED connected to the Shield starts flashing. Unless the process is artificially stopped, the LED will continue to flash.
Page 42
Lesson 4 Hello World in Electronic Hardware Programming: Blink Thinking Expanding Try to use the two loop structures and sleep() function to achieve different lighting effects. For example, you can reduce the delay time to produce more rapid flashing.
LED. Knowledge Base Whether it is to use the button to control the LED on or off, or use Pico to control other types of electronic modules, the key lies in the signal transmission. In an electronic circuit, we generally divide signals into two types: digital signal and analog signal.
Page 44
Lesson 5 Digital Signal in Circuit — Playing with LED take an umbrella if it’s raining, and vice versa. In Python, you can use the “if... else" statement to write such evaluative condition in the following three forms. “if" statement This is the simplest conditional judgment.
Page 45
The Grove - Button is a simple module. When the button is pressed, its return value is 1. When the button is released, its return value is 0.Connect Pico and the Shield. Use Grove data cables to connect the button to D16, and the LED to D18.
Page 46
1 and the LED is switched on; otherwise, the LED remains off: Use a USB cable to connect Pico to the computer, click the “run" button to save the program to any location. Now, press the Grove button to see the program in action!
Page 47
Beginner's Guide for Raspberry Pi Pico Project 2: Button Light By observing the implementation of the program in Project 1, we find that the LED only lights up when the button is pressed. When we release it, the LED will turn off immediately. This is not the same as a typical button light in our daily life, which turns on when pressed, and off when pressed again.
Page 48
Lesson 5 Digital Signal in Circuit — Playing with LED Then, write a program to run in an indefinite “while True" loop. Each time the button is pressed, the value of this variable will be increased by 1: We just need to switch the value of the variable between 0 and 1. Thus, when the value of the variable is increased to 2, we will reset it to 0.
Page 49
Beginner's Guide for Raspberry Pi Pico Thinking Expanding When you write the program, you will find that every time you use a function from a library, you need to define the function fully as referenced from the machine library. It is a bit...
Page 50
Lesson 5 Digital Signal in Circuit — Playing with LED Here, we can write the program in a more concise way: Unlike “import", which imports an entire library, “from...import" only imports some functions in the library. After we use "from...import" to import the class of the function we want to use, we can use the function directly in the later program without having to continuously declare which library the function comes.
These transistors can only switch between two states: on (1) or off (0) — just like a digital signal, which enables Pico to process digital signals directly. For the analog signals which cannot be described with 0s and 1s, the analog signals must be converted into digital signals before they can be recognized by Pico.
Page 52
Lesson 6 Analog Signal in Circuit (1) — Rotary Angle Sensor In this lesson, we will first use a Rotary Angle Sensor that inputs analog signals to Pico, to help you understand the input of analog signals. Rotary Angle Sensor By definition, a rotary potentiometer refers to a potentiometer that can change its resistance value according to the rotation of the adjusting knob on the potentiometer.
Page 53
Beginner's Guide for Raspberry Pi Pico Comparison Operator Comparison operators, also known as relational operators, are used to compare the values of constants, variables, or expressions. If the comparison is true, it returns True; otherwise, it returns False. In fact, you would have seen them in various conditional judgment statements in the projects of previous lessons.
Page 54
Lesson 6 Analog Signal in Circuit (1) — Rotary Angle Sensor Practice & Operation Next, we will use the Rotary Angle Sensor to input analog signal to Pico to control the LED. But before that, we need to understand the range of values for the analog signal returned by the Rotary Angle Sensor.
Page 55
The complete program is as follows: Use a USB cable to connect Pico to the computer, click the “run" button to save the program to any location, you can see the analog value returned by Rotary Angle Sensor in the Shell area.
Page 56
• Grove Shield for Pi Pico • Grove - LED Pack • Grove - Rotary Angle Sensor Plug the Pico and the Shield, use a Grove data cable to connect the LED to D16, and connect the Rotary Angle Sensor to A1. Write a Program...
Page 57
Beginner's Guide for Raspberry Pi Pico In the "if" statement, we use the comparison operator ">" to compare the relationship between the analog value read from the Rotary Angle Sensor and the 30000 threshold. You can test the effect of the program by changing the comparison operator used in the "if"...
Page 58
Lesson 6 Analog Signal in Circuit (1) — Rotary Angle Sensor Thinking Expanding Try to explore more uses of operators with the LED and the Rotary Angle Sensor. For example, when the reading of the Rotary Angle Sensor is greater than 30000, program the LED to turn off;...
Similarly, Pico cannot directly send an analog signal to control the analog circuit. It must first convert its digital signal into an analog signal in some way. However, Pico itself does not have a DAC (Digital to Analog Converter) to convert a digital signal into an analog signal. So when Pico needs to output an analog signal, it needs to use another method to control the analog circuit —...
Page 60
Lesson 7 Analog Signal in Circuit (2) — the Use of PWM The objective of pulse width modulation is to modulate the duty cycle of the pulse signal according to the demand without changing other parameters of the pulse signal, so as to disguise a digital signal as a constant voltage analog signal.
Page 61
• Raspberry Pi Pico • Grove Shield for Pi Pico • Grove - Rotary Angle Sensor Plug the Pico and the Shield, use a Grove data cable to connect the LED to D18, and connect the Rotary Angle Sensor to A0.
Page 62
Just like the Pin function, the function of setting pins to PWM mode is also available in the machine library: We need to use PWM to set related pins. Although each pin of Pico can be set as a PWM pin, some pins cannot be simultaneously set to PWM mode. This is because the pulse width modulator on Pico is divided into eight parts, where each part has two outputs —...
Page 63
“val", and then set the duty cycle of the PWM signal of the LED to “val". The complete program is as follows: Use a USB cable to connect Pico to the computer, click the “run" button to save the program to any location, you can see the actual running effect of the program.
Page 64
Hardware Connection In this project, the electronic hardware we need to use is as follows: • Raspberry Pi Pico • Grove Shield for Pi Pico • Grove - LED Pack Connect the LED to D18. Write a Program To realize the effect of breathing light, we need to use arithmetic operators to operate the duty cycle of the PWM signal.First, declare the...
Page 65
Beginner's Guide for Raspberry Pi Pico After setting the pin, use the “freq()" function to set the frequency of the PWM signal to 500: Through analysis, we can find that the breathing light is actually composed of two parts. The first part is that the LED lights up gradually from the dim state, and enters the second part when the brightness reaches the maximum.
Page 66
Lesson 7 Analog Signal in Circuit (2) — the Use of PWM Use a USB cable to connect Pico to the computer, click the “run" button to save the program to any location, you can see the program in action.
Beginner's Guide for Raspberry Pi Pico Lesson 8 Make Buzzer Sing — the Use of Function The term “function" in mathematics generally refers to a corresponding relationship and change process between values. In the field of programming, a function is a program with specific functions that can complete specific tasks, thus reducing the workload of repetitive programming.
Page 68
Lesson 8 Make Buzzer Sing — the Use of Function The oscillation source is the oscillation circuit, which can convert the input DC signal into a physical oscillation which drives the buzzer to sound.The active buzzer has a built-in oscillation source, which can work by providing a constant DC voltage when it is in use.
Page 69
Beginner's Guide for Raspberry Pi Pico The execution result of the program is as follows: In this program, we define a function named “HelloWorld". Every time we call the function with “HelloWorld()", we execute the “print(“Hello World")" statement in the function body.
Page 70
Lesson 8 Make Buzzer Sing — the Use of Function Attach the Pico and the Shield, and use a Grove data cable to connect the buzzer to A1. Write a Program If we want to use the buzzer to play music, we need to learn to control the two dimensions of the sound emitted by the buzzer: volume and tone.
Page 71
Finally, use “sleep()" to specify the duration of each note, and complete the program. The complete program is as follows: Use a USB cable to connect Pico to the computer, click the “run" button to save the program to any location. Now, you can hear the buzzer play seven basic notes.
Page 72
Lesson 8 Make Buzzer Sing — the Use of Function music, whether it is from the perspective of improving code reuse or program readability, we need to use custom functions to simplify the program. Following Project 1, we can define every note as a function that can be called when we want to play that note.
Page 74
Lesson 8 Make Buzzer Sing — the Use of Function In the fifth line of the program, we defined a variable named “vol" to represent the duty cycle value of the PWM signal in later programs. Now, whenever we want to modify the volume of the buzzer, we only need to modify the initial value of the variable “vol".
Page 76
Lesson 8 Make Buzzer Sing — the Use of Function Use a USB cable to connect Pico to the computer, and click the “run" button to save the program to any location. Now, you can hear the buzzer play Two Tigers.
In our previous projects, if we want to visualize data, we normally rely on the Thonny Shell. However, in some projects, we cannot always connect Pico to the computer. At this time, we need to use some other electronic hardware to complete this work, and a variety of display devices come in handy.
Page 78
Lesson 9 Journey of Data Visualization — the Use of LCD When scientists heat the solid liquid crystal to 145℃ , the liquid crystal first melts into a turbid liquid. When they continue to heat the liquid crystal to 175℃ , it melts again and becomes a clear and transparent liquid.
Page 79
Beginner's Guide for Raspberry Pi Pico Significantly, the liquid crystal itself cannot produce light, it can only change the direction of the light passing through it. So, in addition to the liquid crystal layer, we often need a backlight panel as the light source in an LCD. According to this characteristic, RCA developed a dynamic scattering LCD, and used this technology to develop the first LCD watch in 1972.
Page 80
1. Click to download the third-party library file we want to use, and save it to the computer. 2. Connect Pico to the computer, use Thonny to open the file, click on the “file" option at the top left, and select “save as".
Page 81
In this project, the electronic hardware we need to use is as follows: • Raspberry Pi Pico • Grove Shield for Pi Pico • Grove - 16 x 2 LCD Plug the Pico and the Shield, use a Grove data cable to connect the LCD to I2C1.
Page 82
Write a Program First, define the function libraries that we need to use, including the third-party function library lcd1602 that has just been saved in the Pico. The functions available in the lcd library are as follows: • display() — Enable the display.
Page 83
Beginner's Guide for Raspberry Pi Pico Use a USB cable to connect Pico to the computer, click the “run" button to save the program to any location, you can see the program in action. Project 2: Display Rotary Angle Sensor Reading with LCD In addition to displaying the characters we have written, the LCD can also display the values returned by other sensors.
Page 84
Lesson 9 Journey of Data Visualization — the Use of LCD Write a Program In Lesson 6, we learned how to use ADC to read the Rotary Angle Sensor value. Can we use “d.print()" to display the reading directly? Let's try the following program first: Running the program, Thonny tells us that there is an error in the program, and the error is on line 14.
Page 85
Beginner's Guide for Raspberry Pi Pico This means that the parameter we pass into the print() function is not of the type it can execute. ·Note· Data Type In programming, due to the different storage capacities of various data, different types of data need to be matched with the different memory spaces that they are stored in.
Page 86
Lesson 9 Journey of Data Visualization — the Use of LCD Use a USB cable to connect Pico to the computer, click the “run" button to save the program to any location, rotate the Rotary Angle Sensor, you can see the actual running effect of the program.
Beginner's Guide for Raspberry Pi Pico Lesson 10 Temperature and Humidity Monitoring There are plenty of uses for temperature and humidity monitoring, like weather forecasting. We pay attention to the temperature every day, especially for seasonal changes in weather where we may need to alter our attire according to changes in temperature.
Page 90
In this project, we will use the Shield to connect both the temperature and humidity sensor and LCD module, and use the Pico to display the temperature and humidity value obtained by the sensor on the LCD. First of all, we need to use the LCD to display the value of temperature and humidity.
Page 91
Download the library file in the same way dht11.py(3kB) as in previous lessons and save it in Pico. After that, we can start to import the libraries that we need to use. Recall how we defined the I2C pin in the last lesson. To achieve I2C, we must define both the SCL and SDA data lines and mark the data type, number of lines and the number of characters in each line.
Page 92
The complete program is as follows: Use a USB cable to connect Pico to the computer, click the “run" button to save the program to any location, and you can see program in action.
Page 93
Beginner's Guide for Raspberry Pi Pico Project 2: Adding an Alarm Function In Project 1, we developed the function of displaying the temperature and humidity value on the LCD. We can now also further develop the functions of monitoring and alerting by adding a buzzer.
Page 94
Lesson 10 Temperature and Humidity Monitoring Write a Program Expanding from Project 1, we only need to add code to judge the temperature and humidity and control the buzzer for the alarm behaviour. To do this, we need to use the logical operator. Logical operators can connect two or more simple statements to form more complex statements.
Page 95
Beginner's Guide for Raspberry Pi Pico Use a USB cable to connect Pico to the computer and click the “run" button to save the program to any location. Hold the temperature and humidity sensor with your hand, and you should see the changing values of temperature and humidity on the LCD.
Page 96
Lesson 10 Temperature and Humidity Monitoring Take note that they have slightly different definitions of pins. Download dht20.pylibrary(2kB) use DHT20 to detect the temperature and humidity in the environment, and print the value to the Shell area. With the “dht20.py" library, we can use the “dht20_temperature()" and “dht20_ humidity()"...
Beginner's Guide for Raspberry Pi Pico Lesson 11 Intelligent Fan Although air conditioning is now the people's first choice for cooling, fans have always been popular in daily life due to their portability, energy-saving characteristics and availability. In this lesson, we will make an intelligent fan that can be automatically controlled according to the surrounding temperature.
Page 98
Hardware Connection In this project, the electronic hardware we need to use is as follows: • Raspberry Pi Pico • Grove Shield for Pi Pico • Grove - Mini Fan • Grove - Button Use a Grove data cable to connect the Button to D16 on the Grove Shield, and connect the Mini Fan to D18.
Page 99
“toggle” the fan on and off. Use a USB cable to connect Pico to the computer, click the “run" button to save the program to any location, and then test the running effect by pressing the button.
Page 100
In this project, the electronic hardware we need to use is as follows: • Raspberry Pi Pico • Grove Shield for Pi Pico • Grove - Mini Fan • Grove – Temperature & Humidity Sensor • Grove - 16 x 2 LCD Use a Grove data cable to connect the Temperature &...
Page 101
Beginner's Guide for Raspberry Pi Pico Write a Program First of all, import the required libraries and set the pins of the temperature and humidity sensor, LCD and mini fan. Next, read the value detected by the temperature and humidity sensor — here we only need to read the temperature value —...
Page 102
If you are using a DHT20 temperature and humidity sensor, refer to the following program: Use a USB cable to connect Pico to the computer, and click the “run" button to save the program to any location. Now, you can see the actual running effect of the program.
Page 103
Beginner's Guide for Raspberry Pi Pico In addition to controlling the fan through a button and temperature sensing, what other control methods can you think of? Give it a try. Thinking Expanding The Grove Relay is a digital normally-open switch, which can handle up to 5A current under 250VAC for a long time.
Page 104
Lesson 11 Intelligent Fan After the circuit is connected, we can begin to write the program. We want to write a high output level to the fan and control the switch of the relay through the button, so as to control the opening and closing of the whole circuit.
Beginner's Guide for Raspberry Pi Pico Lesson 12 Intelligent Light Light is an essential electrical appliance in life. Since Edison invented the electric light bulb in 1879, the technology of electric light has been developing and becoming more and more intelligent.
Page 106
Lesson 12 Intelligent Light In light-controlled lighting, the photoresistor of the light sensor adjusts the resistance value according to the light intensity in the environment. When the light intensity is larger, the resistance value decreases and the analog value of the light sensor output is larger. We can control the light on or off or brightness according to this value.
Page 107
In this project, the electronic hardware we need to use is as follows: • Raspberry Pi Pico • Grove Shield for Pi Pico • Grove - RGB LED (WS2813 Mini) Connect the Pico and the Grove Shield, use a Grove data cable to connect the RGB LED to D18.
Page 108
To interface with the new WS2813 RGB LED module, we will need a new library ws2812. py(2kB) to control the RGB LED. After downloading the library file and saving it in Pico, we can start to introduce the function library we need. The functions used in the ws2812 library are as follows: •...
Page 109
Beginner's Guide for Raspberry Pi Pico The complete program is as follows: Use a USB cable to connect Pico to the computer, click the “run" button to save the program to any location. Now, you can see the RGB LED displays different colors.
Page 110
• Grove - RGB LED (WS2813 Mini) • Grove - Light Sensor • Grove - Sound Sensor Connect the Pico and the Shield, use a Grove data cable to connect the light sensor to A0, sound sensor to A1, and RGB LED to D18.
Page 111
Beginner's Guide for Raspberry Pi Pico Next, we use read_u16() to read the values of the light sensor and the sound sensor, store them in the “light" and "noise" variables respectively. Then, we use the print() function to display the values in the Shell area.
Page 112
Lesson 12 Intelligent Light The complete program is as follows:...
Page 113
Beginner's Guide for Raspberry Pi Pico Running the program, we find that the effect of the light sensor is as expected, but the effect of the sound sensor appears to be unstable. Amend print(light) to print(noise), and print the value detected by the sound sensor in the Shell area.
Page 114
Lesson 12 Intelligent Light Running the program, we can find that the lighting part and the noise warning part are all successfully realized.
Page 115
Beginner's Guide for Raspberry Pi Pico Thinking Expanding In Project 1, we displayed different colors in turn by controlling the RGB LED. In the process, we called the functions set in the ws2812 library. There are other light effects in this library; let's...
Beginner's Guide for Raspberry Pi Pico Lesson 13 Automatic Door An automatic door. You arrive in front of the door and it opens automatically. Isn’t it convenient? Well, that’s what we’re going to achieve this lesson. Looking back, we haven’t touched on any electronic module that can detect the human body or actuate the door’s motion.
Page 118
100Hz, and the relationship among the corresponding pulse width, rotation angle and duty_u16 value are as follows: Next, we will try to control the Servo by PWM signal. Project 1: Control Servo Hardware Connection In this project, the electronic hardware we need to use is as follows: • Raspberry Pi Pico...
Page 119
Beginner's Guide for Raspberry Pi Pico • Grove Shield for Pi Pico • Grove - Servo Use a Grove data cable to connect Servo to D20. According to the table above, we will try to make the Servo turn back and forth between 45° and 90° .
Page 120
Lesson 13 Automatic Door Running the program, we can see the Servo turns back and forth between 0° and 180° for ten times, which is the effect we want. If we want to control Servo to other angles, we will need to calculate the corresponding value beforehand.
Page 121
The completed library file is as follows: After completing the library file, we name it “servo.py" and store it in Pico. Then we can call the functions in the library directly. Modifying the program of Project 1 as follows, we can input...
Page 122
Hardware Connection In this project, the electronic hardware we need to use is as follows: • Raspberry Pi Pico • Grove Shield for Pi Pico • Grove – Servo • Grove – PIR Motion Sensor Connect the PIR Motion Sensor to D18, and connect the Servo to D20.
Page 123
Beginner's Guide for Raspberry Pi Pico Write a Program First, introduce the required library, and define the pins of the Servo and the PIR Motion Sensor. Here, we refer to the newly built servo library. There are only two states of the PIR Motion Sensor, triggered and not triggered. Therefore, we only need to judge whether the returned value is 1.
Page 124
Lesson 13 Automatic Door Thinking Expanding In Project 1 and 2, we controlled the Servo rotation to the desired angle by writing the analog value to the Servo pin. Can you try to write a program to make the Servo gradually rotate from 0° to 180°...
Beginner's Guide for Raspberry Pi Pico Lesson 14 Welcome Device In this lesson, we will summarize the projects of this chapter and explore new projects through different combinations of electronic hardware. We will also prepare for creating your own projects by consolidating the creation and use of software libraries through practice.
Page 126
In this project, the electronic hardware we need to use is as follows: • Raspberry Pi Pico • Grove Shield for Pi Pico • Grove - Passive Buzzer Plug the Pico and the Shield, use a Grove data cable to connect the buzzer to A1.
Page 127
First, create a buzzer library. In it, we define the PWM pin and seven basic notes of the buzzer as follows: After creating the library file, name it “buzzer.py" and save it in the Pico. Now, you can call the buzzer library to play music.
Page 128
Servo should turn to open the door, the LCD should display “welcome", and the buzzer should finally play the welcome music. Hardware Connection In this project, the electronic hardware we need to use is as follows: • Raspberry Pi Pico...
Page 129
Beginner's Guide for Raspberry Pi Pico • Grove Shield for Pi Pico • Grove - Passive Buzzer • Grove - 16x2 LCD • Grove - Servo • Grove - PIR Motion Sensor Connect the buzzer to A1, connect the PIR Motion Sensor to D18, connect the Servo to D20, and connect the LCD to I2C1.
Page 130
Lesson 14 Welcome Device Next, we use the “if" statement to evaluate the state detected by the PIR Motion Sensor. When a person is detected, the Servo rotates 160° to open the door, the LCD displays “welcome", and the buzzer starts to play the welcome music.To achieve our welcome sequence, all we have to do is combine the steps that we have learned in the previous lessons.
Page 131
Beginner's Guide for Raspberry Pi Pico After completion, save the program in any location of the computer, move your hand around to the PIR Motion Sensor, and test the effect of the welcome device.
Page 132
Lesson 14 Welcome Device Thinking Expanding In this lesson, we expanded the automatic door project by using what we have learned before to complete the function of the welcome device. Next, try to realize the project you conceptualized on your own!
Beginner's Guide for Raspberry Pi Pico Lesson 15 Create Your Own Projects In previous lessons, we have learned a great deal of knowledge surrounding the Pico and supporting electronic hardware, in addition to programming with Thonny. At this point, we have mastered the basic programming language of MicroPython and applied it through various projects.
Page 136
Lesson 15 Create Your Own Projects It is recommended for a large number of people to participate in the Empathy Map together. It is mainly divided into the following parts: SAYS What does he/she usually say? What do they need to say to others? How would they express themselves? THINKS How does he/she consider the current situation?
Page 137
Beginner's Guide for Raspberry Pi Pico Unlike the general straight-line path of finding and solving problems, it explores every link. Taking product design as an example, from the beginning of finding problems, we should stand in the perspective of the user, understand the user through empathy, listen to the real voice of the user, and form the user portrait.
Page 138
Lesson 15 Create Your Own Projects As can be seen from the above table, even for the hardware selection of prototype products, many factors can be considered and will contribute to your final design. Then, we have to devise the entire program to achieve our intended purpose in software. So far, the functional part of the prototype product is completed.
Page 139
Beginner's Guide for Raspberry Pi Pico Go Through Fire and Water — Testing and Optimization of Prototype Works After completing our prototype, testing and optimization are also very important. We need to verify whether its function is realized and whether it meets the original design requirements. This process should involve the target users as much as possible and lead into further improvements through their feedback.
Beginner's Guide for Raspberry Pi Pico Lesson 16 Project Presentation In this lesson, we will share and show your projects in the form of a project presentation. You can showcase your project and the story behind it through posters, PPTs or videos. Through this process, we can consolidate the key knowledge of of previous lessons by immersing in discussion and communication, and learn to share, and think and explore problems from different angles.
Page 142
Lesson 16 Project Presentation Presentation 1.Product Showcase Each group explains and shows the products in turn under the arrangement of the host. 2.Expert Comments The invited experts and teachers comment on the performance of the group. 3. Selection After all products are showed, the selection shall be carried out. 4.
Page 143
Beginner's Guide for Raspberry Pi Pico Of course, we would also love to have you share your project with us. Email: contact@chaihuo.org...
Page 144
Lesson 16 Project Presentation Course Developers This course was co-authored by the following SeeedStudio employees: Authors:Yimeng Shi, Haixu Liu Designer:Yihui Meng Proofreaders:Lei Feng,Jonathan Tan CONTACTS Tel: +86-0755-86716703 Address: 1002, G3 Building, TCL International E City, 1001 Zhongshan Park Road, Nanshan District, Shenzhen General:contact@chaihuo.org Tech Support: techsupport@chaihuo.org...
Page 145
Beginner's Guide for Raspberry Pi Pico...
Need help?
Do you have a question about the Pico and is the answer not in the manual?
Questions and answers