0% found this document useful (0 votes)
159 views42 pages

Pico Bookletv2

The 'Raspberry Pi Pico Application Book' serves as a comprehensive guide for beginners to learn electronics and coding using the Raspberry Pi Pico and Arduino programming. It covers essential topics such as installing the Thonny IDE, programming with MicroPython, and creating various projects including LED control, temperature measurement, burglar alarms, and weather monitoring. The book aims to facilitate the learning process and encourages users to practice and share their projects and suggestions.

Uploaded by

pvtpabo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
159 views42 pages

Pico Bookletv2

The 'Raspberry Pi Pico Application Book' serves as a comprehensive guide for beginners to learn electronics and coding using the Raspberry Pi Pico and Arduino programming. It covers essential topics such as installing the Thonny IDE, programming with MicroPython, and creating various projects including LED control, temperature measurement, burglar alarms, and weather monitoring. The book aims to facilitate the learning process and encourages users to practice and share their projects and suggestions.

Uploaded by

pvtpabo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

Raspberry Pi Pico Application Book

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.

It just takes a li le pa ence, so you can learn Arduino programming with an


easy and correct roadmap, star ng from the easy and moving towards more
complex. If you want to watch more detailed video explana ons of the
applica ons, you can go to our YouTube channel by scanning the QR code at
the back of the book. You can access the codes wri en in the booklet both
from the descrip on sec on of the related videos and from our blog page.

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

Installing Thonny IDE.............................................................................................6

Installing Micropython Firmware on Raspberry Pi Pico........................................9

Introducing Thonny IDE Interface........................................................................12

Blink Internal LED.................................................................................................15

LED Control with Button......................................................................................18

Temperature Measurement with Pico.................................................................21

Burglar Alarm Using Raspberry Pi Pico................................................................24

Raspberry Pi Pico Weather Monitor....................................................................28

Using of Distance Sensor.....................................................................................38


Raspberry Pi Pico'yu
Tanıyalım
Introducing Raspberry Pi Pico

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

Lastly, You click “Finish”

8
Raspberry Pi Pico'ya
MicroPython Firmware'i
Yükleme
Installing Micropython Firmware on Raspberry Pi Pico

Raspberry Pi Pico is programmable in two programming language that MicroPython and


“C/C++”. You need to download the suitable "firmware" file for programming your Pico.

Just follow the instructions to download. https://www.raspberrypi.org/


documentation/rp2040/getting-started/

You click “Download UF2 file” and download the "firmware"

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.

Copy the “*.UF2” file that downloaded on that folder.

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.

1. You can open a new file with this icon


2. You can open scripts you have saved with this icon
3. You can save the script with this icon
4. You can run the script with this icon
5. You can stop the script with this icon

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”.

After that,you will see a tab like these


screenshots..

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.

When the code runs, the


internal LED on your Pico will
blink and flash at half-second
intervals.

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.

Then open your Thonny IDE and


edit the "blink" code you have
written in the previous project.
Open it by double clicking on the
"blink.py" file on the left side of
Thonny IDE. The codes you have
written in the previous project
will be opened. Now you will
delete these codes completely
and write new code.

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.

Now you will be able to


turn the LED on and off by
pressing the button. Move
on to the next project.

20
Raspberry Pi Pico ile
Sıcaklık Ölçümü
Temperature Measurement with Pico

As I mentioned at the beginning, Raspberry Pi Pico has an internal temperature sensor. So


why not take a temperature measurement?

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

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.

Write "temp.py" as the file name,


click the "OK" button and now you
can read the temperature data
from Shell.

In the Shell window at the


bottom, you can see the
temperature data from your Pico
every 2 seconds.

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

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.

Write "hirsiz.py" as the file name


and click on the "OK" button and
now, in case of any situation that
triggers our motion sensor, the
buzzer will sound and our LED will
light.

In the Shell window at the bottom,


when motion is detected,
“ATTENTION! Motion Detected! ”
text will appear.

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.

Now download the


necessary library to use our
LCD screen from https://
github.com/T-622/RPI-
PICO-I2C-LCD. When open
the link, click the green
button that says "Code" and
then click the "Download
ZIP" button to download the
library.

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.

Then click the "OK" button to save it to the folder

32
Weather Monitor

Do the same for the other two files.

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

After typing the code "Print


(file.read ())", you can see the
recorded data as in the adjacent
photo.

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.

1 from machine import Pin


2 import utime
3
4 trigger = Pin(18, Pin.OUT)
5 echo = Pin(21, Pin.IN)
6
7 def echoTime():
8 trigger.value(0)
9 utime.sleep_us(5)
10 trigger.value(1)
11 utime.sleep_us(10)
12 trigger.value(0)
13 try:
14 echoTime = machine.time_pulse_us(echo, 1, 1000000)
15 cm = (echoTime * 0.034321) * 0.5
16
17 print(str(cm)+" cm")
18 except OSError as e:
19 print(e)
20
21 while True:
22 echoTime()
23 utime.sleep(5)

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

You might also like