Pico Bookletv2
Pico Bookletv2
Welcome to the world of Electronics and Coding. Now that you have opened
this book, you are eager to swim in the sea of wonder and learn new things.
Although learning new things in such ma ers is thought to be difficult, if you
proceed step by step and with the right prac ces, you will realize that it is very
simple. As long as the applica ons are made in the early stages, there will be
places that do not sit down. You will overcome this problem as you prac ce.
This book was wri en by Robo stan Electronics™ the purpose of wri ng is to
guide those who want to start Arduino in an easy and correct way. Our hope is
that these contents will be beneficial to everyone and facilitate your learning
process and make projects quickly.
You can send us your set contents, applica ons, videos and any sugges ons
and ques ons you have in mind at info@robo stan.com
Roboistan Team
Contents
Introducing Raspberry Pi Pico................................................................................4
Raspberry Pi Pico that was released by Raspberry Pi Foundation is a microcontroller that might
use in our Embedded systems projects, prototyping or to the Micropython presented to us for
both electronic and in learning coding. Raspberry Pi Pico, which is quite powerful compared to
Ar-duino Nano, stands out with its 32-bit Arm Cortex M0 + 133 MHz processor. Thanks to the
tempera-ture sensor on it, it will be very easy for us to make projects such as a weather
monitor.
5
Raspberry Pi Pico’ya
Thonny IDE Kurulumu
Installing Thonny IDE
Firstly, You should download Thonny Ide which right version for your operating system
on link https://thonny.org. In this blog, you will see the version for Windows 10.
You run the installation file you downloaded. Follow the these screenshots to complete the
installa-tion process. You just need to click “Next”.
7
Raspberry Pi Pico’ya Thonny IDE Kurulumu
8
Raspberry Pi Pico'ya
MicroPython Firmware'i
Yükleme
Installing Micropython Firmware on Raspberry Pi Pico
10
Raspberry Pi Pico'ya MicroPython Firmware'i Yükleme
Connect to our computer by holding down the "BOOTSEL" button on your Pico. You will
see the folder when you connected.
When the copying process is finished, the folder will close automatically.
11
Thonny IDE
Arayüzünü Tanıyalım
Introducing Thonny IDE Interface
Unlike Arduino, Raspberry Pi Pico has its own memory ,and library or scripts what you want
can be uploaded into the this memory with Thonny IDE. There are some useful things in
Thonny IDE
When you open the Thonny IDE, an interface like in the photo will welcome you. The
functions of the tabs at the top, the section I have included in the orange box, respectively;
• Files: On this tab, you can save scripts what you wrote, open the scripts you have writ-
ten or new Project file
• Edit: on this tab you can undo, forward, copy or select all in scripts what you have writ-
ten
• View: On this tab ,you can customize the interface
• Run: on this tab, you can run code you have written, choose Interpreter for your Rasp-
berry Pi Pico or operate like Debug on code
• Tools: On this tab, you can manage packets or edit Thonny settings
• Help: On this tab, you can get information about Thonny version or view help content
regarding your issue.
13
Introducing Thonny IDE Interface
You adjust the Interpreter Settings on Thonny IDE for using your Raspberry Pi Pico. Click
the the run tab at the top, then click Select Interpreter. Select "MicroPython (Raspberry Pi
Pico)" as the "Interpreter" and "Try to detect port automatically" as the port from the
window that opens.
Add “Files” tab that will contribute on the interface.Click the the“View” tab at the top and
select “Files”.
14
Blink Internal LED
Blink Internal LED
Type the following code into Thonny IDE this code provides the Internal LED to blink every half
second When you examine this code, you wrote the code "from machine import Pin, Timer" so
that be able to access the hardware on the Pico. In line 2, you stated that the internal LED on
the Pico is connected to pin 25. In line 3, you started timer .In line 5,you defined a blink
function. This is a simp-le function that makes the LED light. In line 8, you ran the timer. We
specified the frequency of the process with "freq" in parentheses, the mode of the timer with
the "mode" and the function we would call with the "callback".
Upload this code to your Pico. Let's click on the green "Run" icon at the top.
It asks where you want to save the code. If save the code to the computer and run it, the
code will only run when the Pico is plugged into the computer. For the code to always run.
You need to click on the "Raspberry Pi Pico" option and save it to your Pico.
16
Blink Internal LED
After clicking on the "Raspberry Pi Pico" text, a window like in the photo will open. In this win-
dow, it asks us to which location you want to save the code you wrote in Pico. You can save it
di-rectly in Pico. For this, you need to write a name and file extension to save the code youhave
writ-ten. Since you are working with MicroPython, your file extensions will always be "* .py". I
typed "blink.py" as the filename. You can also type any file name you want. After typing the file
name, you can save and run the code by clicking the "OK" button.
17
Raspberry Pi Pico ile
Buton ile LED Yakma
LED Control with Button
Once you lit LEDs, but this time, you need to realize this project in order to warm up our Pico's
hardware and breadboard usage.
Necessary Materials:
• Raspberry Pi Pico
• Breadboard
• Push Button
• LED
• Male – Male Jumper
• 220 Ω or 330 Ω Resistor
When you look at the pin diagram of your Pico, the 38th pin is "GND", ie the ground pin, the 36th
pin is the "3V3 (OUT)" pin. You will use these two pins frequently in your projects.
First, build the circuit on the breadboard according to the diagram below.
19
LED Control with Button
When you examine the codes below, you defined the hardware of Pi-co with the code "from
machine import Pin" as in the previous project and added the "time" library. With the code
"led = Pin (15, Pin.OUT)", you assigned the 15 nu-mara pin as the pin you connected to the LED.
With the code "button = Pin (14, Pin.IN, Pin.PULL_DOWN)", you defined the pin number 14 to
which you connect the button as the input pin. Then you created a "while loop". In this cycle, it
will change the status of the led according to the value read from the button. For example, if
press the button once while the LED is off, it will turn on, if the LED is on, it will turn off when
you press the button. When press and hold the button with the code "time.sleep (0.5)", the
LED will flash and flash at half-second intervals.
After writing the codes, press the "Run" icon at the top and save your codes to your Pico
and run them.
20
Raspberry Pi Pico ile
Sıcaklık Ölçümü
Temperature Measurement with Pico
First, open the Thonny IDE and open a new file and write the following codes. Now, when you
examine the codes, you have added the necessary "machine" and "utime" libraries as usual.
Since made analog readings with the temperature sensor, you defined that it was connected
to pin num-ber 4 with the code "sensor_temp = machine. ADC (4)", then you converted the
16-bit data from the sensor into voltage data that could be meaningful for you with the code
"conversion_factor". Since the Pico pin gives 3.3 volts, you divided 3.3 volts by 216 - 1 =
65535. Now, when you examine the While loop, read the data from the sensor. In the code on
line 8, multiply the data from the temperature sensor with the "conversion_factor" you just
wrote, and write the temperature data in terms of voltage. You convert the data you have
obtained to "Celsius" in the 9th line. Finally, print the temperature data to Shell with the code
"print (temp)".
Now save these codes to your Pico and run them, then press the "Run" icon at the top.
22
Temperature Measurement with Pico
23
Raspberry Pi Pico ile
Hırsız Alarmı
Burglar Alarm Using Raspberry Pi Pico
In this project, you will make a burglar alarm using PIR sensor, LED and buzzer.
Necessary materials:
• Raspberry Pi Pico
• Breadboard
• PIR Sensor
• Buzzer
• LED
• Male – Male Jumper
• Male – Female Jumper
• 220 Ω or 330 Ω Resistor
•
First, build your circuit according to the diagram below.
Now open a new file in Thonny IDE and write the following codes. . When you examine the
codes, you first added the libraries and then defined the pins to which you connected the PIR
sen-sor, Buzzer and LED. You created a function with "def pir_handler (pin)". When the motion
is detec-ted with the if block in the function, “ATTENTION! Motion Detected! ” printing, buzzer
and LED are working.
25
Burglar Alarm Using Raspberry Pi Pico
Now save these codes to your Pico and run them, then press the "Run" icon at the top.
26
Burglar Alarm Using Raspberry Pi Pico
27
Raspberry Pi Pico ile
Hava Durumu Monitörü
Weather Monitor
In this project, you will make a weather monitor using a 2X16 LCD screen. In this project, you will
learn how to add a library and automatically save the temperature data you measure in a text file.
Necessary materials:
• Raspberry Pi Pico
• Breadboard
• 2X16 LCD Screen
• Male – Female Jumper
First, build your own circuit on the breadboard according to the circuit below.
29
Weather Monitor
Open the downloaded "* .zip" file and extract the "lcd_api.py", "pico_i2c_lcd.py", "pi-
co_i2c_lcd_test.py" files to the desktop.
Open them in Thonny IDE by double clicking on these files that you extract to the desktop.
30
Weather Monitor
Now save these files to the "lib" folder in your Pico in order, click on the "Files" tab on the top
and then click on "Save as ...".
It asks where you want to save the library file. You will choose the Raspberry Pi Pico.
31
Weather Monitor
In this part, you have to choose the location where want to save the file, then type the file
name first. After that double click on the "lib" folder.
32
Weather Monitor
Now that you have added libraries, you can open a new file by clicking the "Plus" icon on the
top of a new Thonny IDE and write the following codes. When you examine the codes, first
added the libraries as in other projects, then made the settings of our 2X16 LCD screen and
created a new text document named "save" with the code "file = open (" record.txt "," w ").
33
Weather Monitor
Now save these codes to your Pico and run them, then press the "Run" icon at the top.
34
Weather Monitor
It asks where you want to save the code. For the code to always run, you need to click on
the "Raspberry Pi Pico" option and save it to our Pico.
Type "havadurumu.py" as the file name and click the "OK" button. Now, you will be able to
see the temperature data on your LCD screen and at the same time this data will be
recorded in a text document.
35
Weather Monitor
Now wait for some data to collect, then click the "Stop" icon at the top to stop the code
from running.
Write the following codes in the Shell section at the bottom so that you can see
the data have saved.
36
Weather Monitor
37
Raspberry Pi Pico ile
Mesafe Sensörü
Kullanımı
Using of Distance Sensor
In this project, you will measure distance with HC-SR04 distance sensor.
Necessary materials:
• Raspberry Pi Pico
• Breadboard
• HC-SR04 Distance Sensor
• Male – Male Jumper
First, create your circuit on the breadboard according to the diagram below.
Now open a new file in Thonny IDE and write your code. When you examine the codes, you defined
the libraries in the first two lines, and the pins to which the distance sensor is connec-ted. Also
wrote the distance measurement function with the function “def echoTime ():”. You have made the
distance measurement function, which defined with the while loop, run every 5 seconds.
39
Using of Distance Sensor
Now save these codes to your Pico and run them, then press the "Run" icon at the top.
It asks where you want to save the code. For the code to always run, you need to click on
the "Raspberry Pi Pico" option and save it to our Pico.
40
Using of Distance Sensor
Write "distance.py" as the file name and click the "OK" button.
You can now see the distance in the Shell section of the Thonny IDE.
41
Hazırlayanlar: Mehmet Mücahit KAYA(İçerik) - Mehmet AKÇALI - Yasin TAŞCIOĞLU (Editör) - Mehmet Nasır KARAER (Grafik)
[email protected] - www.robotistan.com
Tel: 0850 766 0 425