In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to use Python to write programs for the Internet of things through the VSCode RTOS plug-in. I think it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.
Real-time embedded operating systems such as RTOS make programming of embedded systems easier.
The Internet of things (IoT) is ubiquitous, which means that almost everything from refrigerators to pocket watches can be connected to the Internet. To achieve this goal, each product needs to have an embedded computer to run the network stack, and some products are almost unbelievably small. This is what embedded software looks like: very small computers built by modern technology that are hard-coded into hardware chips and do not require any off-board processors, memory or storage disks.
From a traditional perspective, this scenario means that there is no operating system available, but for a variety of reasons, developers have found that real-time embedded operating systems such as RTOS can make embedded system programming very easy.
Although the RT-Thread embedded operating system is committed to encouraging novice programmers to enter the field of the Internet of things, not all people have the ability to hard-code microchips in C language. Fortunately, MicroPython has gradually filled this gap by letting developers create Python code that runs on embedded systems. To make the whole process easier, RT-Thread has a plug-in that can be used for VSCode and VSCodium, providing developers with a development environment for the Internet of things. Some of its features include:
Convenient connection method, you can easily connect to the development board through serial port, network or USB (if you have used Arduino, you will be familiar with this process).
Support uploading files or directories to the development board.
Support for MicroPython-based code, and with intelligent code completion, syntax checking functions.
MicroPython REPL interactive environment is supported.
Rich sample code and demo programs.
Complete project synchronization function.
Run the program code in memory quickly.
The code snippet that runs the function.
Support the mainstream MicroPython development board.
Supports Linux and Windows operating systems and has been fully tested.
Prepare for
Before you start, if you are using the Windows operating system, you must make sure that the default terminal for VSCode is PowerShell. Run VSCodium to start a terminal from the Terminal menu item. In the terminal interface that appears at the bottom of the VSCodium window, select "PowerShell" from the top of the drop-down menu. Whether you are working on Windows or Linux, you must make sure that Python 3 is installed (on Linux, it may already be installed, otherwise it can be installed through a software library).
Also installed is the general VSCode Python plug-in provided by Microsoft. The installation method is to click the "File" menu, find the "Preferences" submenu, and open the "Extensions" panel. In the extension, search "Python" to find the Python plug-in from Microsoft.
VSCodium Python plugin
Of course, before you do this, you need to install VSCodium or VSCode correctly.
Install the plug-in
Install the MicroPython development plug-in in the same way as the Python plug-in. Click the "File" menu, find the "Preferences" submenu, and choose "Extensions".
In the extension, search for "MicroPython" and install the RT-Thread plug-in.
MicroPython plugin for RT-Thread
Use plug-ins
Your development board must be able to access the serial port, which requires the permission of group policy. You may need to add your account to this group, and your account may not be in this group by default. First, make sure your account is not in the "dialout" group:
$groupstux users
In this example, the user "tux" is only a member of the "tux" group and the "users" group, so you need to add the user "tux" to the "dialout" group:
$sudo usermod-append-groups dialout tux
Log out or restart to load your new group permissions.
Create a MicroPython project
The first step in MicroPython development is to create a MicroPython project to write and run code. To create a project using the MicroPython plug-in, click the "Create MicroPython project" button on the lower left.
Create MicroPython project
Then there will be some prompts for you to choose whether to create a blank project or a project that contains routines.
Connect to the development board
Click the "Connection" button at the bottom left of the VSCodium to connect the VSCodium to the development board, and in the pop-up list, select the physical device to connect.
View routines
The MicroPython plug-in provides many routines and libraries for learning and calling. The process of getting the routine is that after activating MicroPython, there will be a "New" shortcut icon on the left button bar of VSCodium, which can be clicked. Click the "document" shortcut icon, a list of routine files will be displayed; click the "folder" shortcut icon, and a list of case libraries will be displayed.
MicroPython examples
Run the MicroPython file directly on the development board
In VSCodium, you can debug the program conveniently and quickly by running a single program file on the development board. The shortcut key Alt+Q triggers a specific plug-in that uploads the current Python file to the development board memory. You can also right-click on the current Python document interface and select "Run the MicroPython file directly on the device" to achieve the same function.
Running code on your device
If you need to check a set of code without uploading code, you can use the "code snippet" feature. To run a snippet from the MicroPython REPL environment, select the snippet you want to run in the editor and click "Execute the selected MicroPython code on the device" from the right-click menu (you can also use the Alt+Q shortcut key).
Load files and directories to the development board
If you need to load a file or directory to the development board, there are ready-made methods: select the file or directory in the project to load into the development board, right-click on the selected object, and click "Download the file/folder to the device" in the right-click menu.
Note that if the development board already has the same name as the file or directory to be loaded, the load operation will cause the original contents of the development board to be overwritten.
Run the os.listdir () command in the REPL environment to check whether the files and directories are loaded successfully. Of course, you can also delete files or directories in REPL with the appropriate command.
The command to delete the file is as follows:
Os.remove ('file_to_delete')
The command to delete a directory is as follows:
Synchronization of os.rmdir ('folder_to_delete') Project
Click the "synchronize" button in the lower left corner to start project synchronization, which will synchronize all files and directories in the local project to the file system of the development board. It is recommended that you do this after debugging the program, and you don't need to synchronize frequently during debugging.
After the synchronization of the project is completed, the list of files on the development board can be seen in the "Device Files List" column.
Let go and try.
RT-Thread releases MicroPython plug-ins in an open source way, which is intended to help old and new developers. Many of its features, such as automatic code completion, influence and promote each other with open source plug-ins. If you want to write software for embedded systems or Internet of things systems, this is the easiest way, no one.
The above is how to use the VSCode RTOS plug-in to use Python to write programs for the Internet of things. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.