Raspberry Pi [4] for Beginners - Python3, GPIOs, Pi Camera, Flask, and More! | Edouard Renard | Skillshare

Raspberry Pi [4] for Beginners - Python3, GPIOs, Pi Camera, Flask, and More!

Edouard Renard, Software Engineer and Entrepreneur

Raspberry Pi [4] for Beginners - Python3, GPIOs, Pi Camera, Flask, and More!

Edouard Renard, Software Engineer and Entrepreneur

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
96 Lessons (9h 56m)
    • 1. Introduction

      3:33
    • 2. What is Raspberry Pi and What Can You Do With it?

      5:10
    • 3. List of Materials for this Course - and Recommendations

      7:28
    • 4. How to get the most out of this course

      1:25
    • 5. Install Raspberry Pi OS Without any External Monitor or Keyboard

      1:00
    • 6. [New] Flash the Raspberry Pi OS with SSH and Wi-Fi Setup, on your micro SD card

      5:45
    • 7. [Old 1/2] Flash the Raspberry Pi OS on your micro SD card

      3:22
    • 8. [Old 2/2] Setup Wi-Fi and SSH Directly on the micro SD card

      4:47
    • 9. Boot your Raspberry Pi For the First Time and Find its IP address

      7:42
    • 10. Connect to Your Pi using SSH

      5:41
    • 11. Setup VNC to Get a Remote Access to your Raspberry Pi OS Desktop

      9:18
    • 12. Finish the Startup Configuration - Last Steps

      11:29
    • 13. Program with Python3

      0:51
    • 14. Your first Python program - Discover the Thonny IDE

      10:59
    • 15. Variables

      10:31
    • 16. Variables - Data Types

      7:49
    • 17. Functions

      10:28
    • 18. Variables - Scope

      6:29
    • 19. Activity 01 - Create a Function to Concatenate 2 Uppercase Strings

      2:46
    • 20. Activity 01 - Solution

      8:11
    • 21. Conditions

      11:06
    • 22. Condition operators

      11:32
    • 23. Activity 02 - Validate User Input

      4:01
    • 24. Activity 02 - Solution

      4:40
    • 25. Loops

      12:26
    • 26. Lists

      14:02
    • 27. Activity 03 - Compute Max Value Inside a List

      2:02
    • 28. Activity 03 - Solution

      9:20
    • 29. Python Modules

      3:32
    • 30. Program with Python3 - Section Conclusion

      0:57
    • 31. Build Your First Raspberry Pi Circuit and Use GPIOs

      0:46
    • 32. Warning - PLEASE WATCH - How to Safely Manipulate Your Board

      3:10
    • 33. Understand How a Breadboard Works

      4:24
    • 34. The Resistors Color Code

      4:54
    • 35. Build Your First Circuit - 1 LED and 1 resistor

      7:39
    • 36. How GPIOs Work

      3:22
    • 37. Create a Python Program to Make an LED Blink

      10:18
    • 38. Activity 04 - Set the LED’s State From User Input

      1:45
    • 39. Activity 04 - Solution

      7:53
    • 40. Add a Push Button to Your Circuit

      8:58
    • 41. Detect When a Button is Pressed with Python

      4:26
    • 42. Activity 05: Power ON the LED When the Button is Pressed

      0:49
    • 43. Activity 05 - Solution

      8:22
    • 44. Add 2 More LEDs to Your Circuit

      6:04
    • 45. Activity 06 - Change the Powered on LED When Pressing the Button

      1:36
    • 46. Activity 06 - Solution

      13:12
    • 47. Activity 07 - Optimize Your Code with Lists and Functions

      2:32
    • 48. Activity 07 - Solution

      16:08
    • 49. Detect Movement with a PIR Sensor

      2:58
    • 50. Tune the PIR sensor

      4:54
    • 51. Add the PIR Sensor to Your Circuit

      8:00
    • 52. Read the PIR’s Data with Python

      6:31
    • 53. Activity 08 - Power on an LED when Motion is Detected - Your First Alarm System

      0:29
    • 54. Activity 08 - Solution

      3:44
    • 55. Use the Terminal on Your Raspberry Pi

      1:59
    • 56. Navigation and File System

      16:15
    • 57. Edit Files From the Terminal with Nano

      8:48
    • 58. Create, Remove, and Manipulate Files

      7:41
    • 59. Install & Update Software

      10:08
    • 60. A Few More Terminal Commands to Gain More Control Over Your Raspberry Pi

      3:39
    • 61. Install Python Modules

      4:08
    • 62. Work with Python from the Terminal

      10:14
    • 63. Read, Write, and Manipulate Files with Python

      11:18
    • 64. Activity 09 - Create a new Python Script From the Terminal

      2:26
    • 65. Activity 09 - Solution

      5:02
    • 66. Send an Email From Your Raspberry Pi

      1:04
    • 67. Create a new Gmail Account

      4:01
    • 68. Install a new Python Module: yagmail

      3:09
    • 69. Get the Password in Your Python Program

      7:56
    • 70. Send Your First Email From the Raspberry Pi

      4:55
    • 71. Add an Attachment to Your Email

      3:08
    • 72. Add Vision to Your Applications with the Raspberry Pi Camera V2 Module

      2:02
    • 73. Plug the Camera to Your Raspberry Pi

      3:10
    • 74. Enable the Camera

      1:30
    • 75. Take a Photo From the Terminal

      5:22
    • 76. Record a Video From the Terminal

      2:40
    • 77. Take a Photo with Python

      6:47
    • 78. Record a Video with Python

      3:18
    • 79. Activity 10 - Take a Series of Pictures

      1:54
    • 80. Activity 10 - Solution

      7:28
    • 81. Create a Web Application on Your Raspberry Pi with Flask and Python

      1:46
    • 82. Write Your First Web Server

      7:46
    • 83. Add a new URL and Connect Flask with GPIOs

      5:45
    • 84. Activity 11 - Choose Which LED to Power on From a Web Browser

      2:56
    • 85. Activity 11 - Solution

      7:33
    • 86. Final Course Project - Overview

      5:49
    • 87. Project - Step 1

      19:45
    • 88. Project - Step 2

      8:25
    • 89. Project - Step 3

      8:13
    • 90. Project - Step 4

      10:05
    • 91. Project - Step 5

      14:57
    • 92. Project - Step 6

      9:17
    • 93. Project - Step 7

      17:19
    • 94. Project Conclusion - Going Further

      1:25
    • 95. What You’ve Learned

      1:16
    • 96. What to do next

      2:16
12 students are watching this class
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

160

Students

--

Projects

About This Class

This complete hands-on, step by step class is targeting the latest version of Raspberry Pi, which is the Raspberry Pi 4. Note that everything also works perfectly for Raspberry Pi 2 and 3 versions.

You don’t need any knowledge in programming, electronics, or anything else. To get started, you just need a computer to work from, and a Raspberry Pi board.

At the end of the class you will have a strong foundation with your Raspberry Pi, and you will be able to start your own projects in no time.

→ Why this class?

You may be just getting started, or have already started to learn how to build projects with your Raspberry Pi. But knowing what to do first, and which path to follow can be quite hard and you may feel stuck.

The problem with most online resources for Raspberry Pi is that they focus on making you run existing programs to make you feel you’ve accomplished a lot, but in reality you’ve just copied/pasted some random code and didn’t even scratch the surface. The “why you should do that” is not involved. So, the next time you have to do something on your own, you feel stuck and too dependent on other people's code.

This class will focus on the “why” and make you become much more autonomous with your Raspberry Pi so you will be able to start your own projects without having to desperately search for code to copy/paste on the Internet. My personal goal is to make you understand enough to get started in a short period of time, and make you think as a problem solver, with engineer-level thinking skills.

→ And how will we do that you may ask?

Simple: 

HANDS-ON.

STEP BY STEP.

NO COPY AND PASTE. 

This class is not a class where you just download some code and run it. This is a class where you will truly understand how to write the code and work with the different Raspberry Pi functionalities. 

I will take the time to explain everything, step by step, even the basic things. I will write the code with you and explain why I write what I write. With the activities and final project you will have even more opportunities to practice on your own, and you will make progress without even noticing it.

→ What will you do/learn in this class?

Here’s an overview of the different topics we’ll cover:

  • Setup your Raspberry Pi and install Raspberry Pi OS without an external monitor and keyboard.
  • Get good Python3 programming basics.
  • Work with the Raspberry Pi’s GPIO panel.
  • Use a PIR sensor to detect movement from your Pi.
  • Discover how to use a Unix terminal and the most useful command line tools.
  • Send an email from your Raspberry Pi.
  • Take photos and videos using the Raspberry Pi camera V2.
  • Create a web server on your Raspberry Pi with the Flask framework.

The class is divided into 15 sections to make it easier to navigate and track progress. Each section is focused on one topic. For each topic we start with hands-on and explanations.

And along the way, through the different sections, you will have many opportunities to practice (11 activities) on the most important points.

After learning all those topics, you’ll work on a final project where you can practice more on everything you’ve seen in the class. This is also a good opportunity to mix different functionalities together, which is where you can really start to create much bigger and powerful applications.

So, don’t wait any longer and start your Raspberry Pi journey with this class!

The teaching method I use is now a proven method - not because I or someone arbitrarily said so, but because of the tons of positive feedback about successful learning results I’ve received over the years with thousands of students.

I don’t come from an academics background. I’m an engineer and all I’ve done is to try to solve real problems by being practical on what I need to do and to learn. I actually used Raspberry Pi to program an entire 6 axis robotic arm which is now on the market. This forced me to go to the point and focus on what’s really useful.

This experience and the lessons I’ve learned is what I want to share with you. Understanding the “why” and focusing on practicing on the key points, is, to me, one of the best ways to progress 10x faster.

My goal here is to give you more freedom when you start a project. To make you less dependent on what you may find (or not) on the Internet. To think more by yourself when building new projects.

See you in the class! :)

--------------

This class is for:

  • Students, Engineers, Researchers, Teachers, Developers, Hobbyists.
  • Anyone wanting to learn how to get started with Raspberry Pi and build amazing projects
  • Anyone wanting to really understand what they’re doing with Raspberry Pi, Python3, and the different components you can use with the board
  • Anyone who already knows Python or Unix and wants to dive into Raspberry Pi
  • People who want to start robotics projects, home automation, web servers, IoT projects, etc. with their Raspberry Pi
  • Raspberry Pi users who feel stuck in their projects and want to get more autonomous

This class is not for you if:

  • You’re not interested in understanding what you’re doing and prefer a quick copy/paste solution.
  • You’re already an advanced Raspberry Pi user.

Pre-requisites for this class:

  • A computer + a Raspberry Pi 4 (also works with Raspberry 2 and 3)
  • A list of hardware components (info in a lesson at the beginning of the class + in PDF "List of Materials"). You can still start and follow the class without those components.
  • NO external monitor or keyboard required.
  • NO programming, Unix, or hardware experience required.
  • A will to learn and to progress with the Raspberry Pi

Meet Your Teacher

Teacher Profile Image

Edouard Renard

Software Engineer and Entrepreneur

Teacher

Hi, I'm Edouard. I’m a software engineer and entrepreneur.

