Transcripts
1. 1 Introduction: Hello and welcome to this new course in which we are going to give you an introduction to programming hardware and Python. Are you interested in the Internet of Things, home automation and connected devices? Have you ever wondered what it would be like to build a plasters, a laser swirled, or even your own robot. If so, then you are in luck. Micro Python can help you do all of these things and even more. Now, as you know, on automation and Internet of Things is one of the mosque trending topics nowadays. And knowing about Python or automation, internet of Things is I'm asked for any embedded system engineer. So in this course, we will talk about the history of microbiome icon and the differences between micro Python and other programming languages. The hardware you will use to build devices using micro Python and are processed to still up, or let's say sit up, code and deploy your own micro Python project. Now, let's talk about to what you will learn in this course in details. First, you will learn, we will talk about the history of micro Python. Then we'll talk about why using micro Python, why not using any other language. And we will discuss the differences between Python and other programming languages. Then we will cover micro Python hardware, hardware that you can use. And they interact easily with micro Python coding. Then we will cover that our micro Python workflow in details. And how to sit up micro Python on your board will whatever doubled that you have chosen, all whatever the bolt that you have at hand. At the end, we will talk about creating and deploying your code and testing it out. I'm sure that at the end of this course, you'll haul idea about Python. Home automation and intangible things will be changed. Thanks for watching this quick introduction. See you inside.
2. 2 History of MicroPython: Hello and welcome to this new lesson. Now, let's talk about the history of micro Python. Now, python's popularity has skyrocketed. In recent years. These days. It's used everywhere from div ops to statistical analysis and even in desktop software. But for a long time there was one field we're Python. Use was conspicuously missing. Developers working with microcontrollers had not yet adopted that anguish. All of that changed in 2003 when George launched a Kickstarter campaign. And under your graduate from Cambridge University, who was an avid drop-off programmer, he wanted to move the Python world from machines that worked with capacities in the gigabytes down to the kilobytes. His Kickstarter campaign, who was an attempt to back his development while he turned his proof of concept into our finished implementation. Money, the blue bars jumped at the chance only to use Python on microcontrollers, but also to get an early version of daemons yours on reference hardware, which was built especially for the task. In fact, by the end of that campaign, Damon had blown past his 15 thousand Euro goal. Thanks. 2 over 1, 0, 0, 0, 0. Here you just shy of a 100 thousand your. And that means that his campaign was a great success. Now, after that, Python started to go beyond the desktop. Boston had moved off the disk tropes, answer vars, and into the world of sensors, actuators, motors, LCD displays, buttons, and circuits. While this presented many challenges, there were also copious opportunities. This club answer well, hardware requires Gigahertz processors, gigabytes of RAM, and terabytes of storage. In the microcontrol world, however, micro Python is the operating system. Essentially, it sits on top of the processors with clock speed. Harking back to the 19 eighties and nineties. Micro pi phone has no help to deal with all that interaction and communication, complications of code executions. And without puts storage booting and so on. If you want to interface with hardware, then you need all code to enable that. Yet somehow, Damon managed to squeeze a powerful high-performing compact Python implementation down into these miniature computers that opened up a whole new world of potential. If you are interested to learn more about the differences between C Python and micro Python, then you can check out that resources of this lecture where we have links to the shallow GitHub that exoplanets the main differences between C Python and micro Python. Now, what we need you to understand so far is that one person was able to stars, Let's say that Python implementation and the microcontroller uncensored world. And from that point, micro Python was created and started to spread out among engineers who developped a lot of projects using this very simple and easy method. Now, we will exhibit in details in the coming lectures, but this is everything that we need you to understand. Micro Python help minimizing the size of data from gigabytes to kilobytes. And it also helps speeding up the processing of information inside a microcontroller. All of that is because one person decided that this can be done and ask for support or Kickstarter. You can be the one who starts and other evolution if you wish. And it only requires one symbol for that's watching this introduction. And I hope that you, now you know the history of microbiome. This is Ashraf.
3. 3 Is MicroPython Read: Electronics as a Hopi and a career path. Micro Python is supported by a diverse community of Python S WHO have a deep interest in seeing that project succeed. Along with distinct and supporting the codebase itself. Developers contribute tutorials, code libraries, and hardware ports. Over the yields, micro Python has attracted professionals and hobbyists from other platforms who sees a potential and convenience of the language. These different bars may have come from more mature platforms like Arduino or PIC, microcontroller. Money came to realize the benefits of using micro Python, as well as specifying Python and micro Python together. Not least for rapid prototyping and faster time to market. So is micropipette ready for serious mission critical work? The European Space Agency, or in short, ESA seems to think so. They helped fund daemons work on micro Python because they wanted to use Python in space. You will increasingly see a critical mass of hobbyists and learners move into academia and from there into the professional world of electronics. At that point, micro Python will truly take off.
4. 4 Python and STEM: Now let's talk about Python and SEM. Sem subjects have been under the education microscope for several years, which has led to an explosion of projects and products targeting the classroom. Python and micro Python are both will placed for teachers and students alike. The basic syntax and bundled interpreter lend these languages to fictive learning environment. And the fact that nor development environment is required is only an added bonus. A few years ago, WBC launched its Micro bit project to get more kids into computing beyond Office style applications. Their goal was to get a microcontroller board into the hands of every school student in the UK. Them in, through his neighbor, acquired one of these balls and quickly gulf his code. Running. Thousands of classrooms, suddenly had the option to run Python in their lessons. Most recently, it You blocks has taken their micro bit and enabled us scratch like drag and drop Python experience. This allowed even more kids to experience microcontrollers, anthropometrics programming for the first time. R3 on donations support the project's continued growth. So Python and micro Python held in the micro bit Project, which was basically a Broderick that targeted kids. So even kids can program using Python and micro Python using it your blocks platform. And I'm sure that there are other platforms out there who are enabling the Python and micro Python for kids. So anyone can program using Python and micro Python. Now, in the next lesson, we are going to discuss the physical computing, but that's it for this lesson. Thanks for watching this is.
5. 5 MicroPython Physical Computing Elements: Physical Computing. Now, as you know, in physical computing, and input is basically a signal that you receive, all the device received. And we, our button signal, intelligent event or sensor reading takes n that that processing is a microcontroller are processes that input and updates the output. So it's basically the brain of the system. In the physical computing. The output is basically receives a signal from that process. So this can be sent in the form of Amador spinning and LED, lighting up, account up, changing a message sending or some similar event. When it comes to micro Python, what does physical computing mean? Usually, your project will consist of these three elements. And these elements will usually be connected by wires and powered by some power source. So your device will have an input up crossing and an output. Your micro Python calls will be placed inside that plus soar, which is the middle element here, which will take inputs and outputs. That's it. That's watching this lesson. This is Ashley.
6. 6 What is A Microcontroller: What is a micro controller? And microcontroller, or microcontrollers are all around you adding intelligence and control to your devices. They are embedded in everything from appliances and home security setups to pacemakers, to HVAC systems, fridge, washing machine, and even more. Now, microcontrollers do relatively simple things. They after they really ugly and in a compact brackish. These compress a CPU, memory and input, output into one general purpose chip. Rather than requiring a whole bowl of chips that team up to perform a task. While those who grew up with early microcontrollers like that, SSID x and that Commodore vice 20 may find these shapes unbelievably powerful. Technically, you have way more power available in your smartwatch. Still, microcontrollers are extremely useful. Even if they're processing power and memory capabilities are limited. A great deal can be done with these little guys. And this is what we are discussing. And in the coming lessons, it would be more clear why we are introducing microcontrollers and what it has to do with micro Python. That's it for this lesson. Thanks for watching. This is.
7. 7 Why MicroPython: Hello and welcome to this new lesson. Now, let's talk about why micro Python. Now. To begin with, first, the language is more accessible to beginners than competing languages. While still being powerful enough. For industrial use cases. You can go from learning the basics to doing real work and quickly. Second, Python allows for rapid feedback. This is because you can interactively enter commands and get a response using the EPR. Also, you can't, you could even tweak your code and run it right away, rather than iterating through code combined, upload, execute cycle. Last, they're worth of Python code and experience out there means that you can do some things more quickly and easily. As a Python programmer, I find that Python requests library string handling and tools for dealing with JSON. Much easier to use in the micro Python world than C Plus Plus for example. So all of these reasons compliant are why we are teaching you micro Python and why we are talking about it in the first place. So I'm sure that will add a lot to your already available knowledge and programming. And it will be easy to transfer your code into micro Python. Thanks for watching this lesson. This is Ashraf.
8. 8 Difference Between MicroPython and Other Programming languages: The differences between micro Python and other programming languages. What about C plus plus? C plus plus is fast, compact and available everywhere. There are tons of C Plus Plus programmers out there. And LH community of Arduino and pick developers and ready to help you. In my opinion, microbiome be seamless and glass in ease of use and convenience. Psi-blast sublist syntax is not as easy to understand right away. What's more? The code needs to be compiled and then transfer to your board before you can get a result. So you need a compiler handy. Now, obviously the tools are getting better. But micro Python still has the advantage. While seamlessly blast may have a speed advantage. Micro Python is fast enough for most purposes. Beside, if you are, if you really need C plus plus, then you can even call your C plus plus code from Michael Python. Now, let's talk about another language. What about assembler? For drove performance? There is no beating. A simpler. However, that doesn't rule out micro Python either. Again, micro Python tends to be plenty fast enough. If you do need that lowest level power, then you can add inline or simpler as to your microbe python projects. What about Raspberry Pi? Raspberry Pi, which runs python, is also heavily present education. It's found an edge in electronics and physical computing thanks to its general purpose input output pins. The Raspberry Pi is also a fully fledged general purpose Linux desktop computer. It has lots of superpower, memory and storage capacity, and it even has a GPU. However, that last aspect can actually be a reason not to choose the pie and go for a microcontroller board. And instead, then I will just run this clip. Applications and multimedia is fantastic, especially when your project might need that rho power. This might be the case for AI, video streams and database projects, for example. But this can cause problems when you work on your use. Case requires real-time processing. If you need very precious timing, then you don't want your code to eight while it's it catch hub with dozens of different processes that all one to execute at the same time. Which is, in this case the operating system tasks if you want alone or let's say if you want analog and port, then the PI would require additional hardware. In contrast, most nitrogen through honors capable of running micro Python have at least one analog. And maybe even more. In addition, the pie is not quite as robust and it can be more expensive. Because of this, it might make more financial sense to leave our microcontroller in your project rather than a whole pie. You don't have to choose one or the other. Perhaps pairing a Raspberry Pi with our microcontroller is the best solution for your project. For instance, you could use the pie for processing power and the microcontroller to interface the hardware. Most people do that. And the interface Raspberry Pi with pec major controller or with Arduino board. And there are already a lot of libraries that support that. And it will make your life much easier. Again, the Raspberry Pi is in just a microcontroller. It's a whole operating or a fully functional operating system device that can handle all of these processes, can allow video streams and a lot of other things. Now, what about basic? If you were to switch on one of those all microcontrollers from back in the day, then they would almost certainly have booted into basic. And the very least, they would have had a dialect of basic on hand. Today. The shine of basic has DLD, somewhat. Python and other block-based languages have replaced it in educational spaces. And it hardly makes a dent in the tech industry. Python has all the advantages of basic, with none over the limitations. This language served as Introduction to Programming for a whole generation. In the next lesson, we are going to discuss in the micro Python hardware. But as of now, I think that you know why we're choosing micro Python to go with in this course. Thanks for watching this lesson. This is Ashraf.
9. 9 MicroPython Hardware: Micro Python hardware. If you're interested in giving micro Python at REI, then that's great. You will need some compatible hardware to uninstall micro Python onto. Fortunately, there are many options ranging from affordable, premium products. There is something for every wallet and use case. So take some time to choose best solution that's right for you. In this lecture, we are going to show you the different options available. And the one that's right for you. This is for you to decide. Now, let's get started. The first option that we have here is that pi bolt. It's one of the most well-specified boards. It's based on the STM 32 and has lots of general-purpose input outputs. And there is also an SD card slot, as you can see here. This slot, there is also an accidental meantime. And RTC with our capability of a 168 megahertz. If you can't find it in stock, then it'll cost you around $40. And as you can see, it has a very simple design and it will get the job done. Now, the second option, the ESP 32 or ESP 82, 66. And the other end of the Apply Scale, our boards based on the ESP 82, 66. These balls only have one analog input. There aren't as many pins as the pi board. They do have Wi-Fi capability, which is a very important thing. You can find them in breadboard friendly boards such as the anode. I'm seeing you for $10 or less. And it's a very interesting bold and we already have more than one course in which we discuss this board. They SB 32, increase their power and capabilities while adding new tools to the feature set. For us mere a small additional cost. The ISPs 32 is that big brother to the ESP 82, 66. One of the best versions of these balls is that m5 stack. This unit comes with obesity speaker, a battery, a card reader, and our color screen. Now, another option is the BBC Micro bit. There Micro bit is our compact board based around the Nordic NRF 51822, which is basically our microcontroller. It has built n Bluetooth and E, and temperature sensing plus an accelerometer. Couple of action buttons and a five-by-five lead grid. And you can see the letter grade right here. Here we have two buttons. And all of these are for testing. If you are in the UK, then you might already have one of these boards. Lots of walls inspired by the micro bit are being, or let's say beginning to appear. So its bond to increase n popularity. They were distributed to all school children in the hubs of inspiring a new generation of coders. Now under fruit produce a fork vehicle circuit Python. However, there are a few main differences between the two. Circuit Python offers support for the other foot range of hardware. Plus the fact that most other fruit implementations future the board appearing as a USB connected drive. In these cases, adding your code is as simple as dragging it this thick, or let's say to their desk inside this ball. The most feature-rich bald of the Adafruit premium line up is down, circuit, playground express, google. It, it has an optional cricket add-on. When you combine these two balls, you will have pins, sensors, motors, live, Rs, RGB lands, and much more. If you are looking for an all in one solution, then visit that one to check out. Unfortunately, Adafruit has dropped computability with the ESP 82 66, even fall there on ESP 82 66 based feather board. Instead, they have chosen to go with the ESP 32 purely as a Wi-Fi core processor in future releases. Now, among these hardware that we have, Sean in this lecture, I think that the most convenient one is the Micro bit bored. But since it's not available in a wide range, you can go with the ESP 32 as a microcontroller and as a micro Python distinct environment. We'll use ESP 32 in a lot of our projects. So moving to micro Python with this ball will be very easy. Now it's also used for Internet of Things and home automation projects. So it will be our win-win situation when you choose the sport. It's also affordable, so you can buy it for like 10, 15 or $1. That's it for this lesson. If you have any question, please ask in that way. And the ball, if you didn't yet choose the board that fits your need, you can robots a question and we can help you depending on your project specifications. That's it. This is Asherah.
10. 10 MicroPython Workflow Serial Interface: Hello and welcome to this new lesson in which we are going to discuss micro Python workflow. If you are familiar with Arduino or pick maximum trial programming, then you might expect to talk first about compilers, development environments, and the toolchain. However, micro Python is a little different at first glance. Now, our PR with micro Python. As with Python, the language may have come with your hardware and you have the option of working with it interactively. And this is known as REPL. Now, there are two ways to get an interactive session, either by using serial terminal connection or by using the web REPL. Now, if you have chosen to go with that serial terminal connection, this is often done through the command line or perhaps an IDE, which we will discuss later. While if you went and choose the web are EPL and this is an option for boards that have a WiFi built end to make sure that your board is connected to the Internet and you can access this ball using the web, our PMF now, in the Metropolitan Python work flow to get a serial REPL on a Mac, for example, you can't run that included 10 our program Screen, and specify your device and the baud rate. As you can see using the shell on Mac, you can apply this command screen device. And this is basically specifying the USB serial FOR YOU device. And the blue number is the baud rate for the serial communication. And you can directly start the serial REPL. Now, it's a different case scenario. You can find your device by listing that dashed Sierra connections. Sometimes you might find it really difficult to find your selected device or the device that you want to use and to which you ask people it's connected. So you can't line this list command LS stands for list device TTY, and it will list all the devices. Then you can go back to this command and run it by writing the device number right here. So TTY device now in Windows, it's easier. You can simply right-click on the Windows logo and the start menu and select Device Manager to know which of the USB ports is configured for your boards. Now, this process is similar to what you would do in the Linux terminal or Windows. Potty is a popular terminal app. There is also one called theorem. Theorem. You can Google both of them. Either way. Simply connect to that component that appears when you attach your device and select that a 115,200 as your baud rates. Once you have RDP connection, you can enter commands just like you would from your Python interactive session. In micro Python, this interface is also where you might want to do symbol overlay think systems style works such as deleting files, all creating folders. So it's basically a command line interfacing using simple lines like ls and delete, add, etc. Now, the command line tools are basically a great way to interact with your micro Python board. There is a great command line tool for interacting with micro Python boards called AMP. This was initially developed by Adafruit, but has now been taken on by a community member. Since Adafruit is focusing solely on their own hardware and developing software for their own hardware. They haven't pay much attention for this tool. And now that it has been taken by someone else, it's being developed to regularly. And you can simply look up for this. And p or ARM Pi lingo will and download that tool. Now, in the next lesson, we are going to talk about the IDEs for micro Python workflow. That's it for the first lesson, the first section in which we cover the serial terminal and how you can interact with your micro Python bald using the serial monitor or OT. I'm P and other software. It's as simple as writing assembly line of code and executing it directly with your ball, connect to your device. Without us, Linux, Mac, or Windows operating system. We will talk more practically in the coming sections, but that's what you need to know for now. Thanks for sharing. This is Ashraf.
11. 11 MicroPython Workflow IDE: Micro Python workflow. Now let's talk about micro Python IDEs. There is a pie chart and blog in that adds micro Python support your IDE. Now, PyCharm is a very popular programming software and it's mainly used for Python programming. It's available right in that plug-in marketplace. And you can add them micro Python support to that. Very sophisticated and let's say efficient software for the micro bit and circuit Python boards. The best editor right now is the more elite or amu. The data from Nicholas told every otherwise keep an eye on the u pi craft, which looks to have a lot of promise and is already pretty useful. Now, this is basically the pie chart marketplace. You can look up for micro Python and install it. I will show you that in a minute. Now, as you can see here, in the UK, Pi craft, you can simply go to the Tools Serial and select your pie or micro Python. But once you have connected the correct serial port and selected your device type, you'll be able to browse the device. Your device type will either be ESP 82, 66, yes, be 32 or micro bit. Now you can interact in the REPL. Now, let me show you that micro or the PyCharm software and how easy it is to the micro Python to it. We will have assimilated section for downloading and installing the software. But let's do a quick overview for pie chart. Now, right, pie chart using the Start menu. As you can see, I have the 2020 version. Now what you need to do is simply to download or install any new plugin. You need to go to the marketplace.
12. 12 Creat and Deploy Code using IDE: Hello and welcome to this new lesson in which we are going to talk about sitting up micro Python on your ball. Now, there is one benefit choosing your pie craft, which is an IDE that we recommended in the previous lessons. And thus the option to easily bear and the micro Python firmware tool ball without having to use command line tools. Now, to go and download your craft, you have to open up your browser. Now, bite you pie crust. As you can see, we have this option in the soil. You pi craft IDE. Now to find the download, you can easily download your pie craft IDE. Now you have more than one option. You can go to the GitHub link directly. And here we have the u pi craft. As you can see, we have more than one file and we have more than one version. As you can see, this is the version one for Windows. You can choose your operating system, Windows, Linux, and other operating systems. Now, you can simply go and download the last version. And as you can see here, we have version 1 dot EXE, click once, and you can download the file. As you can see, it's about 13 megabytes. Now click Open File. Click, Okay. And as you can see here we have a two u pi craft version 1. This is fine when you edit tools help. Now, let's proceed. Now. You can choose your pie craft default firmware, or a fair where you have downloaded the BBC Micro bit shows up as a disk drive. So if we went back to Berlin firmware option and the software will keep going back and forth. Now there's a new version available for you. Pie graph would you like to upgrade? Click OK. Could download the new version. And in solid in your system. You should always check for updates to make sure that you have the latest version. Okay. Now, click Okay. Let's hear that there's more than one version and there is example that you can download and add to your software. Okay, going back, now we have the software. As you can see, we have more than one file edit tools. We have the barren firmware option. Once you select this, you can see that we have more than one option. Here. We can select the board type. We have ESP feta two, we have micro bit, and we have ESP 82, 66. Now, if you have selected Michael bit, you need to make sure that you have the right COM port. I don't have any more connected right now. But if you want to know the exact home board, go to the Start menu, right-click, choose Device Manager. And from here you can see the pores and you can know exactly which compose your balls connected to. And you can't change it. You must change this to match what you have here. Now, you can choose the UPI craft default firmware by selecting this and it's already selected, or a framework that you have downloaded. And you can choose the location of the framework that you have downloaded. Now, since I haven't downloaded and iframe where I will go with the firmware Firmware default choice. And that BBC Micro bit will show up. And this one will show up as our life. We use amu or the wood-based it at all. They'll produce files that you can't drop straight onto that disk, which is the Micro bit desk. And usually the disk will show up on my computer. And your Windows device. If you are using the ESP 32 or ESP 82 66 board with your PI craft. Then you can also install the Python ESP tool with pip and setup your boards framework or firmware using that. Now, the easiest option, we already mentioned that the baseball and it's available everywhere is that USP 32. Now you can simply select this port, make sure the borders right and select Okay. And it will start uploading the firmware for micro Python. Now, let's move on. You can use your IDE and this can be a mu u pi craft or something similar. And we just explained Diu Pi cloud IDE. You can use a command line tool. This can be our shell MPI or something similar to execute your code. In most cases you are going to create a dot py text files and execute them on your micro Python device. This process is similar to what you would do with C Python. You will transfer the files to your Borg in one of two ways. And we already mentioned that two ways here. To use your IDE or to use a command line tool. Now, in the coming lectures, we are going to explain the coding process, how to write a symbol called and how to interact with your board and upload this code to your board. The bond that we are going to use for the practical section which will come next is the ESP 32. And the same thing applies for any other board that you have. Until now we are talking theoretically, but we are starting to exit plan things in a practical manner. Make sure that you have Diu Pi software IDE installed in your system using the steps that we just mentioned. Thanks for watching this lesson. If you have any question, I'm here to help you. This is Ashley.
13. 13 Your First Code: Hello and welcome to the senior. Soon, it'll Schar going to talk about there are micro Python bootup process. Now, when devices that are running micro Python boot up, they look for a file called Booth dot py. If that fine is found, then the device will execute that file automatically. You can also execute dot py files from art, EPL, trumpet. Like execute, open my programmed by D3. Now, let's talk about how to write your micro Python called or your first micro Python code. You will start with a traditional HelloWorld project. You can do this and the REPL by connecting to the correct serial port and entering the following commands. First, you need to interact Clinton tallow worth. And you should see the following output when you run your first command. If this is the result, then you have confirmed that your setup is working. Now to this town that print command that we just mentioned. We need to connect, abort. And we need to make sure that we are updating the firmware of that pole. And in our case, I'm going to connect ASP 32 board and upload the firmware, which is your Pi craft firmer. Now, the code that we are going to execute is that print HelloWorld code, which is a very simple cold.
14. 14 Connect Board and Update Firmware: Now, the code that we are going to execute is that print helloworld code, which is a very simple code. Let's first connect our bold. Now I have connected my ESP V2 ball. Let's go to the Device Manager. Right-click on the start menu and select Device Manager. Now in here you will see that I have the U S P two hours bridge outcome 5, which is basically the cobalt 2, which my ESP 32 board is connected. Now before moving on, we need to go to the micro Python website. As you can see, micro Python, that's all downloads slash ESP third 22. And we need to download the latest version of the firmware. Now to get the firmware, we need to look for the standard firmware section. And as you can see, we have more than one board, as here, the pi bond, thus the 32 board, the IT, the ESP balls. Now Labov that we are using is ESP fail to 2 module. Now, as you can see, this is the ESP 32. And here we have the firm. Where were they? Esp IVF, three-point x. Now, if you don't know what to use, simply go with a 3 x. And here we have more than one generic. And this is version 1.13, which is the version, as you can see, it starts with 1 10. Click once, and now you have it in the downloads. Let's move it to the course folder. Here. Let's add inside the code folder. And let's make sure that we have the click. Okay, click Download. Now we have it here. Now you need to go to the u pi crafts software. Go to the Tools, select the serial port, which is 15. Now, if you'll face a problem like this, could not open port 25. Permission error 13, access is denied. You need to disconnect your ball and reconnected. Now to do that, simply disconnected and the hardware and enact it again. Now. Now after doing this, you need to go to the Tools and go to bold and make sure that ESP 32 is selected. Now, the next step is simply go to the Tools bear and firmware. Go here, select ESP 32. And that burn address is 0 x 1, 0, 0, 0, 0, 0, 0. Yes, arrays. And that comport here, select user, choose the location for your phi. What should this file? Now? Click, Okay. Now as you can see, it's erasing the flash memory. For our ESP 32 board. If you got stuck, you might need to click on the button on your board, which is the Enable button. As you can see now it's burning that firmware. For the ESP 32 micro Python. Again, you need to make sure that you have downloaded the right File and you have selected that USP 32 board, the right come on board. That yes to the Erase option and the barren address, which is 0 x 1, 0, 0, 0, 0. Now, after doing this and having all of this sittings selected, you need to hold down the boot flash button on your ESP theta2 ball and process will start and finish correctly. Now, you need to note if the areas or flash bar does not move and you see an error message saying it is false. It means that your ESP 32 wasn't in a flashing mood. You need to repeat all the steps described earlier and hold the boot flash button again to ensure the ESP filter 2 goes into flashing want. Now without placing your board and the flashing mode, you'll press hard time knowing exactly what's going on. Now, again, we have updated the firmware for our ESP 32 bar, and we have everything ready for our next step. But that's it for this lesson. In the next lesson we are going to test that print HelloWorld example. Thanks for watching this is Ashraf.
15. 15 Blink Led Practical Example: Now let's start with a very simple example, which is the HelloWorld example. You will start with a traditional HelloWorld project. You can do this in the REPL by connecting to the correct serial ball and entering the following. Now, we are unknown that we have connected to come five and we have everything ready. So simply click here and the Connect icon. And once you have connected, you will see that the device mooc dot py file is here. Now, write print, Hello World. Okay, So right. Now simply hit Enter, as you can see, it did respond with HelloWorld. Now, if you didn't see the following, you confirm that your setup is working. Now let's create a more advanced example. Let's create a digital output example. Let's change the output type using the following code that while going to write, you can make the onboard LED blink. The first thing that we need to do in order to do this is to import time, which lets you insert time delays. So let's write this down on Sublime editor. So the first thing that we need to do here and the lighting use Sublime editor because it's bigger, is impulse time. Now this is Sublime Text Editor. You can get it and you can use it to write chords and the language. Now, I will select Python here to make sure that we have colors. Now, you can also import machine, which is a module that gives you easy access to the input output pins on your board. So write impulse machine. Now, you use this module to setup an object called blue LED, which you define as being pen too, which is on the other boards. It may be possible pin 16, all depending on the bolt that you have. Then you sit it as an output pin. And to do this, simply write blue LEDS equals machine. Then. And in here, you need to write two machine, Penn dot out. Now to make this LED blink, we can add a for loop. Let's say that we wanted to blink 20 times. Let's add a for I in range one to 20, or let's say the 21. And in this for loop, what we need to do is symbol. We need to add a tab here, right? Glue lens that value. We will send that value to this blue LED, which will be 0. Then we will use the time that sleep function to turn this lid off for 2.5th. We will repeat this step and write newlyweds, sorry, that value. And we will send one to turn the LED on. We will use Time dot sleep again and make it make a day or 2.5th. Once we are done, we can go back and print link lead donor. That certain, this is our code. Let's explain it one more time. They impose time is basically, let's you and serve time delays. And the machine is a module that gives you easy access to an input, output pins on your ball. And you use this module to stop an object right here called blue LEDS. What you define as being pen tool. On other boards, night be PIN 14 or any other number. Then you sit it as output here. You should execute this code, and once you execute it, you should get our result. Now let's copy the code and go back to our software, you pi. Now, let's create a new file. And in here, Let's paste our code. And this is our code, as you can see. It's an colors and it's recognized as a Python code. Now, let's save it. Now click File. Save As, and let's call it length lid. Click Save. Now, what we need to do is go and click Save, save As. And here, write a blink. Led click. Okay. Now to save this file that we just return, you need to click Save. And if you want to download and run a file, you can simply click this icon. Now once you save the file, using the file Save, you can easily go to the tools and hit the download and run, which is a F5. Now as you can see how this will download the file, please wait. Download. Okay. And as you can see, the file is downloaded. Now we have it here. Plank lead the pie. And you can simply run the file by simply, I go to the run. Now, when you click Run and download undrawn, as you can see, we have an error, which is, the download is okay, but we have an error. And here we have a syntax error. We correct it by adding these two dots. Click Run downloads. Okay, now it's executing this file and the LED is blinking on and off, and everything is working just fine. Now, once the lead stops blinking, you will see that we have the print plane click Done sentence. And as you can see, blink LED done. This is the first example. And as you can see, it's working just fine. Thanks for watching this lesson. Make sure that you apply this example before moving on to another one that's washing. This is Ashraf.
16. 16 Led Fading Example: Hello and welcome to the senior lesson and we're going to plan the second example. What if you don't have a built-in LED? All you want to light up a lead that's not on your ball. You will need a suitable size resistor, such as a 220 ohm resistor. And you will need to connect that to the ground and to the short leg. Fewer glut. The positive long lid of your LED will connect to the general purpose input, output pin numbers 2. Now on that, we must D1 on our board. General purpose input, output pin number two is called digital pen line. On the front face of the board, it has done general purpose input, output number underneath. Now in the case of an, a, an external lend, it will light up when the value is one or on. Now. What if we want to fade a lead, which is the thing that we are going to obtain in this examples or in today's example. In the previous example, we used a for loop, but our hard work can actually blink the LED itself. To do this, you can't sit the pen output as PWM, which stands for pulse width modulation. And we already have a course about that. This allows you to create a signal of on and off pulses. When you turn the LED on and off very quickly, many times a second, it appears that the lid is set to ascertain politeness due to how our eyes work. And this course is not about PWM, but you need to know that pwm is a way for you to control the brightness starting from 0 and up to a 100 percent. Now, how this code works and how you can write this code, you can simply go, Let's go to the previous cones, and let's save it. Click File Save As. And let's say within the same page. First example, blink LED. Now let's create a new example here. First. And this new code, we need to set the brightness and the blink frequency in hertz and let the hardware take over. Now, we can also use PWM to fair dial it in and out. But first let's test this out. First, we need to import from machine, import thin. And again, change the syntax to Python. Again here from machine and port PWM. And we need to import time. Now time is for delay, pin is for hardware configuration. Pwm is for controlling the brightness. Now, but I PWM, which is an object. And make it equal BWM for Penn too. Now, that brightness is freely between 0123. So like PWM, duty, which is basically the duty cycle and rights have been a 100 or do you Karl I TO a 112, but it will be about 15 percent brightness. And then choose the frequency. We need it to light at a frequency of one hertz. That's it. This is the frequency in hertz. This is the brightness between 0123 and this is the PWM pin. Now, on what you need to do is select all copy and go to your software. Now let's serve. Make sure that everything is served. Now create a new file. Paste your chord. Hit Save, and let's call it weird ones. Now click Okay. And here it is. Now click Download. And around. Now all it is a download this file. And as you can see, downloads, okay, fed ones is being executed at a baud rate of duty or 512. Now you can reduce this to 0 and click run again. And you will see that the LED is off. Now let me show you this in action. Now. I'm executing that 0 due to cycle. Now let's increase this to 123. Click download and run. You will see that the LED will turn on at full brightness. Now let's change this to a 100. Click on download and run. Now, you will see that the LED brightness is a little bit. The margin. And connecting and external lid will show you this in a way much clear on what we're much clear way. So make sure that you woke up on external lead to see the fed in and out effect. Now, in the next lesson, we are going to improve this example. And the fade in and fade out effect to the sleds. That's it for this lesson. Thanks for watching. This is Ashley.
17. 17 Fading an LED In and Out: Hello and welcome to this new lesson, NO char gong to improve our previous example. Now, you can also PWM to fade or use PWM to fare the lid in and out. Using the very same code. Let's first save this code. This code is called, Let's save it. And let's call it, call it fed example. Now let's copy the same called, open up a new file. Here, we will leave that very same initials. We will import the same libraries. We will initialize an object called PWM, and the frequency will be more here. And let's make it a 100 on 90 depending on your preferences. It, let's make it a 100 hertz. Now. Let's start by adding an infinite loop. Let's call it Y1. Now. Brightness, let's say that we want a brightness to go up from 0 to 1, 0, 0, 0, 0, guanine 3. We will use a Ford. And let's call it Clyde in range. And let's add the range 0 to 123 and a 100. Now PWM DOT. And this will take as input. And now after doing this, let's print the uprightness. And let's add a delay, time to sleep, 0.1. Now, we will do, we have to move this inside the for loop. And we will write a similar loop for I in range. But this time we will change from 1230 minus a 100 points step. Now, PWM, new t. We will write bright and we will blend the brightness. And the last tip is time that sleep. And here 0.1. This is our code. Now, let's save it. Let's call it fed in and out. Now select all copy and go here to our coding area. Save this file, create a new file. Paste your code here. Now once you paste your code, simply click File Save and save it with fed. And out. Now click Okay, and click, download and run. Now before clicking download and run, let me make sure that we have that yes people. Okay, now I'll click download and run downwards. Okay? And as you can see that politeness is increasing and decreasing from 0 to 1000 by three. Then again, you can see going up and down. And as you can see, the numbers on the display are reflecting these values. That's it. This is how you can easily fit in and out eyelid using micro Python and ESP 32 board. Thanks for watching this. If you have any question, please ask. And if you're on the board, this is Ashraf.
18. 17 1 General board control: Hello and welcome to this new lesson in which we are going to discuss the general board control for the ESP 32 using micro Python coding. Now there are micro Python REPL is on URLs. General purpose input output one is the TX. General purpose input, output three is the RX at baud rate of a 115,200. And now to get started, we will use something called Machine module. Now the first thing that you need to do in your core board is light import machine. Now this is a very important Could you, you can use it for example, to get the current frequency of the CPU by lighting machine, dot frequency. You can also use it to sit the CPU frequency to, let's say, 240 megahertz by simply writing machine dot frequency. Now this is basically very important library. And sitting there, if the frequency is very great functions, if you have a low-power application, you shouldn't run your ESP at a very high frequency because this will consume a lot of power. So you can sit it to our very lovely frequency. Now if want to split 200 to 240 megahertz, we have to write 240. And since this function takes hertz, we have to convert that to a 142 from megahertz to hers by multiplying the number with 1 million. So 1231236 zeros. And to a 140, this is 240 megahertz. Now, the second rule you will that we are going to discuss is the ESP module. And simply write import ESP. Now, this module is a very important module as well. You can turn off vendor Windows operating system debugging messages by simply writing ESP dot or us debug. And here you can write none. And you cut a direct Windows operating system debugging messages to the US by simply writing ESP dot or US debugging. And here you can't slides here. Now if you want to use some low-level methods to end up back with flash storage. You can simply write ASP dot flash size. And this will turn the size of flash memory of your BS people. Now, if you want to start flashing, you can simply write ASP dot slash users. Then start. And this will start the flashing process. And if you want to erase the flash memory, you can't simply write it as p dot slash underscore. There is between the two parentheses you paralyze sector number and sixth row number here is the sector number which you want to erase. And you can start with sectoral 0, 1, 2, and the bending your ESP bore. You can check the data sheet to see how many sectors your flash memory has. Now you can also write and read using the ESP function. So to write data, you can simply write ESP dot flashlight. And the first thing that through tick is the byte offset and then the buffer. And basically this is how Dr. data to help us be flash memory. Now to read, you can do the very same thing, but ESP dot luxury. And from there you have byte, byte offset buffer. And this is how to read from your flash memory inside your ESP ball. Now, another important module is the ESP 32 module. You can write import, yes, 32. And to read that internal halls and solve value, you can simply write USP 32 dot hall sensor. And as you know, the USBE board has internal hall effect sensor. So you can read the value for the heart and that hole is fixed. And so using this method, method directly. And you can also read that Enbridge all of their microcontroller in Fahrenheit using the internal temperature sensor by writing ESP 30 to dot or more richer. And this will read then turn on the temperature of the microcontroller and Fahrenheit. Now, if you want to access the ultra low-power core processor, you can do that using one line. And this is how simple it is to use micro Python. You can write your LP and that's it. Now, this ultra low-power corporis is, are very important mood for ESBL. So to board because it helps minimizing the amount of power this ball is using when it's not doing a heavy duty functions. And now you need to know that that temperatures, so the ESP fell to two. We'll typically read higher than on piano due to the IC and getting Quan while it runs. This effect can be minimized by reading a template Charlson score immediately after working up from sleep. So that will give you high temperatures because they sp3 two to ten to get hot when it's running or it's operating. So these values are not really reliable because operating temperature is usually high for ESPN bush. And avoid this, you can read the temperature when ESBL to, to board goes to sleep. And once it works, our Bukhara read the current temperature. That's it for the three main general board control libraries and the machine speed SB 32. We talked about some of the functions that each of them have, but each of them has, but there are other functions that are available and you can check them out. I'll try to provide documentation for everything. Thanks for watching this lesson. If you have any question, please ask in the calendar ball.
19. 17 2 Timers and Delay: Hello and welcome this in unison. And no two are going to talk about delay and timing and timers n micro Python. Now, to use time module, you need to write import time. Now after that, if you want to sleep for 1 second, like time don't sleep for one. And this will add a delay of funds like I'm now a few on to add a delay of 500 milliseconds, simply like Bim dot sleep, underscore unless and buy at 500. And this is 500 milliseconds. Now, if you want to sleep for, let's say, microseconds, simply add this ten. And this is microseconds. So, and as four milliseconds us four microseconds. And if you want to get millisecond counter, you can simply get a variable, let's call it starts and trying to fix MS. And while this will do is get millisecond counter. So to start counting and milliseconds and install the counting result and the start variable. Now the second thing is if you want to compute that time difference, you can simply write a new variable. Let's call it delta equals time, the ticks, difference. And open two parentheses inside. Then you need to write time. The ticks. Unless. And after doing that, we need to find the difference between this, that current time and start or choose the variable that we have here. And this will return time difference between these two, this one and a current decks in milliseconds. So basically the most used function, or functions are these three. Sleeping for a second, sleeping for 500 milliseconds, living for ten microseconds. You must use these in your software or in your coding to give your ESP bald time to stabilize. Now, the SP five to 20 port has for hardware timers and you can't use the machine the time our class with a timer ID from 0 to three. Now, for using this, you must first import soil, must write from machine. Import dialog. After doing this too, we already mentioned that we have for hardware timers, we can address them by 0123. And to address them, what you need to do is simply write time 0, which is a variable, equals times 0, which is the first time or the first of the fourth timeless. Now if you want to initialize it, you can do that by initializing in that time our specifications. And usually this is done using the time 0, which is the timeout. Don't initialize. And this is basically a function that takes three parameters. Now, it can take more postman than what you might imagine. But for our example, we are going to go with three inputs. The first one is that period. So the timeout period will equal five thousands. The second thing is the timer mode. So the mode equals, and there is more than one mode. The one that we are going to use here is time Aldo underscore shot. And this is the time. Now, as you can see, the Fair theme here is something called the cold bath. Now. Now, the cold bath is basically what the function will return. Now, we usually use something called lambda or lambda. The lambda function allows us to send specific data to the callback function. And in our case, we are going to send the data using that Paul dark and y column. Now the t here is basically what this will return. It will return 0. So it will print 0 serial monitor. So this is our time, our 0 initializing function. And as you can see, the default thing is for the operationalization is to write a frequency, a pre scalar, the period, and we started with a period. So these will be set to default and our example, and this is the period. And we said that the 5000, the wound timeout, uptime or down one shot, two shots. And that division, we ignore this. Now. Once you ignore it, it will be set to default. And here it is sets and the callback here is none. So it will tear nothing. In our example, it will print 0 and that at time equals 0, that it is set to default and our time 0, 0. Now the same thing applies if you want to define another time or as we already mentioned, we have four timers. To either stress I can timeout right time or one more time, one and time are one. And in here, right time, one, initialize. And inside it, you must drive that very same thing. You write, period equals, let's see, 2000s. Moods equals timeout. Your deck. And a callback equals lambda t, one, which shows them all on. And then this is a periodic moons and this is the one short mode. The period is different by 1000 and 2000. And the callback function or material, one, I still footprint 0. And you can use the third, fourth timer. As I mentioned, the period is in milliseconds. And visual timers are not currently supported on this port. So you have to use these hardware timers if you want timeouts inside your application. Thanks for watching this lesson. If you have any question about time up or timing, how to add a delay here to help? This is Ashraf.
20. 17 3 Pins and GPIO: Hello and welcome to this new lesson in which we are going to discuss the pins and John purpose input, output inside the sp3. Do. Now, in order for us to deal with pens on your ESP theta2 bald, you need to use the machine, that pen. And to call it first, you need to write Islam machine and port. Okay? Now to make sure that you can't see this and colors, Let's select Python. Now we are importing machine class from the BSP 32 micro Python libraries. And we are calling the pen class, which is inside the machine. Now, the first thing that you can do is to create our pen on a specific general purpose input output. And let's say for this example, we want to address shall purpose input, output pin 0. So this will equal p, variable will equal 0. Then Pindar out. That's it. Now to set a pin on, which is a high level. Just write p dot on. Now to sit pen, to. Just write p 0, which is the variable dot off. Now, to sit pen tool, you can simply send one to that ben Maya writing a value. So it will give you the same result. This one now put together and put pen on this session verbose output pin numbers tool, simply create a valuable and make it equal. And said that then number, we want either style, purpose input, output pin number two, an ESP fail to board. So here we would like to. And you must write pen dot n, which is n. Now target value either 0 or one and print it out on the serial monitor or from the console assembly plant p2 and go to value. And this will return the value that's coming on in number 2, which shows the sharp verbal input output pin. So if you connected this pin button and press the button, it will print one. Fun press the button and send 0 depending on the connection of that button. Now, as you know, SP3, SP2 also has internal pull up resistors to enable them simply blight before, which is another variable. Use the pen function inside the thrived for n number. And sit that pins as input. After doing that symbolized pen up, which will turn on the internal pull up resistors. Now to sit pin high on passion on what you need to do is write P50 equals n. And as you can see, the pen function has a lot of parameters, so forth can take different parameters and it's up to you to use them. Now we will address pinned them five. And we will sit it as output plan. And we will send a value of one, which will basically SIP. And I'm five as output pin and 10 dot pin soil phyllosilicate connect it to this pin. This LED will be now available. Pins are from this one's ranges from 0 to 19, 21 to 23, 25, 27, 30 to 39. And it's basically depends on your ball. So you must go and check out your data sheets. Now these correspond to the actual shower purpose input, output pin number of the ESP fair to T2 chip. Note that many in the user wants use their own talk numbering. The 0 D1, the tool for mapping between closure colored pens and physical chip pens. You must go to your board documentation. So on if our address pens like this, you must know for sure that the pen that you're addressing is actually the first pen or the second bin, the fourth pen, all the fifth. And it will also reflect on your connection. Now, few things that you might need to log is that Penn num 13 on our EPL, TX and RX. So you can't simply use them for the serial communication. Pins Number 6, 7, 8, 11, 16, and 17 are used for connecting the movie that flash and are not recommended for other uses. Pin number 34 and 39, and here we are only speaking about ESP 52, our input. And also do not have internal pull up resistors. The value of some bins can be set to 10. The phone hold to reduce power consumption during deep sleep. So if you want to reduce power consumption during deep sleep, you can execute pen. Let's say that you own and the rest the same pin. Number four. P4 will equal pen for Penn and how to place it and the whole horde mode. Since then. Don't pull a 100 score halt. And this will hold the pen and it will reduce the ball consumption. And you should only execute this when you are going to DeepSpeed and make sure that this is connected to an interrupt or a timer. Now, you don't want to hold the pen forever. So if you place this line, let's say anywhere in your code, without knowing what you're doing, It will hold your pen and it won't receive anything. So make sure to execute it. When you're bored, goes through deep sleep. That's it for how to other pens and general purpose input, output. Inside. Esp says to ball to using micro Python. If you have any questions, I'm here to help you transferring this is Ashraf.
21. 17 4 PWM: And let me welcome to this new lesson in which we are going to talk about PWM and how you can use such signals with your bolt. Now, PWM can be enabled on all output enable pens that wistful Clancy caravans from one hertz to 40 megahertz. But there is a trail off. As the base frequency increases, that duty resolution decreases. And I won't go into details explaining what is PWM. But you can refer to Google to look it up. I will add some resources if you don't know anything about PWM. But basically we have the arm is a way to control an output. In arrange other than just 05 volts, you can send one fold, two-fold, three-fold, and control the uprightness, overlays, etc. Now, currently the duty cycle has to be in the range of 0 and 1, 0, 0, 0, 0, 3. Now, the first step that you need to do is import the machine. To call it the PWM. From the machine library. We will import pen and PWM libraries. Now channel that syntax to Python. Now to create a PWM object from pin. Just like PWM 0, which is our name of our variable, equals PWM. And inside it's like pin 0. Now this will create a PWM object called PWM 0 on 1000, which is general purpose input output pins Europe. Now after doing this type PWM 0, and this stands for frequency to get the current frequency of w. Now, if you want to set the PWM frequency symbolized PWM 0310. And insights by, let's say 1000. And this is how to set the frequency. This is how could get it and you can print it. Now, the next step is how to get and set the duty cycle PWM 0. Duty in the function that you can use to get the duty cycle. Now simply write blend. And this will trend that you decide kill for your PWM signal. Now to set the duty cycles and derived PWM dot UT. And let's say 200. Now, the last thing that you can do is to turn off PWM on the pen. And you can't seem to do that by writing the WMO, the D initialize. And by calling this function, you are turning off PWM on general purpose and without what Ben Lumber 0. Now, if you want to create a PWM signal on our pen using just one line without writing so many lines, you can simply do that by writing PWM. Let's say T2 equals PWM 10. And here you can say two frequency, let's say 20000. And that the UT equals 512. And this is how to create and configure in one goal. As you can see, her sponsor is the pin number. Then we have the frequency of the PWM signal. Then we have the duty of 512. So this line is more than enough to create a PWM signal on pin to this frequency and this duty cycle without having to write all these lines. Now this is how you can send PWM signal. And most likely you can use this to light and RDP pen or lead, or to control the brightness of assemble lead. That's it for the PWM or pulse width modulation Library. Thanks for watching this lesson. This is Ashraf.
22. 17 5 Analog to Digital Conversion: And on the left and the Simula sun in which we are going to discuss in the analog to digital conversion on ESP first tool using micro Python libraries. Now on the ESP 32, ADC functionality is available on Penn's 32 239. Note that when using the default configuration and what's the voltage on the analog to digital conversion pen must be between 010 volt and 1 volt. And a chain above 110 volt will just read as 4 thousand. And 95. Attention must be applied in order to increase this usable voltage range. Again. And I think about one fall will just read as 4000 95. And you must keep this in mind. Now to use the Ungroup digital conversion class, you need to call the machine library. Now strong machine and port ADC. Now to create An object and ADC object on ADC pen assembly, right? Adc equals ADC pen. And put them in number 38. Now, and this will create an ADC object called ADC on this pen, which is two. And we already mentioned that appends are from 32 to 39. Now, to read a value between 04,095 across voltage range of 0 to one volt. You can simply write ADC 23 ands. And that's it. Now you can store the value by writing analog value equals this. So the analog value will equal this. And this will read that value and solid here. Now, we didn't assign a pin number because we are using this object and this object is connected to pin number 32. Now, you can also change that input at the new machine, which will change the voltage range from 0 to one volt. And then voltage range 0 to 3.6 Paul. And to do this on what you need to do is simply write ADC. And inside that you have for ADC. Egn 11 dB, okay, sorry, 11 dB. And this will change the voltage range to 0 up to 3161. And instead of 0 to one volt, now, you've had to sit nine bit returning value, which will return a range between 0511. So somebody like ADC dot width inside it, you felt like ADC. It with underscore line the b. Okay, nine bit, sorry. Now this will change that attend value to 0 and up to 500. Elegant. Now, if you want to read value using the newly configured attenuation and width, simply call ADC read. And from there, you can store the value that you did to create our new variable. Let's call it analog value. So what's lovely? Fast print this one and this one. Well, this will read a voltage range between 01 fault. It will also give us our return value between 04 thousand 95. Wild guess these configurations chairs these values to 0 to 3.6 volts and 0 to 511. So the new value that we are going to read will be different. Now, ESP 32 specific ADC class methods has more than one difference. Now, we will discuss that this attenuation method and ADC width method. Now, just to get started, you need to learn that the ADC attenuation method, which is the best one, the one that we will discuss varus is basically a method that allows for the sitting of the amount of attenuation in the import of the ADC. This allows for a wider possible input voltage range. And that most of you are seeing the same number of bits now represents a wider range of possible attenuation options inside of these parentheses are as follows. There is that EBC. The attenuation and the score to 0 dB HL dB attenuation and gives a maximum input voltage of one volt. And this is the default configuration. So if you didn't add that enumeration, it will go with the default configuration, which is this one. Now, if you change this to two, underscore, five dB or 2.5 dB attenuation. It gives a maximum input voltage of approximately 1.34 volt. Now, if you change this to sex dB, six dB attenuation gives a maximum impulse voltage of approximately 20 volts. Now, the last option, which is the 11 dB, the 11 dB attenuation, which we already mentioned here. And give us a maximum input voltage of approximately 3.6 for now in this byte, 11 dB attenuation, allowing for up to 3.6 voltage range. Note that the absolute maximum voltage rating for that input tens is 3.6 volt. And so going near this boundary may be damaging to the IC. So always make sure that you keep this into consideration. Go, don't go to 316 balls. Keep a little distance from the highest value. Now, the next function that we are going to discuss is the ADC world function. Now the NDC with function allows for the city of number of bits to be used or utilized and return during ADC reads. Possible with options are the first one is nine bit. So you can simply implemented piping ADC. The width underscore, underscore line bits. Now this is our a nine bit of data and it will change the range. And the other option is thin bit. And tell us another option or shares 11 bit. The maximum option is 12 bit data, and this is the default configuration. Now in this demo configurations we'll visit will return 0 to 4,095. So you can choose the configurations depending on your envelope voltage or analog input voltage and the expected return and range for digital values. That's it for the analog to digital conversion using ESPs here to two and micro Python libraries. If you have any question, please ask. In the mandible. This is Ashraf.
23. 17 6 SPI Protocol: Hello and welcome to this new lesson in which we are going to talk about the software SPI bus. Now, that's software as PI. Using bit bagging works on all pins and is accessed via VM machine, that soft SPI class. Now, to begin, we need to import from the machine library, that pin class and the sauce Hi class. Now, first you need to construct a software SPI bus on a given pens. Polarity is the I, the state of the SEK. And you basically need to choose the phase. And phase 0 means Sam bill on the first inch of seeking. Phase 1 means on the second, and so on. We will explain this in a minute. Now. Again, let's create a new object. Let's call it SPI. And let's call that last soft SPI. Now first. And what will be the baud rate? And the bond rate is basically the base of serial communication. Let's add a 100 thousand. Now, we need to choose the polarity. And as we already mentioned, polarity is the ideal state of the SEK. And here, let's make it one. Now. The third input is the phase. Lag, phase equal 0. Now, phase equals 0 means sample on the edge of the SEK pen. Phase 1 means you need to sample on the second edge and so on. Now, after doing this, we need to assign pens. We need an N, which would be 1000. You'll also need em or 10. Let's make it print two. And now I'm o or m or is I, is basically the master slave. And if you don't know anything about SPI, you can check our class on that. This is not a course to explain the SPI communication protocol. We are just explaining how to implement it on ESP 30 to using micro Python libraries. We need the, um, i is o. Pen watches the master slave out. And let's make it. And let's say for pen for now, we have done the configuration for the US of SPI. The next tip is initializing the baud rate. You can initialize or sieve the positive pi r, I think SPI initialize. And inside here you can write baud rate equals to 100 thousand. Now to read ten bytes on MI or master, enslaved out, you can lights SPI and a three-year-old and simply write 10. Now you can't store it in any variable in here. Now to read ten bytes while outputting 0. If you come by in the very same thing, SPI speeds and write ten and to send output, right, 0, x. So this will read ten bytes on, um, I, I. So this will read thin us 0 while sending 0 excess. Almost her live in. Now to commit I'm Othar. You can simply write mass and make it equal by a 100. And let's give it a silent of it. Now will be used. Now our next line, we will read into their given buffer, but it's 15 bytes in this case because we added 15 here. So right, SPI in dirt, read in two. And right. Now you can also read into their given buffer outward 0 X FF, just like here, by simply writing SPI, the three and in two. And read from buffer. Then 700 x f. Now the right five bytes on the master slave n simply arrived SPI and birthrights. And in here, right, 12345, okay, Sorry, we have to place this inside here. And this will send this number, which is five whites on the amass her outs live in. Now we can also create another by writing a byte array, and let's make it four, which is the size of the array. Now, you can try them out, live in and read from the start enslave out into the buffer. And we can write and read at the same time using this function SPI. And their score read into. Inside here, we can find the things that you want to write. Let's say 1, 2, 3, 4, and, and buffer. So it will arrive this through the master slave in and read the incoming data from master and slave out and store it inside this part. And it will only read form. Now, if you aren't right. And the left arm to the master outs they've n and three in the master in slave out back into the buffer. You can use the very same line, height. Read into. And here simply write buffer. So it will arrive the buffer, the inside them are thought to the master slave n. And we'll read the incoming data from unsold inside of the muscle itself. So the muscle will be updated. I started this line. Now. All of that, a CK, I'm I, I'm I, S, O P specified when initializing the software SPI, like in here. The first line. Then you can go and change the word rate, change whatever you want. Now, let's talk about the hardware SPI bus. This is all software SPI, so you can use an MPN. It doesn't have to support the SPI protocol. Now what about the hardware SPI bus? While there are two hardware SPI channels that allow faster transmission rate up to 18 megahertz. These may be used on any input, output pins that support that require direction and are otherwise unused. But if they are not configured to their default pens, then they need to pass through an extra layer of general purpose input, output multiplexing, which can him back there readability at high speeds. Hardware SPI channels are limited to 40 megahertz when used on pins other than the default ones listed below. And let's list these pens. First for a CK when you have 14 and 18. Now, the fourth is four, which is Pi, and the 18 is four. Vi is P-I. Now for us I have 13 and 23 poll now I'm IS or you will and lighting. So make sure that you are using the right pens. You can either use 14th, here's three and 14, 13, 12, or you can use the other combination which is 1823. And 19. Now, SPI is accessed via the machine that SPI class and has the same methods as software SPI. Now I will explain to you how you can improve in the hardware SPI, using some but 14, 13, 12. And the same thing applies for all these three pillars. So let's call these lines. Now. First call the library, import from Shane, then SBAR. Now the HSP pi equals SPI. And then you must start writing. Now, what we are right here is an amber first fight one. And then write the baud rate, which is one mega watt. Since we have up to 40 mega, let's make ten mega hertz, okay? Now the SEK pin will equal ten. 14. Again, you need to use pins that we mentioned above. Ten loss I will equal number 13, equal 10, number 12. That's it. This is how to configure the SPI. Now, we have that v SPI, which would equal C SPI. Now, right? We'll say mega hertz and the molarity equals 0, the phase equals 0. This SPI, and the number of bits and eight. Now, I will explain these. The first pid equals 0. Now let's talk about the appends, the SEK pen. Pen. Pen. We also have the ISO, which will equal pen. Number 19, and we already mentioned the spins up here, 1823, 19. And all you need to do now is close the parentheses. And that will be SPI is good. 20. Now, let's soak these new parameters. First, the baud rate. Well, we mentioned the baud rate and it's the SEK cloak rate. Now the polarity, it can be either a 0 or one, and it is delivered the ID and a cloak Klein sits at. Now, fingers can be 0 or one to sample data, the first or second clock edge, respectively. Until we already mentioned that. Now the bits is the wind in bits of each transcription. Now only eat is guaranteed to be supported by all hardware. So was placed eight here. If you want to go up by eight, it's not. There are no guarantees that you will receive the right that now the first pit, it can be the most significant bit or the least significant deaths. You can sit that buyer, I think 01. And you also have the SEK, I, i, o, which are basically the tens the law module needs. Now, we have a function that you can use, unworthy used muscle then the soft SPI, we have varied function that reads a number of bytes specified by the data inside this function. Now we have that the initialize to turn off the SPI bus, we have the read into, which will read into the buffer specified. And we use the theory and the software SPI. So basically the hardware SPI uses the same functions. And we have the right which live the bytes content and the far and returns the thing. We also have the right read into what Slavs, the bytes from them. What reading into varied buffer. Now, this is so the things that you need to know about the software and the hardware SPI, the only difference between them is the configuration line, this one. Other than that, all of them, so all the methods all the same. And you can use these methods here or on the hardware SPI. That's it for this lesson. If you have any questions please ask. And under both facile watching this is Ashraf.
24. 17 7 I2C Protocol: Hello and welcome to this new lesson in which hung on to explain the I squared C or I2C bus. Now the software I square C bus using bit banging works on all output capable pens and is accessed via a machine that soft I squared C class. Now, to get started with that, you need to import the machine library. And from it you can import that Penn class and the soft I square C class. Now to initialize the I square c, Let's create an object called I2C or I square C and call the library soft ice cores. See, it will take the SCL Penn number, which is number five in our example. And it will also take the S and the a pin number. And it's all only needs two pens. And let's make it PIN number 4. Now, the frequency equal, let's say 10 thousand hertz, and that's it. Now to scan for I square SSE devices. Cindy right IS curve C in the scan. Now, if you want to read four bytes from device with either a is 0 X3. Now the scan will give a result. So you can win the result to see the devices that are connected to the ESP 32 board. And suppose I square c. Now let's say that there's a device and the other, so this device is 0 x three. Now, if you want to read four bytes from the device, will this address YOU CA right eye to see the 3D form. And inside the tribe, the device address. And the number of paths you want to read, which is four bytes. Now lists you want to read four bytes in this case. Now let's say that you want to write 12 to devise with this address. Now simply right eye to see the thrive right now, right, device address 0. And to send 12 simply right, between these two sides. And the device policy of this value. Now, you can also create a buffer. Pool thin bites. You provide buffer by halfway. And make it 10. Now you can live the given default to the slave by simply arrived to see the two. And here 0 X3. And the path to arrive the buffer, which is 10 bytes to this address, which basically live by given buffer to the slave. Now, there are other functions, but again, they are all basic, read, write, etcetera. And this is how to initialize the software. I square c protocol or I2C protocol. Now, let's talk about the I squared C or I2C bus. Now, there are two hardware. I square see peripherals and there are with identify are 01. And the available output capable pins can be used for a CL and as the a. But the defaults are as follows. For us, yeah. You can use PIN number 18 or 25. For us. The a you can use PIN number 19 or number 26. So 18 and 19 for I square C 0 and 25, 26 for I square C1. Now, this is accessed using that machine do I squared C library. So you'd have ite form machine port. When I square c. Then let's create an object as usual, right? I square C, choose number. We will use the R-square C. And here you need to set the configurations I square c equals I, see capita. And then here, so you have to write the numbers. Let's say a CL equals ten. Now, it's clear the pins on your board. And in this case we have a Cl at pin number 18, and we have the SDA and number line. Now. There might be different, and your ball pen is number 5 and 4, et cetera. Now you have said that frequency and you can set it to 0 or a 100. Now, one here is the ID. This is the device ID because you can have more than one device. Connected, and depending on the device specification, you can set the ID. Now, let's talk about the functions that you can use. And we already mentioned that they are very similar to the soft I squared C. So you can use I squared C. The scan to scan for available devices you can use IS curve C. The tried to to write three bytes to slave or seven bits at address 40 tool. So let's say that this is four to two and we want to, life reminds to slave. We can do that by similar, I think B. And the right 123. These are the three bytes that would be written to this location. Now, if you want to read, you can simply write I square C into three and phone number, or the address pairs. And the number of bytes that you want to read. And you can store them inside a read data variable. Now, you can also use a function to read three bytes from memory of 42, starting at a specific memory address. So let's use this function to read from underscore. And then here the address is false, you to want to start reading from eight. Now, the number of trials that we want to read is three. And this is how you can read three bytes of memory of slave 42, starting at memory address gate. And the sleep now can do similar thing when you want to write to memory and send the address for the tool to be and the value that we want to write. Let's say that want to write x. Now what this will do is the following. It will write one byte to memory of their 42, starting at address two and the slave. So this is how simple it is to The envoy, the I squared c protocol using ESP 32 ball. And by implementing the micro Python programming for microcontrollers issue that these things are. But once you started dealing with these communication protocols, you'll find it's as easy as writing cause an Arduino. That's it for this lesson. Thanks for watching.