Once upon a time, it was popular to say this: When we are not crazy, we are old! This is the re-summoning of youth, or the elegy of dedication to youth. It may be just a taste, perhaps only inwardly!
In today's booming AI, IT giants are quietly laying out, as IT people are you ready? Although Python is not the best programming language into the AI ​​field, but there is no doubt that Python is entering and exploring AI mystery is a very popular programming language. Therefore, while you are still young, whether you are mentally or physically, or you are adolescent during your career, learn Python!
Adafruit's Metro M0 Express development board, which integrates MCU development with Python, is indeed an excellent development board for getting started with Python. Pure Python learning can not help but boring, if you can also point a lamp on the development board, is not it better! (Voice: Still boring!)
In addition to Python, you can also use Arduino to develop and test.
The first kanban and then the light, this is the only way to learn electronic (personal experience, do not imitate).
At first glance, isn't this Arduino board? It's actually not a drop. Although it has its shape, it is more powerful inside. Metro M0 Express has an ATSAMD21G18 core. Compared to ATMe328, it has a great improvement in frequency and storage. The pin is fully compatible with Arduino UNO.
In terms of power supply, a 7V~9V DC power supply interface has been added. The DC Jack specification is 5.5/2.1mm. The polarity is positive and negative. There is also a physical switch next to it. The power is manually turned on or off.
Unlike the Arduino, the GPIO interface no longer uses vias. Instead, it uses a patch type. The entire back of the development board matches the Metro Logo's big logo, making it even more atmospheric.
In terms of hardware configuration, the MCU model is the ADSAMD21G18. The maximum operating frequency is 48MHz and the operating voltage is 3.3V. The memory combination is 256KB of Flash memory plus 32KB of SRAM; it also has a 4MB SPI memory onboard, further expanding the storage requirements. The main features of Metro Express are as follows:
• ATSAMD21G18 core with a maximum operating frequency of 48MHz
• 256KB/32KB storage combination
• 2MB SPI Flash Storage Expansion
• 32.768KHz crystal
• 3.3V voltage regulator, maximum support 500mA
• Native USB support eliminates the need for FTDI-to-serial support
• Hardware Serial/I2C/SPI Support
• PWM output
• 25 GPIOs with 3.3V operation
• SWD debug interface
• switch
It is worth pointing out that the 25 GPIOs can be multiplexed for digital/analog pins, including a real module output pin A0. In addition, native USB support eliminates the need for a conversion chip such as FTDI. In addition to the USB interface, it can also act as a serial communication device, and it can also connect keyboards, mice, and MIDI devices.
In addition, a SWD debug interface is also integrated on the development board. I just don't know how to use it in the Arduino environment.
Don't care about this! Look at the last call.
Connect the USB port of the development board to the PC using the MicroUSB conversion cable. The Windows 10 system is installed on the test PC. After the development board is connected to the PC, the development board is powered via USB. After power-on, the three-color LED lamp of the development board is cycled to display the color, and the TX indicator of the serial communication starts to flash.
Windows 10 automatically detects the serial device and installs the correct driver, as follows
In addition, there will be a large-capacity storage disk on the PC, which contains the PYTHON boot code and related resources, as follows
Which main.py contains the relevant function code. The output of the serial port is as follows
This default program is a bit complicated. For beginners, let's try to write a simple lighting program that is also the first hello world program.
We know that writing Python programs on a PC has a lot of IDEs to choose from. So what is a good IDE to choose from when writing code for MCUs? Adafruit officials recommend using Mu as an IDE for Metro M0 Express. Download and install the Mu program from the official website.
The interface is relatively simple, there is no gimmick! However, this IDE provides a REPL console, which is a very practical program. Of course, you may think that using VSCode does not work with Spyder? Of course it does, but we know that Python programs provide a REPL environment for users to get help or experiment with simple code, and these IDEs are not useful at this time. Because these IDEs are based on the PC-side Python interpreter!
Write a simple piece of Python code first, independent of the MCU, purely to verify the Python interpreter.
code show as below
Import time
s = 0
For i in range(10):
Print(i)
Time.sleep(1)
Print('s = {}'.format(s))
Save the code as sum.py, as follows
The clever thing about Mu is that it saves the code to the disk that the development board maps to the PC. Name the file sum.py and save it. Then see if there is output in the serial port. However, there is no, it is still the output of the main.py program!
It turns out that CircuitPython follows certain rules when dealing with program execution. CircuitPython will find code.txt, code.py, main.txt, and main.py on the disk, find and execute the first program. We save the above code as sum.py, which is not listed in the above file at all, so the newly created file will not run at all!
Understand this point, it will be easier. Just change the name of sum.py to code.py and try it out!
The renamed code file takes effect immediately, as follows
You can see our desired result.
More than that, the hint also gives some useful information, such as "Auto-reload is on" This sentence tells us that the code file will be effective immediately after modification and saving, and we also see that code.py execution will take precedence over main .py.
The last interesting thing is that when code.py is executed, we can press any key to enter the REPL environment as follows
It's really good and powerful!
However, when we mentioned Mu as an IDE, Mu also provided a REPL environment.
The following window is the REPL environment, this is a very useful window, for example, we want to see the development board GPIO interface name, you can execute the following command in the REPL
Users familiar with Arduino programming must be familiar with interfaces A0, A1, so if you want to reference one of the interfaces, follow Python's rules, it should be board.XX, where XX is the name listed above.
OK, here's the official lighting, edit the following code
A piece of code that is very bachelor, of course, also understand! Save, and then automatically run. See LED lights flash flash, the serial port also has a corresponding output.
However, the question arises. Which libraries in CPython can be used? This can refer to the official documentation. See the appendix. Some of the libraries used in the above code are listed in the reference resource and take 5 minutes to familiarize yourself!
For a long time, CircuitPython is CircuitPT is the famous re-migration product of MicroPython, which is specially customized for Adafruit's hardware.
In addition to supporting Python, the development board also supports Arduino mode development. According to the general Arduino development model, first download and install the corresponding board library file, Metro M0 Express is no exception, as follows
Once you are sure, you can add the corresponding board type to Arduino's board manager. One of the most frustrating things here is that the official PDF document uses another development board as an example. It is not for Metro M0 Express. After a long time of installation, it found that the development of Metro M0 Express could not be found. The board model was re-solved after finding the correct library file in the web version! Because Arduino now supports too many types of development boards, many of the board's names are similar, and the result is often to find the wrong target, and make a joke. Wasting time!
The following figure shows the name of the board displayed after the software library is properly installed
Now you can open a blink program to light up, compile and upload the results are as follows
The LED flashes again.
However, the problem has come again, Python can not be used!
This is a normal phenomenon. Now that the storage space is occupied by the ARDUNO program, PYTHON cannot of course be used. Here's how to switch back to Python.
First double-click the reset button on the development board to enter the bootloader mode. At this time, the PC-side mapped drive letter will become METROBOOT, which has 3 files, as follows
Download a file with a .bin extension from the appendix given in the appendix, and be careful not to download it wrong. It must be a .bin file for Metro M0, then drag it to the mapped drive letter and wait for about 15 seconds. A miracle emerged and CircuitPython appeared again. Only at this time CircuitPython has not created a runnable Python file, write one of them, named code.py or main.py, and then throw it to the mapping disk, and again!
Overall, Metro M0 Express is still very fun. The first is hardware parameters upgrade, higher operating frequency and greater storage space, defeated Arduino UNO R3!; Secondly, the introduction of CircuitPython's new programming language, on the one hand the program code is simpler, on the other hand also for those who want Users who want to learn and understand Python provide a reason to learn; the last point is the flexible boot configuration mode, which allows flexible switching between two programming languages ​​(c/c++ and Python)!
As for the inconsistent documentation encountered during the configuration process, we can only blame the author for not being careful when looking at the documents. However, if the official documents are targeted, the user's experience will be better.
Laptop Stand Keyboard And Mouse,Laptop Stand Keyboard Set,Laptop Stand Keyboard Stand,Laptop Stand Keyboard Tray,etc.
Shenzhen Chengrong Technology Co.ltd is a high-quality enterprise specializing in metal stamping and CNC production for 12 years. The company mainly aims at the R&D, production and sales of Notebook Laptop Stands and Mobile Phone Stands. From the mold design and processing to machining and product surface oxidation, spraying treatment etc ,integration can fully meet the various processing needs of customers. Have a complete and scientific quality management system, strength and product quality are recognized and trusted by the industry, to meet changing economic and social needs .
Laptop Stand Keyboard And Mouse,Laptop Stand Keyboard Set,Laptop Stand Keyboard Stand,Laptop Stand Keyboard Tray
Shenzhen ChengRong Technology Co.,Ltd. , https://www.laptopstandsupplier.com