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 > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use micropython on newbit". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "how to use micropython on newbit"!
newbit (microbit) supports a variety of tools, such as JavaScript Block Editor, Mbed, gcc, espuino, etc. But let's start with the most familiar micropython.
ready
First of all, make sure that the Mbed serial driver is installed (note that you need to connect newbit to the computer first when installing), so that you can carry out the following work. Serial ports are automatically recognized on Linux and MacOS without the need to install drivers.
Then run a serial terminal software, such as putty, mobaxterm, etc., the serial number is where newbit is located, and the serial parameters are the standard 115200, n, 8, 1, none on MicroPython.
If you haven't downloaded the new program to newbit, it's still the original routine, so you can use micropython directly. Entering ctrl-c in the terminal software will abort the current program and return to REPL. If other programs have been downloaded, the original micropython firmware may have been flushed, so you need to download the micropython firmware and download it to newbit.
After downloading the new firmware, you need to press the reset button on the opposite side to see the familiar REPL prompt interface on the terminal.
MicroPython v1.7-9-gbe020eb on 2016-04-18; micro:bit with nRF51822
Type "help()" for more information.
>>>
>>>
Under REPL, we can input various instructions, code, and perform various functions. These can be referred to the previous "micropython Chinese tutorial 2.0," not repeated.
However, you may find that the version of micropython is very low, still version 1.7.9, and now the latest version is 1.8.7. This is because the official micropython file has not been updated, and the new version of the volume is relatively large, most of the nRF51822 can not fit. The current micropython leaves only 8K of space for users, which is still the case when Bluetooth functionality is not included. It is estimated that it will be possible to replace micropython when upgrading to nRF58400.
Note: There is a problem with this version of micropython is that there is a bug in the paste function. You cannot paste large code, otherwise you will have an error and need to disconnect the USB to reconnect to recover.
Graphic display:
There is a 5x5 LED array on the newbit, which can display small graphics and text, and the display effect is good.
In micropython, a dedicated library has been designed for LEDs, which can be easily displayed. Most of the time, as long as a command completes the display function. For example, the following code displays the scrolling text Hello ,World!:
from microbit import *
display.scroll("Hello, World! ")
This is displayed at the default speed. If you want to speed up or slow down, you can add the parameter delay, such as:
display.scroll("Hello, World! ", delay=50)
The default delay is 150. Setting it to 50 speeds up scrolling.
If you want to loop the display, you can add the loop parameter, in which case you can only return REPL via ctrl-C.
display.scroll("Hello, World! ", loop=True)
The default characters displayed are non-equidistant, which can be inconvenient in some cases. This can be done with monospaced fonts:
display.scroll("Hello, World! ", monospace=True)
By default, the display.scroll function does not return until the display is complete, equivalent to working in blocking mode. It can also be changed to non-blocking mode, so that after entering a command, the display can proceed in the background, and REPL can continue to enter other commands. Blocking and non-blocking are specified by the parameter wait.
display.scroll("Hello, World! ", wait=False)
The display.scroll function does not support Chinese and special characters
Note that in microbit's micropython, there are no common modules such as pyb and machine, but microbit libraries are used.
display.scroll can only display text, if you need to display graphics, you have to use another function display.show, it can display text, graphics, but can not scroll display, only one icon or character can be displayed at a time. For example:
display.show("Hello, World! ")
display.show(Image.HEART)
Microbit library has dozens of built-in icons, which can display commonly used emoticons, clocks, arrows, etc. You can view built-in icons through dir or tab key.
The display.show function also supports parameters such as delay, loop, wait, etc., similar to the display.scroll function. But display.show also has a special feature that supports displaying one set of icons at a time, such as:
display.show((Image.YES, Image.NO, Image.MEH))
In addition to built-in graphics, we can also define our own graphics, such as:
ico=Image('11111:12345:13579:50000:90000')
display.show(ico)
Each graph needs to define 5 parameters, each parameter is separated by a colon, a parameter has 5 numbers, representing 5 LEDs in 1 row, and each number represents the brightness of the LED.
We can also operate each LED directly, such as:
display.set_pixel(1, 1, 2)
The first two parameters are X/Y coordinates, and the third parameter is brightness (0-9, the larger the number, the brighter). You can also use the display.get_pixel function to read LED brightness.
Other common functions:
Clear the screen, display.clear()
Display.off()
Display.on()
At this point, I believe everyone has a deeper understanding of "how to use micropython on newbit", so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
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.