[Diao Ye Learns Programming] MicroPython Manual WiPy The main classification of the specific port library wipy.machine

Insert image description here

MicroPython is a lightweight version of the interpreter designed for running the Python 3 programming language in embedded systems. Compared with regular Python, the MicroPython interpreter is small (only about 100KB) and is compiled into a binary Executable file to run, resulting in higher execution efficiency. It uses a lightweight garbage collection mechanism and removes most of the Python standard library to accommodate resource-constrained microcontrollers.

The main features of MicroPython include:
1. The syntax and functions are compatible with standard Python, making it easy to learn and use. Supports most core syntax of Python.
2. Directly access and control hardware, control GPIO, I2C, SPI, etc. like Arduino.
3. Powerful module system, providing file system, network, graphical interface and other functions.
4. Support cross-compilation to generate efficient native code, which is 10-100 times faster than the interpreter.
5. The amount of code is small and the memory usage is small. It is suitable for running on MCU and development boards with small memory.
6. Open source license, free to use. The Shell interactive environment provides convenience for development and testing.
7. The built-in I/O driver supports a large number of microcontroller platforms, such as ESP8266, ESP32, STM32, micro:bit, control board and PyBoard, etc. There is an active community.

MicroPython application scenarios include:
1. Rapidly build prototypes and user interactions for embedded products.
2. Make some small programmable hardware projects.
3. As an educational tool, it helps beginners learn Python and IoT programming.
4. Build smart device firmware to achieve advanced control and cloud connectivity.
5. Various microcontroller applications such as Internet of Things, embedded intelligence, robots, etc.

Things to note when using MicroPython:
1. Memory and Flash space are limited.
2. The explanation and execution efficiency is not as good as C language.
3. Some library functions are different from the standard version.
4. Optimize the syntax for the platform and correct the differences with standard Python.
5. Use memory resources rationally and avoid frequently allocating large memory blocks.
6. Use native code to improve the performance of speed-critical parts.
7. Use abstraction appropriately to encapsulate underlying hardware operations.

Generally speaking, MicroPython brings Python into the field of microcontrollers, which is an important innovation that not only lowers the programming threshold but also provides good hardware control capabilities. It is very suitable for the development of various types of Internet of Things and intelligent hardware.
Insert image description here

MicroPython is a streamlined implementation of the Python language for microcontrollers that allows developers to write embedded applications using Python syntax and standard libraries. WiPy is a wireless development board based on ESP32 chip, which supports running MicroPython firmware. MicroPython WiPy-specific libraries are a set of modules designed for WiPy that provide access to WiPy-specific functionality and hardware interfaces. The main features of MicroPython's WiPy-specific libraries are as follows:

1. It contains some WiPy-related modules, such as machine, network, pycom, uos, etc., which respectively provide WiPy machine-level control, network connection, lighting control, operating system interface and other functions.
2. It also contains some common MicroPython modules, such as binascii, hashlib, math, random, struct, time, etc., which provide some commonly used data processing, encryption, mathematics, random numbers, data structures, time and other functions.
3. It follows the design principles of MicroPython, which are simplicity, efficiency, portability and compatibility.

Insert image description here
wipy.machine is a module used to access and control hardware functions on the WiPy development board. It contains some classes and functions related to WiPy hardware.

1. Main features of wipy.machine

wipy.machine is a module used to access and control hardware functions on the WiPy development board. It contains some classes and functions related to WiPy hardware.
wipy.machine is a submodule of the machine module. The machine module is one of the standard libraries of MicroPython. It provides some functions related to the hardware of different platforms.
wipy.machine contains access to some WiPy-specific hardware functions and interfaces, such as ADCWiPy, TimerWiPy, UART, SPI, I2C, etc., which respectively provide analog-to-digital conversion, timer, serial port, SPI bus, I2C bus and other functions.
wipy.machine also includes access to some common hardware functions and interfaces, such as Pin, PWM, RTC, WDT, etc., which respectively provide pin control, pulse width modulation, real-time clock, watchdog timer and other functions.
wipy.machine follows MicroPython's design principles, which are simplicity, efficiency, portability and compatibility.

2. Precautions for use are as follows:

Before using the wipy.machine module, you need to import the machine and wipy modules first, and use the import machine and import wipy statements.
When using the wipy.machine module, you need to be careful not to conflict with other modules or devices, and to avoid using excessive memory and power resources.
When using the wipy.machine module, you need to pay attention to the specifications and limitations of hardware devices and sensors, and respect the relevant copyright and license agreements.

Insert image description here

3. The main categories of wipy.machine are as follows:

ADCWiPy class – Analog-to-digital conversion, used to create and control analog-to-digital conversion (ADC) objects that can read the value of analog signals.
TimerWiPy class – timer, used to create and control hardware timer objects, which can perform scheduled tasks or generate PWM signals.
UART class – serial port, used to create and control serial communication objects, which can exchange data with other devices or computers.
SPI class – SPI bus, used to create and control SPI communication objects, which can perform high-speed synchronous data transmission with other devices.
I2C class – I2C bus used to create and control I2C communication objects that enable low-speed asynchronous data transfer to other devices.

4. The detailed directory of wipy.machine is as follows:

1. ADCWiPy class
constructor: ADCWiPy(bits=12)
method: channel(pin, attn=ADC.ATTN_0DB)
method: init(bits=12)
method: deinit()

2. ADCChannel class
method: value()

3. TimerWiPy class
constructor: TimerWiPy(id, mode=Timer.PERIODIC, width=32)
method: channel(id, mode, pin=None, pulse_width_percent=None, freq=None)
method: init(freq=None, mode =None, width=None)
method: deinit()

Insert image description here

4. TimerChannel class
method: callback(fun)
method: freq([value])
method: pulse_width([value])
method: pulse_width_percent([value])

5. UART class
constructor: UART(id, baudrate=9600, bits=8, parity=None, stop=1, pins=(TXD, RXD), ctrl_pin=None) method: any() method: read(
[
nbytes ])
method: readall()
method: readinto(buf[, nbytes])
method: readline()
method: write(buf)

6. SPI class
constructor: SPI(id, mode=SPI.MASTER, baudrate=1000000, polarity=0, phase=0, bits=8, firstbit=SPI.MSB, pins=(SCLK, MOSI, MISO))
method :deinit()
method: read(nbytes[, write=0x00])
method: readinto(buf[, write=0x00])
method: write(buf) method
: write_readinto(write_buf, read_buf)

7. I2C class
constructor: I2C(id, mode=I2C.MASTER, baudrate=1000000, pins=(SDA, SCL))
method: deinit()
method: scan()
method: start() method
: stop()
method :readfrom(addr, nbytes[, stop=True])
method: readfrom_into(addr, buf[, stop=True])
method: writeto(addr, buf[, stop=True])
method: readfrom_mem(addr, memaddr, nbytes [, addrsize=8])
Method: readfrom_mem_into(addr, memaddr, buf[, addrsize=8])
Method: writeto_mem(addr, memaddr, buf[, addrsize=8])

Insert image description here

Guess you like

Origin blog.csdn.net/weixin_41659040/article/details/132962514