ESP8266 and MicroPython

Page 20

ESP8266 and Micropython - Coding cool stuff

CHAPTER 5 • MicroPython HARDWARE LIBRARIES 5.1 Overview

In the last Chapters we have seen how to write a MicroPython program and then how to run this program on the NodeMCU development board which was uploaded with the MicroPython firmware. In addition, several MicroPython programming examples were given to show how various features of MicroPython can be used in programs In this Chapter we shall be looking at the modules of hardware specific MicroPython libraries that can be used in our MicroPython projects. 5.2 machine Library Module

The machine library module contains hardware related MicroPython functions. Some of the commonly used functions in this module are: machine.reset(): resets the device as if the RESET button is pressed machine.reset.cause(): returns the cause of the reset. The following constants are available: machine.PWRON.RESET machine.HARD_RESET machine.WDT_RESET machine.DEEPSLEEP_RESET machine.SOFT_RESET machine.enable_irq(state): Re-enable interrupt requests. State is the value returned from the last call to disable_irq. machine.disable_irq(): Disable interrupt requests machine.freq(): returns the CPU frequency (in Hz) machine.sleep(): Stops the CPU and disables all peripherals except for WLAN. Wake sources must be configured for wake up. machine.unique_id(): returns a byte string with a unique identifier of the board in use. 5.3 machine Library Module Classes

Some of the commonly used classes supported by the machine library are: Pin: ADC: PWM: I2C:

input-output pins class analog to Digital converter class pulse-width-modulated output I2C protocol class

â—? 100

ESP8266 UK 170601.indd 100

09-06-17 12:05


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.