micropython | efficient Python implementation for microcontrollers | Interpreter library

 by   micropython C Version: v1.20.0 License: Non-SPDX

kandi X-RAY | micropython Summary

kandi X-RAY | micropython Summary

micropython is a C library typically used in Utilities, Interpreter applications. micropython has no bugs, it has no vulnerabilities and it has medium support. However micropython has a Non-SPDX License. You can download it from GitHub.

. This is the MicroPython project, which aims to put an implementation of Python 3.x on microcontrollers and small embedded systems. You can find the official website at [micropython.org] MicroPython implements the entire Python 3.4 syntax (including exceptions, with, yield from, etc., and additionally async/await keywords from Python 3.5). The following core datatypes are provided: str (including basic Unicode support), bytes, bytearray, tuple, list, dict, set, frozenset, array.array, collections.namedtuple, classes and instances. Builtin modules include sys, time, and struct, etc. Select ports have support for _thread module (multithreading). Note that only a subset of Python 3 functionality is implemented for the data types and modules. MicroPython can execute scripts in textual source form or from precompiled bytecode, in both cases either from an on-device filesystem or "frozen" into the MicroPython executable. See the repository for the MicroPython board (PyBoard), the officially supported reference electronic circuit board. Major components in this repository: - py/ — the core Python implementation, including compiler, runtime, and core library. - mpy-cross/ — the MicroPython cross-compiler which is used to turn scripts into precompiled bytecode. - ports/unix/ — a version of MicroPython that runs on Unix. - ports/stm32/ — a version of MicroPython that runs on the PyBoard and similar STM32 boards (using ST’s Cube HAL drivers). - ports/minimal/ — a minimal MicroPython port. Start with this if you want to port MicroPython to another microcontroller. - tests/ — test framework and test scripts. - docs/ — user documentation in Sphinx reStructuredText format. Rendered HTML documentation is available at Additional components: - ports/bare-arm/ — a bare minimum version of MicroPython for ARM MCUs. Used mostly to control code size. - ports/teensy/ — a version of MicroPython that runs on the Teensy 3.1 (preliminary but functional). - ports/pic16bit/ — a version of MicroPython for 16-bit PIC microcontrollers. - ports/cc3200/ — a version of MicroPython that runs on the CC3200 from TI. - ports/esp8266/ — a version of MicroPython that runs on Espressif’s ESP8266 SoC. - ports/esp32/ — a version of MicroPython that runs on Espressif’s ESP32 SoC. - ports/nrf/ — a version of MicroPython that runs on Nordic’s nRF51 and nRF52 MCUs. - extmod/ — additional (non-core) modules implemented in C. - tools/ — various tools, including the pyboard.py module. - examples/ — a few example Python scripts. The subdirectories above may include READMEs with additional info. "make" is used to build the components, or "gmake" on BSD-based systems. You will also need bash, gcc, and Python 3.3+ available as the command python3 (if your system only has Python 2.7 then invoke make with the additional option PYTHON=python2).

            kandi-support Support

              micropython has a medium active ecosystem.
              It has 16747 star(s) with 6530 fork(s). There are 730 watchers for this library.
              It had no major release in the last 12 months.
              There are 1324 open issues and 3489 have been closed. On average issues are closed in 198 days. There are 287 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of micropython is v1.20.0

            kandi-Quality Quality

              micropython has 0 bugs and 0 code smells.

            kandi-Security Security

              micropython has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              micropython code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              micropython has a Non-SPDX License.
              Non-SPDX licenses can be open source with a non SPDX compliant license, or non open source licenses, and you need to review them closely before use.

            kandi-Reuse Reuse

              micropython releases are available to install and integrate.
              Installation instructions are not available. Examples and code snippets are available.
              It has 47163 lines of code, 2897 functions and 1378 files.
              It has medium code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of micropython
            Get all kandi verified functions for this library.

            micropython Key Features

            No Key Features are available at this moment for micropython.

            micropython Examples and Code Snippets

            L2CAP connection-oriented-channels
            Cdot img1Lines of Code : 13dot img1License : Non-SPDX (NOASSERTION)
            copy iconCopy
            This feature allows for socket-like data exchange between two BLE devices.
            Once the devices are connected via GAP, either device can listen for the
            other to connect on a numeric PSM (Protocol/Service Multiplexer).
            **Note:** This is currently only sup  
            Pairing and bonding
            Cdot img2Lines of Code : 9dot img2License : Non-SPDX (NOASSERTION)
            copy iconCopy
            Pairing allows a connection to be encrypted and authenticated via exchange
            of secrets (with optional MITM protection via passkey authentication).
            Bonding is the process of storing those secrets into non-volatile storage.
            When bonded, a device is able  
            Building the documentation locally
            Cdot img3Lines of Code : 0dot img3License : Non-SPDX (NOASSERTION)
            copy iconCopy
            pip install sphinx
            pip install sphinx_rtd_theme
            make html  
            micropython - ble temperature central
            Pythondot img4Lines of Code : 180dot img4License : Non-SPDX
            copy iconCopy
            # This example finds and connects to a BLE temperature sensor (e.g. the one in ble_temperature.py).
            import bluetooth
            import random
            import struct
            import time
            import micropython
            from ble_advertising import decode_services, decode_name
            from micropyth  
            micropython - ble simple central
            Pythondot img5Lines of Code : 177dot img5License : Non-SPDX
            copy iconCopy
            # This example finds and connects to a peripheral running the
            # UART service (e.g. ble_simple_peripheral.py).
            import bluetooth
            import random
            import struct
            import time
            import micropython
            from ble_advertising import decode_services, decode_name
            micropython - ble bonding peripheral
            Pythondot img6Lines of Code : 153dot img6License : Non-SPDX
            copy iconCopy
            # This example demonstrates a simple temperature sensor peripheral.
            # The sensor's local value updates every second, and it will notify
            # any connected central every 10 seconds.
            # Work-in-progress demo of implementing bonding and passkey auth.

            Community Discussions


            How to retrieve and format wifi MAC address in MicroPython on ESP32?
            Asked 2022-Apr-17 at 15:02

            I have the following MicroPython code running on an ESP32:



            Answered 2022-Apr-17 at 15:02

            I am also a little suspicious of the bytes retrieved from wlan_sta.config('mac'). I would have expected something that looked more like b'\xaa\xbb\xcc\x11\x22\x33' instead of b'0\xae\xa4z\xa7$'. The z and the $ seem very out of place for something that should be hexadecimal and it seems too short for what should be six pairs of digits.

            You're not getting back a hexadecimal string, you're getting a byte string. So if the MAC address contains the value 7A, then the byte string will contain z (which has ASCII value 122 (hex 7A)).

            Am I using the correct method to get the MAC address?

            You are!

            If it is correct, how can I format it as six pairs of hex digits?

            If you want to print the MAC address as a hex string, you can use the ubinascii.hexlify method:

            Source https://stackoverflow.com/questions/71902740


            micropython and sys.implementation- different on XIAO SAMD21 and XIAO RP2040
            Asked 2022-Mar-27 at 18:05

            I was working with micropython on a SEEED XIAO (SAMD21) using version 1.18, and wanted to use 'compiled' libraries (.mpy) to conserve space. I had mpy-cross for version 5 which worked okay for me. I also wanted to have floating point so I built a new micropython with that option- from the latest (20220302) github version- and noticed that mpy-cross had updated to version 6. I thought I would check to see which versions of .mpy were used The micropython documentation suggests some code to check the version of .mpy using the sys.implementation object. I noticed a variety of sys.implementation implementations.

            Version 1.18- released by micropython 20220117 on the XIAO SAMD21 gave the following results:



            Answered 2022-Mar-27 at 18:05

            If you want to use precompiled/bytecode .mpy files then you will need to Decide to use either bytecode or compile to native code for your mcu platforms.

            For bytecode you will need to distribute a bytecode version that matches the runtime firmware, 1.12-1.18 == 5, next version will increase

            For native code you'll need to distribute versions for each platform that you want to support. An esp32c3 cannot run stm32 native code and vice-versa

            Also the different ports/board will indeed have differences in some of the stdlib APIs. Your code must be robust enough to handle these differences.

            Source https://stackoverflow.com/questions/71330735


            How to send the contents of a variable to Micropython repl
            Asked 2022-Mar-06 at 21:19

            I am trying to create a file in an ESP32 named "PassWord" containing a password, using Micropython Serial. The code below works with a "hardwired" password, but I would like to be able to send the contents of a variable that was typed in by the user. The sending script is running in Win10 using Python 3.7.9



            Answered 2022-Mar-06 at 21:19

            You could do something like this. Just made this as an exaggerated example so you can learn. You could put this whole thing into the send function input if you wanted.

            Source https://stackoverflow.com/questions/71365971


            Change url of a webpage on a local network
            Asked 2022-Mar-01 at 08:57

            I built a webpage on an ESP32 chip, charged to create an access point allowing my computer to connect in order to access this page.
            For the moment I can only access it using the IP of my ESP by typing it in a browser but it can be very bothersome.
            I'd like to know if it was possible to change the url of the page using words instead of the ESP's IP.
            Maybe I'm missing some technical terms but I didn't find any solution on the internet.

            PS: I'm using micropython with sockets to serve html files from the board:



            Answered 2022-Feb-26 at 19:31

            Certainly. The easiest option is enabling mDNS. This allows hosts in the same local network to resolve the device's name (e.g. espressif.local) into its IP. Only works in local network and requires an mDNS client on the computer (Mac, Linux and Windows all tend to have it built in these days).

            No idea how to do it in Micropython, though. Give Google a try.

            Source https://stackoverflow.com/questions/71276214


            SPDT Switches with a Raspberry Pi Pico
            Asked 2022-Feb-23 at 12:37

            Basically I'm just trying to figure out how an spdt switch would work with a raspberry pi pico. When I search for information on how to interface a switch with a pico, all I get is info on button switches.

            Does the spdt switch act like a closed circuit, constantly providing power to the pin I connect it to?

            Assuming the answer to the question above is "yes", how would I go about telling micropython to do different things based on which pin is receiving power?

            Sorry for the simple questions, I have no experience in the domain of microcontrollers and can't find this info anywhere.



            Answered 2022-Feb-23 at 12:37

            A switch -- by itself -- doesn't provide power to anything. All it does is close and open a circuit. You can replace the switch with a wire and connect/disconnect the wire and accomplish the same thing.

            If you had the middle pin of the switch connected to GPIO 2, and the two outer pins wire to Ground and Vcc, you could use the switch to switch the value of the GPIO between logic 0 and logic 1.

            Reading the value would look something like this:

            Source https://stackoverflow.com/questions/71230625


            Is it possible to wait for either button A or button B?
            Asked 2022-Feb-11 at 15:27

            This is code that waits for an event coming from button A.

            control.waitForEvent(Button.A, EventBusValue.MICROBIT_EVT_ANY)

            I want to wait for either button A OR button B to be pressed.

            Is this possible?


            I know that in Scratch this is possible with something like button.any, also the above code is written in microjavascript, but it is written similarly in micropython, so maybe someone from this field can also help. Thank you.



            Answered 2021-Dec-28 at 20:08

            Have a look at the python code generated using the 'on event from' block in https://makecode.microbit.org. This block can be found under the Advanced tab. The block can be set to wait for either button A or B to be pressed. The micropython code generated in this case is:

            Source https://stackoverflow.com/questions/70424520


            No such file or directory: 'arm-none-eabi-gcc' error trying to make micropython for STM32
            Asked 2022-Feb-09 at 13:39

            I am following the documentation for building micropython



            Answered 2022-Feb-09 at 12:32

            For some reason the installer did not put the binaries in my path. I fixed this with

            Source https://stackoverflow.com/questions/71047549


            How to iterate through files in a folder using MicroPython?
            Asked 2022-Feb-02 at 21:34

            I'm trying to read all files with .asm and .py extensions in an sd card using MicroPython.

            I checked the answers in this question but they don't work with MicroPython.

            MicroPython doesn't have glob nor pathlib and when using os library and try this code:



            Answered 2022-Feb-02 at 14:08

            your on the right track, os.listdir works just fine on any version of MicroPython, but does not recurse the sub-folders.

            so you need to distinguish a folder from a filenode as in the below.

            Source https://stackoverflow.com/questions/70946767


            Can't install Micropython module through upip, error message is not clear
            Asked 2022-Feb-02 at 15:49

            I'm trying to work with the Tronpy module in Micropython. It works fine when I'm using CPython. However, in Micropython, I tried to install it and got an error message. I'm using Fedora 34.



            Answered 2022-Feb-02 at 15:49

            It appears that you are attempting to upip install a CPython module on MicroPython. (sorry , could have seen that sooner)

            That will not work - unless that module is packaged specifically for MicroPython.

            The error message could be clearer though...

            I would suggest searching PyPi for MicroPython specific packages, either through the micropython- prefix or using the programming language filter:

            lastly: in upip you can enable some debug messages by setting upip.debug = True as in the below sample

            Source https://stackoverflow.com/questions/70934653


            esp32 micropython littlefs
            Asked 2022-Jan-31 at 22:27

            Using a Expressif dev-board and standard micropython.bin I was able to create a littlefs2 partition, mount it and write data into a file:



            Answered 2022-Jan-31 at 22:27
            A - Revert to fat

            if reformat with vfsFat is close enough to 'getting rid of' you can do the following:

            Source https://stackoverflow.com/questions/70783552

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network


            No vulnerabilities reported

            Install micropython

            You can download it from GitHub.


            MicroPython is an open-source project and welcomes contributions. To be productive, please be sure to follow the [Contributors' Guidelines](https://github.com/micropython/micropython/wiki/ContributorGuidelines) and the [Code Conventions](https://github.com/micropython/micropython/blob/master/CODECONVENTIONS.md). Note that MicroPython is licenced under the MIT license, and all contributions should follow this license.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries

            Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Explore Related Topics

            Consider Popular Interpreter Libraries


            by v8


            by micropython


            by RustPython


            by robertkrimen


            by mvdan

            Try Top Libraries by micropython


            by micropythonPython


            by micropythonC


            by micropythonJavaScript


            by micropythonC


            by micropythonPython