Giter Site home page Giter Site logo

micropython-hw-lib's Introduction

micropython-hw-lib

Micropython (ESP8266) library for hardware peripherals. The collection includes external repositories, therefore it is required to run git submodule update --init after cloning repository.

Usage

The scripts are simple python modules that should be placed directly into micropython filesystem and imported, e.g:

from pcf8574 import PCF8574.

Precompilation

Bytecode

To save some space and time at import, individual files can be cross-compiled prior to transfering them to filesystem. This will generate micropython bytecode .mpy files that can be imported just like normal scripts with command above. The cross-compiler is part of micropython source and first needs to be built. Aftwerwards, it can be used like this:

MICROPYTHON_ROOT_DIR/mpy-cross/mpy-cross pcf8574.py

You can also use uPyLoader as a graphical interface to mpy-cross. Simply select files in left pane and press Compile. The bytecode files will be generated in same directory as source and are ready for transfer into device.

Freezing module

However, these files still reside in filesystem. To optimize further, they can be "freezed" (saved) into Flash memory. This will make them permanent part of the micropython binary. This can be done by placing them inside target's modules or scripts folder, e.g:

MICROPYTHON_ROOT_DIR/esp8266/modules/

MICROPYTHON_ROOT_DIR/esp8266/scripts/

The difference between the two is that scripts in modules folder gets compiled into bytecode with mpy-cross tool like above, while those in scripts will be just freezed into Flash. Note that only .py scripts should be placed in both folders as anything else can cause firmware corruption. After placing scripts in either of them, rebuild is needed. This will generate new firmware image that can be flashed like usual. The scripts are immediately available using the import syntax from above.

micropython-hw-lib's People

Contributors

betaravener avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.