machine
— Hardware related functions¶
The machine
module contains specific functions related to the hardware on a specific circuit board. Most of the functions in this module allow direct and unrestricted access to and control the hardware blocks on the system (such as CPU, timer, bus, etc.).
Improper use can cause failures, locks, board breakdown, and, in extreme cases, hardware damage.
About machine
module functions and callback used by class methods:All these callbacks should be considered to be executed in the context of the interrupt。
This is true for both physical devices with ID> = 0 and “virtual” (for example, - 1) (these “virtual” devices are still thin pads above real and real hardware interrupts).
See :ref:` interrupt handler <isr_rules>`
- Class Pin – control I/O pins
- Class ADC – Analog-to-digital conversion
- Class TouchPad – Touch
- Class PWM – Pulse width modulation
- Class UART – Duplex serial communication bus
- Class I2C – Two-wire serial protocol
- Class SPI – Serial Peripheral Interface Bus Protocol (Master)
- Class Timer – Hardware Control Timer
- Class RTC – Real Time Clock
- Class WDT – Watchdog timer
Other functions¶
-
machine.
unique_id
()¶ Returns the byte string of the unique identifier of board/ SoC. If the underlying hardware allows it, it will change fromboard/ SoC instance to another instance. Length varies by hardware (if you need a short ID, use a substring of the full value). In some MicroPython ports, the ID corresponds to the network MAC address.
>>> machine.unique_id() b'\xccP\xe3\x90\xeb\xd4'
-
machine.
time_pulse_us
(pin, pulse_level, timeout_us=1000000)¶ Test the duration of the external pulse level at the given pin and return the duration of the external pulse level in microseconds.
pulse_level
== 1 test high level duration, pulse_ Level = 0 test low level duration. When the set level is inconsistent with the current pulse level, the timing will start when the input level is consistent with the set level. If the set level is consistent with the current pulse level, the timing will start immediately. When pin level and set level are always opposite, it will wait for timeout, and timeout returns to - 2. When the pin level and the setting level are the same all the time, it will also wait for the timeout, and the timeout will return to - 1,timeout_us
is the timeout.
-
machine.
rng
()¶ Returns a random number generated by 24 bit software.