I’ve been working on programming robots for years. When I first started I really had a lot of trouble trying to properly learn. I found what works and what doesn’t work, what I needed, and what I didn’t need. So now I’m sharing that with you, so you can save the precious time you have.

Also I have co founded a robotics startup and programmed an entire robotic arm from scratch, with ROS, Raspberry Pi and Arduino. My view on software and robotics is very practical: I’m interested in how to best use a language/framework to build useful applications. 

And thus the approach I have in my online courses is really down to earth and practical.

I like to make complex stu... See full profile

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Your creative journey starts here.

  • Unlimited access to every class
  • Supportive online creative community
  • Learn offline with Skillshare’s app

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

phone

Transcripts

1. Introduction: Welcome to this course on Raspberry Pi for beginners. You want to create fun and useful projects with Raspberry Pi and starting from scratch? Or you are already using Raspberry Pi, but you feel stuck and you don't know what to do to progress in the right direction? You also want to learn by doing, and you think it's important to really understand what you do? Well, this course is for you. I am Edouard, a software engineer, entrepreneur, and robotics teacher. In the past, I have used Raspberry Pi to program an entire six axis robotic arm from scratch. Now, my focus is on teaching you the practical knowledge that I have and make complex stuff easy to understand. Starting with Raspberry Pi can be really hard. I know that. And today I am here to help you on this journey. In this complete step-by-step course, you will learn everything you need to get started through hands-on activities. At the end of the course, you will have a very strong foundation with Raspberry Pi. This foundation will make you confident enough, to create your own programs and start your own custom projects on a very broad range of topics. You don't need to have any experience in programming, or hardware engineering to start this course. It is structured in a way that makes it easy to follow for beginners and directly going to the point through a ton of practice. The course is focused on the Raspberry Pi 4, but also works perfectly for the Raspberry Pi 2 and the Raspberry Pi 3. Here is how we will progress together: First, I will show you one step at a time how to install and correctly configure the Raspberry Pi operating system without any external monitor or keyboard. Then you will start to work with Python 3 directly on your Raspberry Pi. I will teach you all of the necessary basics you need. After Python, you will learn how to control hardware components using the Raspberry Pi GPIOs. From this point, you will already have a very strong foundation which will help you in any future project you start. Then we will expand on several new topics. You will learn how to detect the movement using a PIR sensor. How to send an email from your Raspberry Pi, how to use the terminal to get access to even more functionalities. How to take photos and videos with the Raspberry Pi camera module, how to create a web server hosted on your Pi with Python and the Flask framework. Finally, you will use all this knowledge to create a complete project with Raspberry Pi and practice with all the different topics mixed together. And that's not all. All along the course, I will give you the best practices you can implement right from the start and explain to you why you need to do what you're doing. The goal here is to make you become more autonomous in your projects and give you engineer level thinking skills to solve any problem. Also, when we program, I will write and explain all the code we use. No copy and paste. Only practice through hands-on activities. Alright, so if you want to start learning Raspberry Pi in a practical and efficient way, wait no more, and let's get started. 2. What is Raspberry Pi and What Can You Do With it?: What is the Raspberry Pi and what can you do with it? The Raspberry Pi is a very small computer, the size of a credit card. But it is quite powerful and it can run a lot of applications. So what can you do with this ball? And this is where the Raspberry Pi truly shines. Here are some examples of projects you can easily make with a Raspberry Pi, began to automate your home. Make your personal devices smarter with IoT or Internet of Things. You can also build a retro gaming console. Create a security, are an alarm system, host server for a web or mobile application. You can even run a Minecraft server on your Raspberry Pi program. Robots, such as robotic arms, drones, hex Apple's mobile robots, et cetera, create a smart mirror. You can also install different operating systems. For example, raspberry by OS, you going to Windows, IoT and much, much more, or simply use the Raspberry Pi as your own portable computer. And of course, this list is far from being exhaustive. You can find much more projects online and you can also get inspired to create your own capstone projects. One great thing about Raspberry Pi is the community. So what does the community bring to you? Well, for example, you can see what other people do with their Raspberry Pi. You can ask questions, get some help for more advanced to users. You can also collaborate with other users on similar projects and progress together. Raspberry Pi is created by the Raspberry Pi Foundation. The goal of the foundation is to make computers and digital making available for everyone across the world. For less than $40, you can get the Raspberry Pi Board and the complete setup with computer screen, keyboard and mouse would cost you less than a $100, which is a very good first step when you compare this price with the price of any other computer or laptop available on the market. The first raspberry pie board was released in 2012. Then the foundation has continued to develop new iterations to make the board more powerful and more functionalities, make it easier to use. Developed the community. In 2015, the Raspberry Pi to was released with much more computation power than the first one. Then the Raspberry PI three came in 2016 with again more computation power. And this time the Wi-Fi feature was directly integrated in the board. So you don't have to use a Wi-Fi USB dongle anymore. Today. The latest version is the Raspberry Pi for released in 2019. This new version is really great, much better performance than the version three. A few changes in the external collectors to make it compatible with modern applications and an increased amount of RAM. In fact, we've raspberry by four. You can even choose the amount of RAM you want. The Raspberry PI 23 had one gigabyte of RAM, which was already good. Now, for the Raspberry PI four, you can choose between two gigabytes, four gigabytes, and even eight gigabytes of RAM, which is huge for that board. At the beginning, the Raspberry Pi four was also the labelled with one gigabyte of RAM, but not anymore. Now, what can you find on the ball? Here? You have the CPU run Wi-Fi and Bluetooth chips, and all of the components required to make the Raspberry Pi work. And let's focus on the connectors. You have one Ethernet port with gigabyte ethernet. For USB ports, including two USB, three ports in blue, one USB-C port to power on the board, to micro HDMI ports. We've 4K video support for two external displays. A jack, audio output ports. One display, both for the Raspberry Pi touchscreen, one port for the Raspberry Pi camera module, a MicroSD slot on the back of the board. And actually you will install the operating system directly on a macro. And finally, you have a 40 pins are GPIO header that we will use a lot dreamy scopes to control different hardware components. With Python programming, GPIO means General Purpose Input, Output. This header is the same for the Raspberry Pi 2B, 3B, and the Raspberry Pi four. All right, and now you should have a slightly better idea of what is the Raspberry Pi. It's built bows and the applications you can do with it. 3. List of Materials for this Course - and Recommendations: Here is the list of material you will need to complete 100% of this course. You can also download a PDF containing all the information as an additional resource. First, of course, you will need a Raspberry Pi bold. And now, which raspberry pie board should you use for this course? I have good news for you. Even if discourse is targeted to Raspberry Pi for, well, in fact, you can also use the Raspberry Pi three and the Raspberry Pi two versions. Everything will be the same. Also, no need to worry about the additional letters in the Raspberry Pi version, such as b, b plus, etcetera, everything will work. You can install the Raspberry Pi operating system on all those bolts and the GPIO header is identical. So if you have an old raspberry pie board, don't worry, discuss will work for you as well. Only for the Raspberry Pi to, you will need a USB Wi-Fi dongle because the WiFi was not already integrated on the board at that time. If you get the Raspberry Pi for, you will be able to choose different configurations for the RAM. Two gigabytes, four gigabytes are eight megabyte. There was a one gigabyte version previously, but they are not selling it anymore. If you have this one, it's perfectly fine. So when choosing the RAM, of course, the more, the better, but it also becomes more expensive. I personally use the two gigabyte version and it works perfectly fine for most of the projects. I would recommend buying two of four gigabyte version. Unless you plan on executing high-demand programs, eight gigabyte is something you probably don't need. Then you need a power supply for your pi. If you buy your Raspberry Pi with a kid, you should already have one included. If not, then you will need to get one. Note that a good smart phone charger is totally fine and it's what I use without any problem. The only thing you should avoid to do is to power your Raspberry Pi directly from your computer with a USB cable. This would be the Raspberry Pi, right? But the current won't be enough for the board to run well. And you can expect all sorts of arrows and programs when running your bold. So either use a power supply specifically designed for Raspberry Pi, use a phone charger with at least five volt and 2m. If you use the Raspberry Pi four, aim for three MP if possible. And 2.5. MP for the previous versions of the boat. The third and final part you need if you just want to run your Raspberry Pi solo is a micro SD card. When choosing which microSD card you want to use for your Raspberry Pi, there are two important factors, the class of the SD card and storage capacity. First, make sure you get a card with class ten and not lower. The class ten symbol should look like this. A ten inside a circle. If you have a card with less than class, then, then it will be too slow for your Pi. Some of the new SD cards are even more powerful and faster. For example, this extreme prom micro SD card. And here you can see we have a number three inside a U shape. I won't go into details about that, but if you see that symbol, that's also a very good option. Now about the storage capacity, I recommend you get at least eight gigabytes of storage. So you can install the operating system and have some room for extra files or program. Eight gigabyte is really the minimum you should aim for. If possible, I suggest you go for 16 kilobytes and why not 32 gigabytes, if you know, you will have to store big files on your Raspberry Pi. Note that any god that is 64 gigabyte or more will need some extra formatting so they can be used, but it's not a huge problem. And for this course, I will stick to 81632 gigabyte SD card, which is any way more than enough for what we will need to do with the Raspberry Pi, the power supply, and the micro SD card. You can already installed the Raspberry Pi operating system, learn Python, and follow most of the course. Now, if you want to be able to create the hardware secrets and do the activities related to GPIOs. You will also need the following breadboard set of wires that can connect to the breadboard and the Raspberry Pi GPIOs. You will need male to female wires, male to male wires, and female to female wires. We need a set of resistors. We will use one kilo ohm, ten kilo ohm resistors in this course. But if you don't have those, you can also get resistors as low as 330 ohm and as high as 20 kilo ohm. I will give more details during the course. Usually the best thing you can do with resistors is just to get a complete set with many different values, like what you see on the screen. It's really quite cheap. Then you would need three LEDs with the color you want. It really doesn't matter. And finally, a push button. We've four legs like this one. For all those components. Breadboard, wires, resistors, LEDs and push buttons. Usually you can easily find kids that contain everything. Just search for breadboard kids. And you will find some. Also, if you already worked with Arduino previously and have an Arduino kit, you probably already have all of those components. So with those components, you can do almost all sections in this course. Now for two sections at the end and the final project, you will also need a PIR sensor, which is a passive infrared sensor. Here is the reference of the sensor, HCI 501. I suggest you buy a set of two or three minimum. Usually it's almost the same price, whether you buy one or u by three, it will be especially useful to have more than one if you buy the cheap ones where there is a higher chance of getting a sensor not working correctly. And the last hardware component is the Raspberry Pi camera module version. To note that you have two models for the camera. The standard one with a green board and NWA version with a black board. The black version is perfect for walking in the dark, but won't produce good-looking photos in daylight compared to the standard green version. So for this course, I will be using the standard wall. And this is the one I recommend if you're just getting started and you don't have a specific project which requires working in the dark. Either way, all of the instructions will work for both cameras. Well, that's it for the list of parts for this course. If you already have a Raspberry Pi bald, you can start the course right now while waiting for the other bats. 4. How to get the most out of this course: Here are a few points that will help you get the most out of this course. First, follow the clues in the order. Don't skip any lesson. Price pose between each step and make sure you can successfully do the step before you continue. If you already know Python, you may skip the basic Python part, but I still recommend you at least watch it. As a reminder, when I write code and do experiments, first watch the listen, and then write the code and do the experiments by yourself. Watching plus doing is much more efficient than just watching. And finally, I will give you many activities and challenges during the schools, make sure you take enough time to solve the challenges by yourself before watching this solution. This is the only way you will truly make great progress. And one additional quick world. Caution, when you want to manipulate your Raspberry Pi, whether for removing the micro SD card or changing a hardware component, always first shut down the Raspberry Pi from the software. Wait at least 20 seconds and remove the power cable, and then you can safely manipulate the board. Alright, enough talking, no legs. Installed the raspberry by operating system. 5. Install Raspberry Pi OS Without any External Monitor or Keyboard: In this section, you are going to install everything you need so you can then use your Raspberry Pi. Again, note that you don't need acne, external monitor or keyboard. We will manage to get to work on the Raspberry Pi desktop directly from the computer you are using right now. I will guide you through every step. There are quite a few ones, but don't be discouraged. You see that each step individually is really not that complicated. Make sure you can finish one step before you start with the next one. Once you've done the installation process, a few times, you will see that it can be done very quickly in less than 30 minutes, you can have a complete new Raspberry Pi image installed and configured on your pie. So for the first time, make sure you watch every video from beginning to end and follow all of the instructions by the letter. At the end, it will all make sense to you and you can come back to any lesson for a specific part of the setup. 6. [New] Flash the Raspberry Pi OS with SSH and Wi-Fi Setup, on your micro SD card: The very first step before using the pie is to flash an operating system on the SD card, you have to do some configuration. In this lesson, I will show you how you can easily install the Raspberry Pi operating system on your micro SD card, but also how to set up the WiFi and an SSH connection so we can get access to the buy for further configuration. Note that this video is an upgraded version of the installation video. You can still find the old videos in this section, okay, In case you just want to set up SSH and Wi-Fi separately. So to install Raspberry Pi OS, the first thing you do is you go on Raspberry Pi.org, you have the URL and then you can click on software, okay? And you're gonna get this page are something that is maybe similar, okay? And you're going to have here install Reisberg by always using Raspberry Pi imager. We're going to download the Raspberry Pi imager, which is a software that is going to do everything for us. So that's gonna make our life simpler. So you can click here on download for Windows. If you're on Windows currently on MacOS, are you going to, I'm going to download for Windows? And one thing that is important is that this video is only going to work for imager that is at least 1.6, okay? So if you have anything below 1.6, okay, then you have to download a new one or you have to check the other video. Okay, so I'm going to save the file. And once it's done, I'm going to install the Raspberry Pi imager. Okay, so you click on yes, if you have a pop-up and then click on Install. Okay, Finish. And if you want to find it easily, well, you just type Raspberry Pi imager on your bar here at the bottom and just, just find the application here, or maybe it's on your desktop. So once you're here, you're going to close that. Once you're here, you're going to first choose an operating system that you're going to flush in the SDK. And you're going to choose the first one, okay, Raspberry Pi or ice here. So just to the first one you can see you have many different ones. For example, you can choose, well, you can see many different operating system, but we're going to go with the main one, Raspberry Pi OS, which was previously named Raspbian. Okay, So if you are looking into installing Raspbian, well that's not a new name, Raspberry Pi voice. And then what you are going to do. So I'm going to put I'm going to physically put my SD card in the computer. Okay. Maybe that's going to open something like this. Well, you don't care about that. Okay. You just close the windows. You can see I already have stuff on that. I'm going to just close and I'm not being too format anything for now. Again, I'm going to click on Choose storage and choose the SD card here. And you have the SD card. And one more thing I'm going to do now, and this is the configuration that you can't see on the screen. I'm going to need to use a shortcut Control Shift and x. Okay, So you do Control Shift and x and you see we have a new window here. We've more configuration. And so what I'm going to do is I'm going to click on enable SSH. And we're going to use, use password authentication with the password for the user, which is raspberry. So you can just type raspberry here, okay, to set the password for the user data, the default password. And then you can go down and you are going to click on Configure Wi-Fi. And these may be, is going to show you the current Wi-Fi. You're connected in some mixture that, well, here I'm on Windows, you can see I have, so I have named my network, your WiFi network, okay, for simplicity for its goals. And the password is for me, your password, okay, so we just replace that. And so those values have to be the same ones you are using here for your computer, okay? So that then you can access the Raspberry Pi from your computer because you are going to be in the same network. Okay? And well, that's the case. We can click on Save and then you can click on right. But before you do that, make sure the SD card doesn't contain anything that you wanted to keep. Because once you click on right, that's going to erase everything. So you click on right. Okay. Everything will be arranged. Are you sure? Yes. And then it's going to download the operating system. So you can click on Console if you need to. And it's going to download the Raspberry Pi operating system if it's already downloaded before it's going to keep it and retrieve it from the cache. And then he's going to write it inside the SD card and then you can wait until it's done. And that's going to take a few minutes. Okay? And once it is done well, if you have any of that, you can just click on, Okay, cancel, okay. Just don't click on Format anything. And then you can see successfully written on Azekah continue. And then what you can do is remove the SD card from your computer. And well, that's it. Now, you will be able to boot up your Raspberry Pi with the Raspberry Pi operating system. 7. [Old 1/2] Flash the Raspberry Pi OS on your micro SD card: The very first step before using the pie is to flash an operating system on the SD card you have and to do some configuration. In this lesson, I will show you how you can easily install the Raspberry Pi operating system on your micro SD card. So first of all, you are going to go to the raspberry pi.org websites. So you have the URL here. And on this website you are going to go to the downloads page. In this download page you can see all of the different operating systems for Raspberry Pi. So the main one is raspberry by Glace, which was also called Raspbian before. Okay, So issue new Raspbian, know it is raspberry by operating system. And you also have here a bunch of variant for us. But for this course we are going to use the main raspberry by ice and to install it is very easy. We are going first to install the raspberry by image or software. So you choose the version which corresponds to your operating system. So right now I'm using Windows. I'm going to download the raspberry by imager for Windows. Saved a fire, and now you can click to install the software. Okay, now that the Raspberry Pi 3 major is installed, simply studied. And here it is very, very simple. First you are going to choose an operating system here. So click on Choose OS, and you're going to click on the very top one Raspberry Pi OS. So you click on raspberry by voice, and that will download the operating system and flush it into the SDK. And now for the essay God you simply, it is not the time to, but the SD council to micro SD card directly on your computer, which I'm doing right now. You may also see a new Explorer window opening just when you plug the Azekah Lucas. So you can just close it. And now you're going to click on Choose SD card. And you should see the SD card here. So for the schools, I'm using a 16 gigabytes as the guard. So you have chosen the Raspberry Pi OS as an operating system and your SD card. Now you are going to click on right? And before you do that, make sure that you're as the god doesn't contain some data that you want to keep. Because everything on your SD card will be arranged. So you can go, okay. Other message saying it will be everything will be erased and then you click on Yes, and you can wait. So this will download the Raspberry Pi co-branding system. If you are flushing another god, the Raspberry Pi OS will already be cached so you don't need to download it. Again, it's automatically done for you. And then it will write, as you can see here in Twitter right on the God. This can take actually a quite few minutes. So you may have to wait between 10 and 20 minutes. And when you see that misbehavior, it means that the operating system has been successfully written to your SD card. 8. [Old 2/2] Setup Wi-Fi and SSH Directly on the micro SD card: Now that your operating system is flashed on your micro SD card, what you could do is to directly put the child into the Raspberry Pi, plug a monitor with HDMI cable, plug the keyboard and then power on the PI and follow the installation instructions on the screen. But as previously saved, we are not going to use any external monitor occupied. So what we'll need to do is to configure the network before we would the Raspberry Pi for the first time. So then when we put the Raspberry Pi, automatically connect to the Wi-Fi and we will be able to use SSH to get access to it to continue the configuration, okay? If you don't know what is SSH at this point, it's really not a problem. We're going to go through that together later. So now you can open a file explorer and you will see that next to your main partitions, you may have several here. You have a new boot device here. So if you don't see that, maybe just after flushing the OS on the ethnical, you can just remove the SD card. Okay, like I'm doing now and put it back again in the computer. And it should appear after a few seconds here. Okay? So you're going to go inside that folder here and you can see here we have a bunch of different files. Don't need to worry about all of them. What we're going to do is simply add a new file to configure the Wi-Fi first. So you can do new new text document. And you are going to name it WPA supplicant. And you are going to remove the tick x t extension and instead use cough. You press Enter and they may say that you may have a warning, but just click yes. And you have a new file, make sure that the file has the exact same name as here. So now you can open that file, okay, with any text editor. And you are going to put some configuration that you just need actually to copy and paste. I'm going to zoom in here. So you can actually download this text file, okay, with this lecture, with the additional resources for this course. And just copy and paste that into your W PAs supplicant.com. So here you have one line with country US. You can change with the code name for your country if you want to, but it's not mandatory. Don't need to change that, no need to change that. And here it is where you will actually put the network. So the name of the network and the password to connect to the network. So how finite we'll just check which network you are connected to. Okay? So here I have named my network, your WiFi network, okay, just to make it easier for this course. So I'm going to put the same name here, so you should use the same network that your computer here is going to lead to. So your WiFi network, you put your name here, and of course you will put your password here. And for me it's just your password. I have put that as my password, but for you it will be different. So now you can save the file with Control S and you can close it. Really pay attention that you don't make a mistake in the naming, should just make a typo with von later. They mean what be able to connect. Okay, So that file here, we'll make the Raspberry Pi automatically connect to your WiFi when you bought it. And now just one more thing to do is we're going to create a new, you can create just a new empty text document and you're going to name it as H and remove any extension, so just SSH and nothing else. So you press Enter and again you press yes, if you have a warning. So now you have an SSH fire. Okay, and that's it for this step of the configuration. Now while you can do is simply you can remove the SD card. So maybe you can simply right-click and click on eject. Here. It is a safe way to do that. And you can physically ejects your SD card from your computer. 9. Boot your Raspberry Pi For the First Time and Find its IP address: We have the configuration from the last step on boot, your Raspberry Pi should automatically try to connect to the Wi-Fi network you've provided. So what you can do now is first, make sure that your Raspberry Pi is powered off. Okay, this is very important. Now, you can put the SD card in the SD card slot of the pie, okay, make sure it is correctly inside the slot, like you can see here on the screen. And then, and only then you can power on your Raspberry Pi. So what you should see is first, you will have the red LED which should be pulled on. And then you should also seen just next to it the green LED blinking quite randomly. And if it's blinking randomly, it means simply that the Raspberry Pi is booting. And so you can wait a little bit and after a few seconds, maybe one minute top. The raspberry pi should be connected to your WiFi network. And now that is where we need to actually find the IP address of nice Raspberry Pi under network so we can get access to it. So to find the IP address, we are going to use a tool, okay, this is software you can download. Here I'm using the angry IP Scanner, okay, so these tool is quite good to find all the IP addresses and Holst inside a network. So I've chosen this one because simply it's available for Windows, Mac, or Linux, so anyone can use it with this course. You may have already used some specific software. For example, for Windows, you have advanced IP Scanner, which is as good as angry IP Scanner even better. So if you already know other IP Scanner software's for your operating system, feel free to use them. And if you are going to use angry IP Scanner as I'm doing here, you can simply here, well, you can click on that and download and install the software just like you would install any software. And you will also have to install Java here because the software uses Java. So you can click on here and just download and install the latest version here base. So you have to install Java plus this software. And if you are using Mac OS, you have the instructions here. And Linux you have the instructions here. And now that the software is installed Well, you simply have to start it. And you may have another pop up asking you to accept some stuff related to the network. So you have to press yes. Okay. So otherwise it will not work. So you have this software study them before we even do anything, please go back to check your WiFi network here and make sure that your laptop, so this laptop over there, is connected to the same Wi-Fi network as the Raspberry Pi. So as the configuration you have setup inside the SD card of the Raspberry Pi, okay? It's not in the same network. You will never be able to find the Raspberry Pi form this commutator. So this is actually a very important first step you need to check here. So once this is done, well, go back to angry IP Scanner. And before we start we have little bit of configuration here. So as you can see, we have the hostname. The hostname is the, actually the host name of this major hints. So that is my hostname, which will be different for you. And you are going to click on that IP button with an arrow here. So you click on that and you will see different stuff here. So you may have just one or two or more like, like me. And you're going to select the one with Wi-Fi here. So this is actually, this is the IP address of that computer in the Wi-Fi network. I have a few other ones here, for example, with virtual machines. But if I chose them, would not be able to connect to the Raspberry Pi because it's not the same network. So I have to choose the wifi ip address. And as you can see, this will automatically update the IP range here. Okay? And what you're going to do is actually so you have four different numbers from IP address. You're going to change the last one here for the beginning of the range to let c one and the last one here to 255. So when you will scan, this will scan between 1255 in that network here. And your Raspberry Pi is somewhere between those two numbers. So when you scan, you will see the IP address, the host name, and port. But one thing actually you can do is click on that. And we're going to add the Mac vendor here. I will show you why later. So you click on MAG vendor, you put add here, so it should be on the left and you click on ok. So it shouldn't be here. That column should media. And not just press stat. Okay, and once this is done, you will have that kind of window message. So for me it took 30 seconds, it can take moral is time. And so you can click on close and you have, as you can see, 1-2-3, 4-5-6, et cetera, until 255. What you can do is simply maybe click on pink and sought by pings. So you have all of the different IP address which are actually corresponding to real machines. Okay? So what is blue? There is something when it's red, it means that nothing has been detected for this IP address. So we can see that actually that is the first one here. This is the laptop I'm using. Here. I can see here the IP address finishing with 56 for me. So of course, this can be completely different for you. Tell me completely different number here. I can see a Mac Vendome here, Raspberry Pi training. So it means I have found my Raspberry Pi on the network. Okay, and the reason I have asked you to add the mag vendor here is because, well, for some reason, it depends. Sometimes you may not be able to see the host name, which would be raspberry by. So if you use, for example, the advanced IP Scanner software on Windows, you will see the hostname, but not with angry IP Scanner. I mean, at least not for my specific situation. So here you can clearly see that this is the Raspberry Pi you're looking for. If you don't have any information here, you can still guess by looking at the blue dots here because you will only have a few. Okay, so this is my computer. The first one would not be raspberry Pi, it will not finish with a one. So here, even if I didn't have that, I could guess that this would be the Raspberry Pi IP address. So once you have that, write down the IP address, and we are going to use that just in the next lesson. 10. Connect to Your Pi using SSH: Great. You've successfully installed Raspberry Pi operating system, configured the Wi-Fi and you know, the IP address of the Raspberry Pi in the network. What we can do now is to use SSH to take control over the Raspberry Pi and really get access to it. This, we provide you with command line access in a terminal, which we are going to use in the next, listen to install VNC and get access to the Raspberry Pi desktop. Don't worry too much about understanding common lanes and how a terminal works for now. We will come back to it in a future section of discourse. For now, this is just a required step of the configuration. So please follow every instruction one by one and make sure you write the exact same thing as 9x right here. So first of all, I'm going to open a file explorer here and go to my main partition here. Go to users to select your user name, okay? And here you may see a dot SSH folder here. If you don't see it when you have nothing to do and you can just skip the next 20 seconds or so. If you have an SSH folder, you're going to go inside and you may have known hosts, fine. What you can do is if you don't know SSH, ah, stuff, you can just simply remove that file for no. It may prevent some errors when you try to connect to your Raspberry Pi. Okay? And now what you can do is to open a terminal, okay? So Windows key and then Cmd or command, and click on that and this will open a terminal on windows. So if you are using Linux, iOS, you know how to use a terminal. And if you're using Mac, you can also open a new terminal. Okay? And if you're using Windows ten, Windows ten with a quite recently updated version, you can simply connect to the Raspberry Pi with SSH terminal. So you can easily check if you have SSH available for you on Windows ten, k simply you can type SSH on the terminal and press enter. Okay, here I am. Message, use age SSH. So if you have that, it means you have SSH and you don't need to do anything else. If you don't have that and if instead you have a message like SSH command not found, then it means you won't be able to use SSH in the Windows Terminal. So in that case, in that very specific case on Windows, you would need to install another software to use SSH. And you can, for example, use buddy login, go on putty.org and you can simply download it, install the software, and then studied. So pulley is an SSH client. You can use it the same way we are going to use this common line here. This will just make you use a GUI tool. So you will have to fill up the IP address, the username, and the password, as we are going to do here. So coming back to the terminal, which you can do to get access to your Raspberry Pi is to type SSH and then space. And then you need to provide the username. So what is the username for Raspberry Pi, for your Raspberry Pi, Well, the default username that is already here when you flush the OS into the card, is named simply by, okay? So there is no way for you to discover that. It's simply the default one that I'm giving it to you. Here. You can also find it on the Raspberry Pi website. So we are going to be connected as the user named by. Then you can put at the IP address that you found here with your IP Scanner software. So for me it would be a hundred ninety two hundred sixty eight that 4356. So of course that will be different for you. Okay? So just use the IP address you found there. And then you can simply press Enter, okay, for the very first connection, you will have that message. Are you sure you want to continue connecting? Because actually the host here your machine doesn't know, has not been connected to your Raspberry Pi before. So you can just press yes. Ok. And now it's asking you for the password. Okay, so we have the user by and we need to give the password. So what is the password? Well, do password is simply raspberry. Okay. Like that. No uppercase, no space, no nothing. Just Raspberry like that. So you can go ahead and type raspberry. You will not see anything. Okay? As you can see when I typed, you will not see anything written on the screen. And then you press Enter. And if it works, if you've provided the correct password, then you're in. You can see here you have the Pi user and then the hostname is Raspberry Pi. And you are connected to the Raspberry Pi for the first time, Great. And know that you're in. Let's go ahead and go to the next lessons so we can have access to the Raspberry Pi desktop. 11. Setup VNC to Get a Remote Access to your Raspberry Pi OS Desktop: Let's now install and configure VNC. Vnc will simply allow you to use the Raspberry Pi desktop from your own computer. This is great, so you don't need to only use the terminal with command lines and you also don't need to have a monitor plugged to your Raspberry Pi. And even if you have a monitor, you will see that it's sometimes more convenient to work without it. So the reason why we set up SSH just before is simply because we need to access the Raspberry Pi through SSH so we can actually set up VNC. So that's what we're going to do here. So if SSH is not working for you, please go back to the previous lesson. And now I am going to connect to the Raspberry Pi via SSH. So SSH. And then you put the username, which is Pi here AT and the IP address. So of course, this will be defined for you. Okay? Center under password, raspberry. Okay. Don't worry about the warning message here about password. We are just going to change the password later. So here to enable VNC and make it work correctly, there are a few different steps that we need to do in the order, so please follow along. First, you are going to type. So here you are in a terminal inside the Raspberry Pi. You're going to type sudo space raspy dash config. And if you see that, for example, if I press tab here, I can have the auto-completion to make sure it is the right command. Sudo will make you run the command as an administrator on the machine, which is required here. And raspy configures interests so you can get access to a configuration. So you press Enter and it will bring you to that menu here so you can navigate using the arrows, okay, from your keyboard is very simple, and then just press Enter to choose whatever you want. And the third thing we are going to do is go to interface options. Okay, press Enter and then go to VNC. Press Enter again and modulate the VNC server to be enabled. You're gonna select yes, press Enter. And you can see the VNC server is enabled. So I'm going to use the right arrow key to go to Select and then finish, and then press Enter on Finish. I am going to reboot the Raspberry Pi with the command sudo root. So you do sudo robots Enter and you can see now, so the Raspberry Pi is rebooting and we are back to where we were before. So here I'm back on Windows, okay. I lost the connection to the Raspberry Pi. You could, because of course it's rebooting. So now you have to wait a few seconds until the Raspberry Pi has boots again and is connected to the Wi-Fi network. Okay, I'm going to use the same command as before and wait a bit and then press Enter. And you can see when you have the password, it means that the Raspberry Pi has correctly route. So you just put the password raspberry wants more and you're back to stage, okay, on the Raspberry Pi with the user. And now you're going to go back to raspy config. We've pseudo raspy complete. And so here the VNC server is enabled, but that's not going to just work like that. So you need to go here we are in one, so I'm going to press Enter and go to boot, auto logging. And I'm going to choose so by default that may be one of those, okay, console, but you're going to choose desktop or desktop auto login, okay? So it means that it's going to boot on the desktop. And if you use auto logging is going to put on a desktop and it's not going to ask you for the password to boot it. So I'm going to use that because it's just simpler. I press Enter. Okay. And then what I can do is I can just go to finish again. Would you like to reboot now? Okay, They ask you that because you have changed an option that needs a root. So do you like to robot now? Yes, you press yes and he's going to reboot. Again. Assange going to make the steps one by one gay and reboot every time so that you get see each step one by one. So now you have to wait a bit until the Raspberry Pi has I put the password raspberry again. Okay, and I'm going back to raspy config. And the last step, we are going to go on display options, okay? And resolution, okay? And you're gonna choose a different screen resolution than the default work, okay? Because for some reasons, if you have the default resolution, the VNC server may not work. So you have to choose a different resolution here and in which one to choose. Well, basically choose the one that corresponds to your current screen here. So on my laptop here, I have a full HD resolution on the screen. So I'm going to choose. Full HD resolution. So you press Enter on the resolution you want. Okay. The resolution, we said that a lot. Okay. And then go back to finish. Would you like to Robert no. And yes. And you reboot one more time. Okay. So those are the three steps we need to do. So we can enable VNC and make it work. So now we have set up the NC on the Raspberry Pi. So this is the server site. What we need to do now is to get the client. So here I'm using Windows, I need to get a client so I can actually connect to the Raspberry Pi and get access to the desktop. And to do that, we are going to actually installed the Real VNC, VNC viewer. So you can go to that. You are here, Real VNC.com. You can simply, so Di Vinci do your Real VNC and it's basically the first link. And as you can see, this is multiplatform, so you can choose whatever OS you're using right now for Windows and Mac OS and Linux. As you can see, there is a Raspberry Pi here, but don't mix things up, okay? If you choose these indices, the client to connect to the Raspberry bytes. So if you choose this, basically it means that you are controlling a raspberry buy from another Raspberry Pi, okay? Here we are controlling the Raspberry Pi from windows here because my laptop is running Windows at the moment. So I'm going to choose the Windows Client and simply download it. Okay, David, and when it is done, you can donald it before. So you can just run it and go through the installation setup. And once it is installed, you simply have to launch the application, okay, and you will get that you hear. So what are we going to do now? First, make sure that your Raspberry Pi has been removed. So it is powered on, it is running. And also makes sure that, yeah, I'm going back to my network configuration. You should have the correct configuration because you could just previously connect to SSH, but make sure you always have your computer and your Raspberry Pi on the same network. Otherwise you won't be able to connected to your Raspberry buy from your laptop. So now I'm going to go here to find and new connection where you can just press Control N issue. And here I'm going to put the IP address path near Rosemary Beck. Okay? So really make sure that you know that somewhere so you don't forget it. And I'm giving names to just saw, we can recognize the connection here, just Raspberry Pi. You can put whatever name you want here, okay? And let's click on, Okay. And now I'm going to double-click on that. Okay, You may have a warning like that and let's don't worry about that. Let's become continues. You don't have the wiring at spine 2, and now you have to give the username and password. So the username is by and the password is raspberry. Okay, Just like we did for SSH, okay. You can choose to remember the password or not. I'm not going to do that now because we are going to change the bus will later. Okay. You can now have access to your Raspberry Pi desktop without any external monitor. Great, isn't it? Now, stay with me for the last configuration steps which I will cover in the next lesson. 12. Finish the Startup Configuration - Last Steps: In this lesson, I'm going to show you how to configure the Raspberry PI on the first boat with the desktop. So either you have followed the previous instructions by connecting the Raspberry Pi to a Wi-Fi network, setting up SSH and setting up the NC. Okay. Are you may have just plugged a monitor to the Raspberry Pi women HDMI cable. In that case, you will also arrived to that screen on your new monitor. So instructions are the same for both configurations. So first, okay, you may have that warning. Ssh is enabled in the default password for the user changed. So you will only get that. Of course, if you have previously said SSH, like we did, just click on OK, doesn't matter. And you have the welcome screen to set everything up. So I'm just going to get you through the different steps here. Click on next. So you choose your country in Guangzhou. For me is France. Ok. Too long wage. I'm going to use the English language so you can just sit your keyboard. Anything that is related to your country. Okay, next. Okay, and here they will ask you to enter a new password. So we could have done that before, but because we have this option to do that here, I didn't do it before, so we can just change the password now. So simply, simply to the password that you walked, and that will become the new password for the user. Okay, so your user is still named by, okay. But then the password will not be raspberry anymore. The post-World would be the password that you sit here, okay, so make sure that you remember the password after you sell it here. Then you click on Next. If you, okay, if the screen shows a black border around desktop, you can click on that. Or me, in my situation, I don't have black borders, so I'm just going to click on Next. And then they will search for wireless network. So if it is the first time you boot your Raspberry Pi with an external monitor. Of course he or you have to choose which network you want to connect to and setup the provide the password. Here. I'm not going to do that because I'm already connected to that network because that's what we previously did in another step. So I'm going to click on skip. What you can become next if you're not connected and could date software, you can click next. Okay, it will check for updates. So after fetching the new relabeled update, it will download the new packages. So can install packages may take some time here depending on your internet connection speed. And after all, the updates have been donated, Dowd Raspberry Pi, we install those updates. So here again, you have to wait a few minutes. Okay? And finally you will get this message system is up to date, so you click on OK. And now the setup is complete so you can actually press restart. And as you can see when they press restart here because I'm using VNC, I get a message attempting to reconnect to VNC server, okay, because of course the Raspberry Pi know is shutting down. So the VNC client can't connect to the VNC server. So what you can do here, you just need to wait. The Raspberry Pi is disconnected and the client, the VNC client, will continue to try to connect to the Raspberry Pi. And when the Raspberry Pi you will boot again. It will enable the VNC server and the client will be able to connect. And here, as you can see, we have the message. Either the username was not recognized, all the password was incorrect. And you get this the first time because the password actually you have changed. The password. Password is not raspberry anymore. The password is the new buzzword that you have set. So you click on OK and you can double-click on the VNC client again. And you can put your new password. Okay? And there you can actually click on remember, password. Okay? And it will connect again as the user. Okay? So now if I click here, I close it, I can connect again and it will not ask for the password. Great, and just one or two more things I want to show you. First, you can go here and click. You can just browse here and chip what's actually what's inside, what other different programs. And if you go to hear preferences and Raspberry Pi configuration, and if you go to interfaces, that is basically the same thing that we did with the raspy convenient, OK, when we entered the Raspberry Pi with SSH, and that is where, for example, you can enable SSH, okay? So here we have already enabled it. That is where you can enable VNC. Here, though, if you are using an external monitor, it would be like this. So you just have to click on Enable, okay, and then restart. And then you can use VNC. And we're going to actually see more of the font interfaces here during this course, but I'm going to leave it like that for now. And one thing that you makes balance is, okay, if I try to put full screen, as you can see, it doesn't really work. It's not good. As you can see that the resolution is not really a BIG correctly, OK. It's either too big or not fitting the screen. So to fix that, simply follow what I'm doing here. You can click here to open a terminal, okay, and got me look familiar to you before if you've used SSH like in the previous steps. When we used SSH, we were opening a new terminal inside the Raspberry Pi. And here we are simply doing the same thing, but instead of connecting to the Raspberry Pi from Windows or whatever, we are simply opening a new terminal directly inside the Raspberry Pi, which is the same thing. So you can use the command sudo. And then nano. Nano, which is a text editor, and then slash, slash config dot t. Ok, so you can just type this exact command and this will open the file name configured x t, which is located in the slush mood. So slashes the root of the file system. So this is will fight is located. And what you can do is use the rows from the kibble to navigating the final. So you can use the down arrow to go down until the end of the file. At the end of the file you will see that like Nietzsche overlay the S4, etc. etc.. What you can do is add a hashtag before. So this will simply comment the line. Okay? And you can press Control S, okay, you will see that message here. Control A's will save the file and then control x will exit the file. So now that we have changed, dad, as you can see, it's in boot directory, so you can guess that it will apply on boot. So you can reboot your Raspberry Pi's. So you have two choices. You can do sudo reboot like we did before with SSH. And you can also go here and click on logout and shouldn't, just like you would shut down any computer. Ok, so if you want to actually reboot the Raspberry Pi, you have to pick on reboot. Here I have clicked on shutdown. So what it will do is simply shut down the Raspberry Pi. And so you have to wait a few seconds. Let's say that when you shut down Raspberry Pi like this, wait, something like ten to 20 signals after night. What you do is you take off the power cable from your Raspberry Pi, okay? And then you put the power cable back in the Raspberry Pi, so it will again, okay, for now, this is the only solution you have to boot. A Raspberry Pi is when it's Troodon is you take out the power cable and you put it back inside. So the pie is no routing. You can wait a few seconds or maybe up to one minute. Okay, and now the VNC client has connected again to the Raspberry Pi, and now it's much better. Okay, so you can go here and click on Enter full-screen mode. Okay, and now you have your Raspberry Pi fullscreen with the same resolution as your monitor. And you can click here to exit fullscreen. Okay, so great. You have setup everything and now you're ready to go to the next step, which is to start some programming with Python on your Raspberry Pi. So at this point, the important thing is that the configuration is working. If you don't understand all the steps, especially the common line tools we have used are the different options. That is really not a problem here because we are going to come back to that little later because this is kind of more advanced. Okay, I'm making glucose very easy at the beginning and going step-by-step to the more advanced. What I encourage you to do before we actually go to the next session is just play around and see what's inside. You can open a web browser. You can just take the default options, okay, be curious about what's in there. And I will see you in the next section. And one last very important thing is actually when you want to shut down and pull off the Raspberry Pi, don't just take off triple cable when it's running, okay? You just don't unplug your computer when it's running, okay, first what you do is you go here, you shut down your computer, and then when it's completely shut down, you can remove dipolar cable. Ok? So if you don't do that, you may correct the ethical and when you put again, you might have an error. And in that case, you would have to completely reinstall your Raspberry Pi. 13. Program with Python3: Alright, let's do some programming. Please make sure that you've correctly done every step from the previous section and that your raspberry pie is installed and configured. This is very important so you can follow along. From now, I will do everything using the Raspberry Pi desktop. So before you actually start to program with GPIOs camera, web servers and so on, you need to have some basics in Python. This section is here so you can get all of the required Python programming knowledge to start doing fun projects with your Raspberry Pi. At this point, you already know Python. Be free to jump ahead to the next section. However, I still recommend you watch the next lessons as the remainder. Ok, so let's get started. 14. Your first Python program - Discover the Thonny IDE: Let's start with a very simple Python program. First of all, well, where can you write an execute your Python programs? Well, here we are going to use a software that is already installed for you on the Raspberry Pi you're breeding system. This software is called funny. So you can simply started, you click here on the menu and then programming, and you select here phoneme Python IDE. So this will start the IDE. And actually the first thing you're going to do is click here, switch to regular mode k because this is a very simplified view. Maybe a little bit to simplify. And we're going to switch to regular modes. So you can click here, click on OK, and then you can close it and reopen it again. Okay, and it's much better now. So basically it's the same thing, but you have like the menu bar here and few more options that we are going to use. This software right here. A great tool where you can write Python code, save a Python program into a file, and also run and debug your programs. It is very handy because setting up Python with the environment can be quite tricky. Here. Nothing to do. Just open up Sony and you're good to go. We're first going to look at the bottom part here, named the shell. If you ever close it by mistake here, for example, I click here, the shell is gone. What I just need to do is click on View and click on shell and shell is back. Again. This shell part is an already configured Python under amount where you can simply run any Python command you want and it will be executed right away. But go ahead and do a basic Hello World program. So what do we want to do is simply to print some text. You can use the already existing print function from Python to print any text you want. So you can type print and then you open up the parentheses. You can use quotes, okay? Because we are going to provide a string, okay? So you can open a quote and let's say for example, hello, Raspberry Pi. Well, you end the quote and you close the parentheses. Now what you can do is press Enter, and as you can see, we have hello Raspberry Pi. So what happened here is that in this Python Under Armour, and here you have executed that command. So the Python interpreter will actually get that common. No, it has to print something and that's thing is what you've provided inside the Our Antilles here. And it will print it in the terminal. Where you can do is also click on the arrow from your keyboard, ok, and that we bring the last commands you've executed. So if you want to execute again, you can just use the up arrow and execute that line again. Now, you could create an entire programs like that on the shelf, but as soon as you close the shell, your program will be gone. So what we're going to do from now on is to write the Python program into a file so we can save the file reopened phi and also run it. And to do that is very simple. If you have a text editor panel where you can simply write all of your biofilm lines, okay, all of the Python commands. And then from that file you are going to be able to run it and see the result in the shell right here. So let's simply write a print command here. So in that pre-increment, I'm going to say Hello. I like this. It's just changing the string. And now to execute it. So if I press Enter here, well basically I can have as many lines I like wanting my program. So to be able to execute it, we are going to click here on this Play button. The first thing it will do is to ask you to save the file, okay? It will ask you to simplify before you can execute it. So what we can do here maybe is to get organized and go to documents. Okay, so first you are in your home directory here, which by the artery because it's the pie username. So you go to document. And let's create a new folder by clicking here. Let's name it Python programs. Ok. You are in your Python programs folder. And let's name this file. Hello, wald dot P Y. Ok, so the blazon, fine. We'll have PY extension. Ok, you must have all your Python file have nice extension. Otherwise, it will not be recognized as a Python file. And then for the name of the file, don't put any space. Okay, don't write a name like that. Hello space, world. If you want to put space, what you can do and what I usually do is to add underscore here. So hello underscore, world dot pi. We can click on OK. That will save the file. So you can see now we have the helloworld dot Wi-Fi saved in that directory. And now you can see on the shell here we have document. So this is from the thorny IDE around helloworld dot and the string here, hello i that we asked to print from that current. Great, so the result between this and that is the exact same result. But here we have, of course, file. And I can run it again if I want cake and just run it as many times as I want. I can also hear and go back to the previous command with the up arrow, okay, run hello world, and it will run the program again. And well that's pretty much it. Great. You can now use Python to print something on the screen and you are able to even save the file so you can reuse it later. And of course you can write as many comments as you ought. We could totally add another brains, let's say ABC. Okay? And let's print it. Let's run the script. You can see we have hello BIN a missing. So when you use print multiple times, it will go back to a new line every time, as you can see here. Also, you can have empty lines, as you can see where higher three empty lines here, I can just remove them if I want to. I can add empty lines between different commands. It really doesn't matter. This is just about how you organize your code, okay? And of course we are going to discuss more about that later on in this course. Where you can also do is to add a comment here so you can add stag before a line, and this will command all of the lines. So basically, as you can see here, when I add this, the line is knowing light gray. And a command line simply means that this line will not be executed. So now if I run the script, as you can see, I only have hello API. I don't have the ABC printed, OK, because I have put this line has a comment. You will see that comments are very important later on when you program with any language, okay? They will make your code much easier to understand for other people and even for you when you come back to your code, for example, we could add a command here. Says the next line will print abc. So this is quite obvious here, but this is so you can get the feeling of how to use commands in comments are also great when you just want to skip one line, okay? For example, if I want to skip deadline from being executed, I just put a comment. I can run the script and then if I want the line back, I just end comment this line and it's fee. I don't need to delete it completely. Okay. And the last thing I'm going to show you here is if you have some errors, because for now, when we run the script, everything works well. We don't have any era, but maybe here, let's say forget this parentheses here. I run the script and as you can see, we have a syntax error. Ok, so when you have an arrow like that, it will be in red. And you can see the filename here, which is obviously this file over there, and also the line. So this gives you the line length four, whereas line four, you can see that d rho comes from that line, okay? And then you have an explanation that can be sometimes very explicit, sometimes not. Okay? And here you can see that print abc, the parenthesis is missing. I can also maybe have that if I forget. To end the string again, you can see we have a slightly different message, okay, still in line for, let's say instead of print IOUs prints, because I forgot the n, Then you will have an arrow named print is not defined. Okay, so you can have a lot of different errors in your program. And as you begin with Python, it's quite normal at the beginning to get a lot of arrows like that. So when you get an arrow, make sure that you've correctly written out of the liters of the symbols in the right order, okay? Because one small modification here will just cause an error. Ok, it's very easy to get arrows at the beginning, but don't worry about that. It is part of the process. So great. Now you can use Python to print something on the screen. This is a really good first step for k because we are going to use that print function a lot to debug our programs for all of the duration of the course. And now that you can use this funny ID, let's continue and start with variables. 15. Variables: One of the most important things to learn first is how to use variables with Python. And first, let's understand why you need violence. So I've made here a very simple and dumb program which basically prints for and then prints for and then prints for again. So of course, if you already know a bit about programming, you may think that, yes, we should use a loop to do that three times instead of writing three times the print function. And that is a right, and that is something that we're going to do later on here. It's just to show you the why we need variables. Okay? So let's say here, I am printing for under ice, okay, I want to print seven. So let's say I need to change seven here. Also need to change seven here. And I need to change to seven here. So as you can see, every time I want to change the value, I need to change manually the number, every occurrences, okay, now let's, I want to change to eight, a change to eight here, and I forget to change to eight here. So when I run the script, I get 887 and maybe something we were wrong. Okay? So that will be much simpler if we could just set the value once, okay, and then use that value without having to remember every time which value we have to set. Okay, and here it's only a three line program, but as you can guess, when we have hundreds of line separated in different files, it will be a real mess if you don't have variables. So for example, I'm going to create a number variable equals seven, okay? And what I'm going to do is simply to replace the number here. We have the actual number viable and run the script again. So now we have 777. And if I want to change the value, let's say we go back to four, then I can run the current script and we have 444. Okay, so we just need to change the value of the variable once and it will be updated for every time we use the dial. So basically that's the first approach of why you need vial. And now what I'm going to do is simply open a new file. Okay, so that example was just stand why. And now let's come back to an empty program and start from the beginning. So what is a variable? A variable is basically a container where you store an information to use later. A variable has a name. So this is easier for you and your computer to recognize it. Basically, almost all values that you will use in your programs will be stored in violence. You can give any name you want to a viable. For example, let's create a variable that is named just a OK. And that variable a will store a number, an integer number. So what I'm going to do is write a that is the name of the variable. And then I'm going to write equal to assign a value to that variable. And then I'm going to give the value of the variable, let's say five. Okay? So with this line, when this line gets executed, basically what it does is it creates a variable named a and it assigns the value five to the variable a. So what's on the right goes into what's on the left of the equal sign. So what we can do, what we just did before, we can print actually this vial. So when I print a, Actually, I'm not going to see a here and a terminal. I'm going to see what's inside of the variable a, okay, so if I run those scripts, so of course I will need to, David. So let's create variables not by, okay? And you can see that we have five, ok? So the value at this moment in line to the value inside a is five. So the print function, we print 510 are, as you can see, if I change to six, no print with print six, okay. What I can do also to initialize a viable or to set value inside the variable at anytime, I can use some operators like addition, subtraction, multiplication, division, etc. So all of the basic symbols, you can use them. So for example, I can do six times, two, okay? You, you don't need to use bases here, just more readable. Okay, this is kind of a breast practice here. So now I run the script and I can see a is no 12, okay, because six times two equals 12. So this was first interpreted it to 12. And then with the equal sign, 12 is going to the a viable. Ok. And once you've assigned a, once you've created a variable here, you can, later on you can change the value inside that variable. Let's say I do a equals one, okay? I just change to one. And if I print the value of a at this point, then you can see we have one, okay? At this point it was 12, and at this point it is one. So if I print here, I have two brings, okay? The first one is 12, the signal one is one, okay, because the program gets executed in the other. Ok? So first we go to line 18 equals 12. Second we print a, so we print 12. And then line three, we set a new value to a, and then line four, we print the value from a. Ok, this is the exact same line as line two, but this time the value inside a has changed and it's no one. Okay, so you can create a variable, you can set the value will default operators. You can assign different values. The time of the program to same variables, okay? And what you can also do now is to create any other variable. Let say create variable B, which is equal to three, then I can print b, etcetera. What I can do also is to create a variable, let's say b. And instead of setting the value three, I can set the value from a. I can say B equals a. So what this means is at this point at line six, the value inside a will be evaluated. So at this point, a equals one, okay? So B will be equal to one. So B will be created and will be assigned a value which is one. So now if I do print B, I will see that b equals one. Eigen also do for example, a plus one. And b will be two, OK, because we take the value from a and then we add y. If I remove that here. So I have a equals 12, and then b equals a plus one, then b equals 13. So as you can see here, the order is very important, okay? If you assign different values to a before you create B, then of course the new value of a will be used. And also if I tried to run that command before that one, Okay? If I tried to do b equals a plus one, but I haven't defined a before. What will happen is we will get an arrow that is quite explicit here on line one, as you can see, line one, so this is the line one. We have name error. Name a is not defined. So you can see here that we are trying to access a value from within the a viable. But this variable has not been defined before. When we need to do is we need to define a before we actually use B, because B depends on the value of a. Now foreign again, it works. And finally, what I want to add here for variables is that you should try to always give a meaningful name to your variables. So I've only used a and b here as an example. It's okay to make things very simple. But let's say that you want to store a temperature inside a vial. Not just say a equals 45. Ok? If you want to store a temperature, then you will name your variable temperature. Okay? Maybe temperature, Celsius temperature to Fahrenheit, or like you can use storage temperature, warehouse temperature. Just give a meaningful name to your viable. If you want to create a counter, then simply name it counter. If you want a user age variable, then just use user age. And as you can see, again, we don't use here, we use underscore. So whenever you want to separate worlds with space, simply use an underscore. So that will make this one via OK. If I do that, you will get an error, invalid syntax, okay, you can't have just two names like that. You need to have an underscore here, and it will work. Great. So to recap, a variable is a container that you can use to store a value and re-use that value later on in your program. To create a viable, you must give it a name and assign a value to it. 16. Variables - Data Types: In the previous lesson, you have discovered what we're vegetables. And so far you've only used variables to store integer numbers. But in fact, there are many more types you can use. Let's discover the most important ones now that you would basically need in all of your future or programs. And again, for any variable you create, make sure to give a meaningful name like that. For example, here I'm just going back to using a and B and stuff. So it's just easier to explain you the variables, ok, but keep in mind to give meaningful names. So what you've seen for now is the integer type and just going to print a again. Okay, so integer is simply a round number, 5612356. You can have also minus, minus five is an integer number. So minus infinity to plus infinite, just with round numbers. What you can have now the single type you can have is float number. So let's say 3.14. So when you have a comma here, when you have a float number, you simply need to put a point, okay, that will make a float number. So now if I run the script, you can see that a is no 3.14. So basically you have two different types for numbers, the indigenous and the float numbers. Now you can also use strings. So for example, hello. We've seen that before with hello world programs, okay? You use quotes, okay, and between the quotes you put any text. You can also that number, just, just anything you want. Okay? And this will be a string. So no, a is a string. So that type will be very useful whenever you want to deal with text. And a fourth type I want to show you here is the Boolean type, okay? So the Boolean type is basically true or false. It is a two-state type. So you have true, okay? As you can see here, we have a special okay, when you type true, you can't have true or you can have false. Okay? So if you don't have this color, it means that you didn't write correctly the true or false. Okay, this is an uppercase not locate. If I do that, we have an ERA because false is not defined. Okay? It, we tried to look at variable name false, which doesn't exist. But the keyword false with uppercase is actually a key word in Python that is recognized by your program. So now if you print a is false. And if I set it back to true. Now a is true. Okay, so that's it for the types for non integer, float, string, and boolean. As you can see, the type of a variable is dynamically set. When you create the variable, you don't have to specify any type here before the name of the variable. With languages like C, C plus, plus, and java, you would have to specify the type when you create the viable, but not in Python. In Python, it is dynamically set. So if you want to check the type of a variable, you can actually do that by using the type function lies. You can see when I use type, you can see the color changes because it is recognised by the IDE. So I can use type and then parentheses and the name of the variable. Okay, so we have print, print function with parentheses and inside we have the type function with parenthesis. Okay? So what will happen is first the type will be evaluated and then the type will be printed. As you can see here, we have class bool. So this is a boolean. If I do one class int 1.00, okay? You can just use 0, and now it is becoming a float number k. And if I put it with quotes like this, now it is a string objects. So if you are not sure about a type, you can simply use that command type with the name of the variable. And then you can eventually print that type to see what's inside a viable. And these types settings also means that you could change a variable types anytime in your program. For example, I could have a which is okay, let's put hello. Okay, to make obviously it is a string. I can then do something with that and then I can set two, for example, in a and let's print type of a again. So I run the script and you can see the first time, but it is evaluated. We have class STR, so this is a screen and then it is an integer. So that is something that you could theoretically do. However, this practice is strongly discouraged, even if you can theoretically changed the type of the variable at any time. In practice, this is a very good way to mess up your programs and get a lot of errors. So when you've set a viable, when you've defined a variable, you can change it to any value after that, but stick to values that are of the same type as the original one. So in this case, if a is a string, then a would stay a string and then I'm only using it for strings, data types. One advice to avoid mistakes we've types is simply to use meaningful names for your variables. So for example, let's say I have a Wi-Fi name, viable and I give it a string. So for example, your Wi-Fi. So this is pretty clear that this will contain a string, so later on you will not use it to actually store a number. Ok? If I have a user age variable, let's say 45, it's pretty clear that user age will stay an integer number, okay? Then for example, temperature can be 20.3. Temperature will not be a Boolean, temperature will not be a string, okay? And is alive, for example, true or false. You can expect to live to be a Boolean. So that is how basically you can avoid mistakes with types. And at any point you can also check the type of any variable with the type function is alive. For example, this will give bull and you can put that inside a print function. So to recap, you can use different types, four variables, depending on the value you want to store. Horizontal integers, float numbers, strings, and Booleans. 17. Functions: One of the most important things you want to do when programming is to avoid repetition code too much. Let's say, Hey, I have this program. So first I create variable a. I initialize a 22 a, which is an integer. So a will be an integer variable. And then as you can see, I do the same thing three times. So I multiply a by three on this line, on this line, on, on that line. So instead of repeating the code to triple the number, every time we need to triple the number. Maybe we can create a function that does just that. So then the code to triple the number, we only be written once and we can use it anytime. So what is a function? A function is a re-using will block of code that you can call from another part of your program. A function has a name and it can take some input parameters, as well as written some values. Let's create a function here so you will understand what I'm talking about. So I'm going to create a function at the very top, the program here. And create a function first, you will need to use the keyword def, def to define a function after death, you need to give the name of the function. So as I told you with variables, you need to give meaningful names. So what this function will do, this function will triple a number. So let's just call it triple number with a underscore here so we can have a space between the two different worlds. We saw that is the name of the function triple number. Then we will add some arguments here, some parameters between parentheses. Okay? So that is the input parameters. And we want to triple a numbers, so we expect to receive a number. So you just given name here for the input parameter, and then you add a color. So every time you write a function, you need to do that. Deaf. The name of a function, the arguments you need to pass, and then a column. And if I press enter Now, as you can see, we have a new indentation, okay, which is here, four spaces. So I'm going to come back to the invitation later on so you will understand why we have in notation in Python. And now what I can do here in that function is, well, I can use any instruction I want. Ok. I can just put any code I want and do anything. I can change the variable. I can change the data inside the variable, I can print something. And finally, what I can do is also to return a value. So when you add the return keyword, you can see it has a special color here. So you can return a value, and when you return a value, let's say written number times three, okay? When you use the written keyword, the function will exit and we written whatever you have on the right here. So when I do triple number with the number parameter, what I do is I written three times the number parameter. So great, I have a function here. And now what I can simply do is use that function here, for example, triple number. Okay? I open up the parenthesis, I close the parenthesis, and inside I give a number. So let's give them the number a. So instead of giving a number, I give a viable, the variable will be evaluated to its value, which is here too, okay? And then the two will be here assigned to number. So it's like we create a number viable inside that function. Okay? And then we return the number times three. So here the value will be two. W goes inside here, the value gets here, and then we return two times three. So the return value will be here. When you call triple number a, this will be evaluated to the return value of the function. So here you will have six and then you have b equals six. So the value here will be assigned to the variable b is, so you can just use that. Okay? And as you can see, the name here is very important because when you use the function triple number, you expect the number two we tripled, okay, if I just did times two, then it doesn't make any sense. And you should have a double number function, okay? So I'm going to keep it like that. So now I can, of course render program. Let's save as functions by. So when we actually run the program and nothing is printing on the shell because of course we don't ask to print anything nor I can, for example, to print print the liable be okay, check what's inside. And as you can see, we have six inside. Ok? So now every time you need to triple a number, you can simply call that function anywhere. Okay? I can also do, for example, here, the triple number a plus triple number of C. Okay? So I'm going to run the script in. Actually, maybe I can print D instead of b. And you can see that deep. Equals 24. Okay, why 24? Because we tripled value from a, so a is two, so we get six here. And then we triple the value from the variable SC cable. The variable C was already using that function. So the variable signal contains six, okay? And what we do is we triple number and no, C is evaluated to six, ok, so six goes there. And six times three is 18. And we have 18 plus six, which gives us 24. Now we can go even further. Let's create another function here that I call Deaf print triple number. So then function will simply print the triple of any number. So in that case, what I can do is I can do print and then triple numbers. So I'm calling a function inside a function, okay? And the value I'm giving it here is simply number, ok? This is the value you got from the parameter. Okay? And I have to close the parentheses twice, once for the print function, and once for the triple number, okay? And now if I called that function here, print triple number, if I call it here with, let's say B Iran scripts. And I can see 18, okay, because we triple first a, we put the value inside me and then we triple B. And here as you can see, this print triple number doesn't return any viable OK, doesn't return any value. So you can have two types of functions. The functions that return something and functions that don't return anything. Another example is, let's say do deaf, say hello, okay? And here I'm not giving any parameter, okay? And in that function I simply print hello. Okay? Now I can simply call, say hello. And I will see that we have Hello printed on the shell. So to recap, a function is a reusable block of code that you can call from any part of your program. It has a name, as you can see here. It can contain some input parameters, okay? It can contain one, but you can add many other parameters with a comma between each parameters, okay? Then you have column and it can return a value or not. You can also call a function from within another function, okay? So you can have a lot of layers between your function locally, you can have function a calls function, meaning that calls function c, etcetera, etcetera. And one thing to remember is of course, to define the function. So to write the function before you actually call it, okay? If I use say hello here before I define the function, then we will have an arrow, okay? Just like when you try to access a variable before you have created, okay, so first declare your function and then call the function, okay. 18. Variables - Scope: Great. You can know create basic Python programs using variables and functions. But before we go any further, there is one thing you need to clearly understand. And this is the scope of a variable are what can we call it also as the visibility of available. Depending on where you create a viable, it may or may not be accessible from another part of the programs. So let's take an example here. Let's say I create my viable a equals five. So of course I can print a, no problem, this will walk. So let's say we scope. So this work because a is in the same scope here when we use it here and when we use it here. And now let's, okay, let me create a function here. Let's say print a gages very don't function. Two will simply print a here. So if i really, of course, it's not, nothing is printing because I'm not calling that function. So I need to call that function so it can run. And we can see that it works. Okay, we have five here, which is the result of print. And this works because a was defined here. And now we actually use it here. Now let's create another function, def create. And I'm going to create a variable name be. We have a value ten, ok. And what I'm going to do here is print k, So I create b, and then I print me. And let's see what happens here. We have an era name B is not defined in line ten. Ok, as we can see, 910 here, named B is not defined. Why is that? Well, this is basically because b here is not on the same scope as here. So when you create a viable at the top of your program here without any indentation, you can use it everywhere. After that, it is what we call a global variable. When you create a variable inside a block of code with indentation, as you can see here. For example, inside that function, then the variable is a local variable. The variable is here created inside the function. So it means that we cannot use it outside of this inner Don dated block of code. After the block of code is executed, then the variable is gone. The only way to access that variable is between its creation here. And the end of the block of code which is here, immediate. The rule we scope is very simple. A viable will be visible in the scope. It is created in and in every nested scope inside this initial scope. So when you have the variable a here, which is in the global scope, it is visible from the scope. So if I do print a, it will work. And when I use the variable a inside a block of code that has more in notation than it works, okay? But the viable we create here in a more inundated block of code will not be accessible inside a less indented block of code. So that's why we have the era with print p. Because we are trying to access a variable which is declared in a more nested scope from a more global scope. And funnel, we only have one level of imitation. But then you will see that you can have much more levels, which means that we have more nested scopes. If I go back to the function, let's open the functions. Okay, here. As you can see, we have number and number here. So basically when you create a function, the parameters you give there, so you have to give a name. And what it will do here is it will create a local variable inside that function. Ok? So the variable number will be created here, and it will be assigned a value at the moment when you actually call the function. So here you assign the value from a which is two. So when you call triple number, number will be assigned an integer value from this line. And then number will be alive until you actually go out of this block of code at this point. So you return the value here, number times three, and then the number variable is destroyed. And that's where you can actually have the same name in two different scopes. Ok? This scope is completely different from that scope here, okay? Two different scopes. So you can have the same name for the two different arguments. We'll not conflicts between each other, okay? And there is no way from that actually block of code to get access to that variable here. So when working with variables, always keep in mind the scope of the violence. Is this variable declared in a more general or a more local scope? And in the scope that I am currently writing in, can I get access to these viable? Once you get used to it, it's fairly simple to spot the scope of any viable. And of course we are going to come back to this a lot of time during this course. 19. Activity 01 - Create a Function to Concatenate 2 Uppercase Strings: This is the first activity of these codes. So when I give you an activity, I will first make an introduction. Video or text depends. And I will give you your challenge to do, which will make you practice on what you have just seen before, okay, I may also give you a few tips so you can start with the activity and then the next video will be the solution. What are you going to do in this activity? Well, you're going to create a function that will concatenate two strings together and make them uppercase. So what do I mean by that is, okay, let's say you have a string, hello, okay? And you have the string world. So that would be the two inputs for your functional. And the output will be Hello space world, but actually uppercase. So hello space world. So you have a function which takes two arguments. Then you give the two arguments. And that function will create a new string, okay? Which will actually, but the two strings together with space and put them uppercase. So just two things here that you actually don't know. So I'm going to tell you that so you can continue with this activity. When you have a string, let say string name Esther, you can simply do dot upper, and this will make the string uppercase. So that is something you can use if you want to actually bring two strings together. It's very simple. Let's say you have a ABC and DEF. Then if you want to create a new strings with a combination of two, you can simply do a plus B. Okay? When you do a plus B, then the result will be ABCDEF. So now it's your turn to practice and make sure you take enough time to do the activity, okay, because this is where you will really apply. What you've just learned in this is where it will all make sense to you, okay? And even if it's hard, I really encourage you to take time to work on this change if you need. Just go back to the previous videos ok, where you can rewatch the explanations until you understand. And then I will see you in the next lesson for the solution. 20. Activity 01 - Solution: This is the solution of the first activity where you have to create a function to concatenate two strings and make them uppercase. So let's start and we are going to create a function. First, we need to write the keyword def to define the function. Then we need to give the name for the function. So the name, because we need to concatenate two uppercase strings, that's name it, conquer the innate uppercase strings. So the shorter the name of the function, the better, but it's also much better to give a meaningful name, so it doesn't have to be only one or two words, okay? If the function name only makes sense, if you have four different worlds, then use for different worlds. And actually we are going to receive two different arguments for this function. And simply let's, let's name them Esther. Esther, big string a, string B, which makes sense for that functions, okay? And that actually variables that will be created here when we receive the parameters and there will be destroyed right after that function. So for the duration of that function, it is perfectly clear that SQL is a string and as TLB is another string, and we are going to do stuff with both strings. So Now, don't forget the column. You press Enter and you have the implementation. If you don't have implantation, you can simply use the tab and make sure you have 44 spaces here. So what we can do, let's say mu, we can create a new string which will be best year a plus STR. Okay? And because we need to make them uppercase, I'm going to use STR, a dot above and as TRB dot. Okay? And there is one more thing we need to add is a space, okay? Because we need to add a space between the two strings. So what we can do is simply add a new space like that and plus. So you can, as you can see, you can add any number of strings. So first the string a with uppercase, then we add a new string, which is a symbol space. Then we add the string b as an uppercase string. In what we can do now is to return the new string. Okay, and I've just created a new variable here to show you that we can actually optimize this career here because we just create a new variable that we don't really use, okay? And we simply return it. So instead of doing that, we can simply written the result, ok, if we need to use the result of that inside that function, it would have made sense to create a new string viable. And then use it. And that would be a local variable inside that function that you could not use anywhere else outside of the function. But now because we just need to written it, then you simply use written. Ok, so we have a function, but if we just run the program like that, so let's run it. That would be Activity one. So if I run the activity one dot pi, of course we have nothing because when you actually create a function, you don't ask to run that function, you just create a function so you can use it. It's like a template you can use, but you are not calling it. So if you don't call it, nothing will happen. Ok? So now we create a variable named result, and I will call that function concatenate. What you can do here. I'm going to breath control and space. Ok. And as you can see, this will make the rest of the function here automatically appear on the screen. Control space is basically the auto completion tool, which is specific to this thorny IDE, okay? And this is a great thing to do, okay? You can stand the name of a function and use control space to see what are the different possibilities or just to go faster when you write code. So now I have the name of the function to call it, I need to use parentheses, okay? And I need to give two parameters here, okay? Because there are two parameters, I need to give two parameters. Let's see what happens if I just, so let's say hello here. If I just do that, what will happen is we will have an IRA macaws. Okay, here's pretty self explanatory. The function is missing one required positional argument, which is as TRB k. So this will go into STR eight, but we are missing as TRB. So hello world. And then I can run the script. And now it's working. But of course we don't have any thing printed on the screen because we didn't ask it to print. So print result. And we can see Hello, world, great and same as we did here. The, we have created a variable named result here in the global scope that will contain the result of that function call. But because we do nothing else than just printing the result, we could just actually do print here. And but all of the function call inside the print parentheses, okay? And remove that. So here as you can see, we can actually use a function as a parameter for another function. The print function is a function, so it expects you to give one here, one argument that is a string or some value to print. Okay? But actually that value can be from another function call. And for example, you could actually here, instead of hello world, let's do. So. Now it's, it's quite long, okay? But you can actually see, you can actually call a function inside a function if I, if I run that, what happens is we have Hello, Hello World. Because what will happen is we have the print, but inside we have concatenate uppercase strings. And inside we have hello and another concatenate uppercase strings. So that will be executed first, it will be evaluated to this hello world. And then for this function we have hello plus HelloWorld. So it will be evaluated to Hello, hello world, thanks to that function here. And then it will be actually used by the print function. So that is the end of the activity. If it was a little bit too hard for you, come back to the previous lessons, watch the explanations again and tried to do the activity again until it's not difficult for you anymore. 21. Conditions: For now you have seen that the instructions you're right in a Python program will be executed one by one, and every instruction will be executed. But as you progress, you will want to make your program more dynamic and also be able to execute only some of the instructions depending on some specific conditions. For example, you might do a certain action if a button is pressed, and if the button is not pressed, you will do another action, which means that some of the instructions will be executed. Some of them won't be executing. So let's write our first condition in Python. I'm first going to create temperature variable. Okay, let's, let's give it 21 degrees. I'm going to talk in Celsius degrees here, but it doesn't really matter. So I'm going to use integers, okay, for temperature viable and to test something. So to use a condition, you are going to use the keyword if here you can see the cure, if the color here, and if, if, what if conditions. So the conditional statement, let's say temperature is greater than 20. So we are going to test a variable inside the if. And this is the condition statement that we are testing. With this symbol, it means greater than. So if the temperature is greater than 20, then I add a column. I go to the newline and as you can see, we have a new indentation. So what does it mean? It means that if this condition is true, then that code here, that block of code will be executed. So let's just add one instruction here. Let's say print one. So let's say just, it's warm. It's, it's water. Okay. And then I'm going to just run that code. I'm going to save it. Conditions. Okay? And as you can see, we have the result. It's okay. We have that result because here the temperature is 24. Okay? So when we arrive in the line of the program here, the temperature variable will be evaluated to 21. So if 21 is greater than 20, so it is 21 greater than 20, yes. So we execute that block of code. Now let us say temperature is now 19. Let's run the script again. And as you can see, we don't have anything here, printed here. And here. Let's say I add a new instructions, but here I go back one inundation and I add another print, let's say end of program, just making Siebel and I run it. You can see we still have the end of program. So if here, the if statement will only affect the following indented block of code. That is just something else. So you can see that first block of code, okay, which will be executed, we create a viable temperature. Then we test the variable temperature. As you can see, it's on the same here. Same notation. If this is true, we go to that block of code, and when that block of code is finished, we come back to the previous notation and we continue to execute all of the commands. Okay? So that's why you can see that even if here, we don't enter that block of code because the condition is false, we still execute everything that is after. But now if I, let's say I indent that line and let's run again. You can see we don't have anything here because this is no part of the block of code inside the if statement. So I'm going to put it back there. And let's let's, let's put 30. If I put 30, we will have its one and then we will have end of program. Ok, so it's always executed in the other, okay? And if it's just that some parts of the code maybe executed or may not be executed depending on the condition here. Okay, so we have our if, your if block of code, what we can add now also is, It's okay. And you can see we have the column here for else, so else and a colon, and then you go back to New Line, a new indent, also the block of code. And let's say print, not. So one. Okay, so what does that mean? We test if the temperature is greater than 20, okay, if this is the case, we enter that block of code. And else, so if it is not the case, we enter that block of code. So the if else structure is really useful when you want to test a condition and when you want to execute something if it is true and something else if it is false. Okay, so let's run the program again. You can see It's one, okay, because that condition is true. So we under that block of code, No, if I put nine degrees, you can see not so warm and we still have the end of program. So what happened here is that first we said the temperature variable with a value nine. Then we arrive at this if. And we test if the temperature is greater than 20, this is not the case. So we don't go inside that block of code. Instead we go inside the else block of code and we execute that instructions here. And of course you can add many different instructions, just keep the same indentation and it will be in the same block of code. And finally, to make things a little bit more complete, we can also add else. If ok. And in Python, you can use elif. And let's make an example so you can understand, I'm going to do temperature greater than ten, let's say Print. So temperature between 1120, elif, temperature greater than 0, and print temperature between 110. And let's say it is freezing cold. So when did I do here? I have added multiple else if statements here. So basically all of that is one structure, OK. And you first until structure with the first if and you test. If that is true, then you execute that. And after that, you go out of that Trojan. So you go back to line 11. If that is not true, then you go to the next line, the next leaf line, and you check the condition. So if the condition is true, you will execute that block of code here. And once you have executing that block of code, you go out of the structure. So basically you test the conditions and whenever you have something that is true, it will execute the following inundated block of code. So if I run the program here, you can see temperature between 110, okay? Which means that this test has failed. So we go to the next one. This test has failed, okay, because nine is not greater than ten. And then we go to that test here. Is nine greater than 0? Yes, so we enter that block of code and then we exit. So let's try it with, let's say minus six. You can see it is freezing cold. So we have checked all of the different tests and none of them passed. So we are going to the else block. And one more thing here, the order of the different tests is very important because the first test that will be evaluated to true will be accepted and the first block of code will then be executed. And not the following ones. Okay, so let's say I use 0 here and 20 here. And I putting, let's say 35 degrees. Okay? As you can see, we still go into that first block of code. Not that we're okay because here that is true. The temperature is greater than 2035 is greater than 20. But if you look at the way the program is executed, if we go there, so is temperature greater than 0? Yes. So we do that block of code and then we exit the structure. And as soon as we have accepted one condition here are of the rest won't be executed. Okay, so make sure that when you do a condition like that, you pay attention to the order of the tests, okay? Because in that case, this test will always be true when that one is true and when that when is true, which means that those two blocks of code, whale never be executed with that specific order. Okay? Now if I go back here, there is a chance for every block of code to be executed. 22. Condition operators: You can now use conditions to test some variables. Now let us see what are the different comparison operators which will allow you to test different things. Okay? So, because now you've only seen the greater than operator, but actually there are quite a few more of them. So let's start by commenting all of those lines. What you can do is select the lines here, right-click and command out. You can also adjust toggle commit here. You can also use that shortcut if you want to write. So now if I just write script, nothing will appear here because those lines won't be executing. So let's create a variable here. Let's say a equals 5C. And now I'm going to show you all of the most common condition operators. So the condition of burritos, you will use them inside the if statement. Okay, so for now you have seen if a is greater than five, let's say print. Let's just print, okay. Let's see how it goes. And as you can see, okay, is not printed because here it is strictly greater than five. Okay? So five is not strictly greater than five. Okay? So if I put four here, then it will work. But we five, it will not work. What we can do is we can ask to check if a is greater or equal. And in that case, it will work. Okay, so you can use the greater, which is strictly greater than or the greater are equal. And now of course you have the opposite which is lower than. So let's test if a is lower than six, which is true here because five is lower than six. And know, if I go back to five here, of course five is not lower strictly than five. Ok? So this is strictly lower than. And now I can use lower or equal. And it works in the situation. So to compare a something is greater or lower than something else. You can use the lower than, the greater than operator. And if you want, you can add an equal sign, which means greater are equal, lower and equal. So you already have for different comparison operators. And now another one which is also very quite useful is the equal operator. And the equal operator, it's very important that you pay attention to that you must put two equals. That is a very common mistake among beginner, is that you only test a equals five like that when you are not used to programming, it can really make sense to write that if a equals five, which seems normal but it won't work. You have to write if a equals, equals five, okay? If you don't do that. You may not have an arrow, okay? Are you will have an error that will be quite hard to understand. So this is very important that you pull the two equal signs, okay? So this will test, of course, the equality. If I run scripts, I have, okay, because a is five and we taste is five equal to five? Yes. If a change to any other value, of course it will not work. So let's put five here. And now you have the operator to test the difference, which is just the opposite. And instead of the first equal, you will put a exclamation mark. So exclamation mark equal means different. Okay? So if a is different than five, we print, okay? Okay, which is not the case here. So let's put seven by is different than seven. We print OK. So quick recap here. You have the equal, equal operator to test. If two things are equal, then the not equal operator, then you have the strictly greater than. The greater than or equal. You have the strictly lower than the lower are equal so that the six operators that you will