Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.2k
Welcome to the MicroPython Wiki!
This is the wiki for theMicroPython project, which puts an implementation of Python 3.x on a microcontroller or embedded system.
This wiki complements theofficial documentation and aims to provide a place for community-edited documentation, tips, tricks, and guides. Anyone with a GitHub account can contribute.
This wiki replaces the formerGollum Wiki on micropython.org and the content from there is being migrated over. In the meantime, you can access ithere.
The following hints result from problems that have frequently arisen inDiscussions and in the former Forum. The notes are intended for those new tomicrocontroller programming.
It's worth getting familiar with the language before using it in amicrocontroller context. This is best done on a PC with an online course or anintroductory textbook. With a basic grasp of the language it's a good idea tostudy itsuse on microcontrollers(official doc).
Perhaps you want to measure temperature and display it on a screen. Beginnersoften rush out and buy hardware, then start trying to figure out how to use it.The problem is that hardware devices usually need a device driver. This is aprogram providing an application program interface (API) for the device. Writingdevice drivers is not a beginner task; numerous drivers for MicroPython havebeen written and published. You are advised to seek devices for which a driveralready exists.
Platforms to run MicroPython also have different characteristics. If you havespecial requirements such a battery powered operation or high speed I/O, searchdiscussions and if necessary request help before spending money. Differentplatforms alsodiffer in how they support numerical computations.
Most firmware applications need to do several things at once. You might want todetect a button press while taking regular temperature readings and updating adisplay.
You've read the adverts which promise these powerful features:
- Timers
- Interrupts
- Threading
- Multi-core (on some boards)
All of these promise concurrency, but using them requires care and some reading.
These features are powerful but require some expertise to deploy effectively inan application; they carry risks of introducing subtle bugs. They are rarelythe best way to achieve concurrency. In most cases the best approach is knownas cooperative multi-tasking and the Python implementation is a library calledasyncio
.
Either way you probably have some reading to do. Learnasyncio
or learn howto write reliable code using the magic features.
- Asyncio official docs.
- Asyncio unofficial tutorial.
- Interrupts official guide - also applies to timer callbacks.
Writing code for threading and multi-core is particularly challenging. There is noofficial guide.This unofficial docprovides some guidance but does assume some MicroPython knowledge.
Please post a request inDiscussions. Choose a topic appropriate to your queryand write a title which summarises your problem. Please indicate when the issuehas been resolved. Also avoid spamming multiple root messages about the sameissue as it makes it hard to provide a coherent response or for helpers to knowif the issue is resolved. Your request will be seen, and if someone has an ideahow to fix it they will respond.
Please raise issues against MicroPython only if you are convinced that you havefound a bug in MicroPython. Examples of bugs are when the same code sampleproduces a different outcome in MicroPython compared to CPython. Study thelist of differencesbetween MicroPython and CPython to be sure this isn't a known isse.
If you're unsure whether something is a bug please ask in discussions beforeraising an issue: the maintainers are busy and you will probably get a quickerresponse.
To report a bug provide a minimal code sample that reproduces the bug withdetails of how it should be run - hardware, firmware build, any necessarywiring. Choose the issue title with care, identfying the hardware platform atthe start of the line. For example (fictitious bug)
rp2: RTC runs backwards on 32nd of month.
This will ensure that the report is seen by the appropriate maintainer.