11 ms·
MicroPython
- ak_25 6y agoI think this is good for someone getting started with microcontrollers(similar to the Arduino) However, one should not be disillusioned — I doubt this can be used to deploy a mass market product. However, I can see micro-python’s value in rapid-prototyping to some extent for someone who is not into embedded/firmware as much.
- StavrosK 6y agoWhy not? I've used it and it works fine, you don't get the granular control you get with C but I don't think there's anything that makes it fundamentally unsuitable for production.
- ak_25 6y agoWhen you have a product that is running out of flash and you want to deploy an update for your customers, you need that granular control. I just can’t fathom deploying a full product where I don’t have this sort of control? From a performance/space standpoint there is decades of compiler optimization experience with IAR/GCC, I’m not sure micropython can achieve that.
- StavrosK 6y agoI don't think it's inconceivable that there would be a product where you'd have ample storage and CPU power for your application and would want to optimize for speed of development instead. I've built things on MicroPython that would be just fine to ship as they were, for example, if I were to commercialize them.
- ak_25 6y agoWhen engineers start cutting corners and start to design not for performance but “speed of development” — it becomes a slippery slope. I guess I’m speaking from the standpoint of a firmware engineer, I honestly don’t think going with micro-python for our next product will buy us anything. However, as I said; if you’re not into firmware and/or just getting started, this makes a great prototyping language.
- StavrosK 6y agoIf you're a firmware engineer and already familiar with the ins and outs of C, I don't think it buys you anything, agreed. I also don't think there's something fundamentally wrong with it that would force a hobbyist to rewrite everything in C if they wanted to commercialize their prototype.
- ak_25 6y agoI can agree with this. If you find a language that is more approachable and gets stuff done, you should go for it. (And hopefully get sucked into firmware(I wish we had more firmware-engineers ;-) ))
- pjmlp 6y agoFor me, some of the hardware supported by MicroPython is more powerful that what I had on a desk during my MS-DOS days, so I can easily see using it for certain kinds of applications. If it was good enough to run Turbo Basic, Quick Basic, Turbo Pascal, Turbo C++, Clipper, it can easily take MicroPython.
- schwartzworld 6y agoyou're being a little hyperbolic. haven't you ever heard of premature optimization?
- embedpythony 6y agoThere are a few reasons. Number one, stability issues from heap fragmentation. http://docs.micropython.org/en/latest/reference/constrained.html#ram http://docs.micropython.org/en/latest/reference/constrained.... Even if you are careful about manual allocation, Python is not a compiled language, and the interpreter will frequently request heap allocations on its own. So if you expect a program to run for a long time without crashing, you'll probably need to use much less memory than the system has available. It's also quite slow. That's not a huge issue since modern microcontrollers are fast and you can write your own .mpy modules in C, but it does affect power consumption. It's also pretty high on the "drama" scale as far as OSS projects go. Last I checked, there was a brewing split between the original maintainer and one of the largest contributors, and Adafruit have already gotten frustrated enough to make a hard fork called CircuitPython. Personally, I would use it a lot more if I could trust it to run stably. For reference, I've used it in a Cortex-M0 clock which can run more or less indefinitely, but needs 16-32KB of RAM just to read an I2C clock and set some 7-segments. And when I tried to set up a simple wireless MQTT sensor with a supported Cortex-M4 board, I couldn't get it to run longer than a few days before the application crashed from memory fragmentation. So from my perspective, it is only usable for trivial tasks, and even if it were more stable, I'm not sure which fork would be the right choice for long-term development. Still, it's an excellent educational tool and I always like to see more of those.
- jennasys 6y agoAdafruit's fork was for business reasons as they wanted control over implementation for the hardware they sell, and to focus development efforts on making it more accessible to newcomers. While I'm not thrilled with the fork since it dilutes the original project imo, they do still contribute back to the micropython project. But I don't think there's any lost love there, they just had different goals with a financial stake (unlike the uasyncio split which was ego driven)
- mianos 6y agoI have an ESP8266 running MQTT to make an alert on a speaker (I2C) on demand. I just looked at the counter I periodically send to MQTT. It has been up for over 200 days. It does not leak.
- pmorici 6y agoDigi started using it as the user facing API for the programmable version of there xbee radio modules and those are very popular.
- analog31 6y agoIn my view, nothing can be used to deploy a product, without further consideration. My rationale for saying this is that in addition to programming in any language, you need to understand hardware, including safety. And I think that by the time a person reaches that level of knowledge, they have probably familiarized themselves with programming at a variety of levels from bare-metal C up to desktop software. Now, I've only been playing with MicroPython (actually the CircuitPython fork) for a few months, and at this point haven't come up with a "scale" of project that needs more than bare metal C but less than a full blown operating system. But then again I haven't come up with any good product ideas in that time period. As I mentioned to a friend of mine: "Hi, we're programmers, and we're here to burn your house down." Between the two real projects that I'm nursing along right now, one uses a FFT and the other an interrupt running at 170 kHz, so neither of those can be pure Python projects yet.
- matt_trentini 6y ago> one uses a FFT and the other an interrupt running at 170 kHz Neither of those rule out using MicroPython. Though you are likely to have to do some C work to achieve higher performance.
- analog31 6y agoYes, definitely. Any application that I can think of off the top of my head involves adding C code. This is not a hurdle, but would be for someone who is using Python to get into embedded programming at a beginner level. From the MicroPython documentation: >>>Compiling the cmodule into MicroPython >>>To build such a module, compile MicroPython (see getting started) with an extra make flag named USER_C_MODULES set to the directory containing all modules you want included (not to the module itself). For example: ... This is not precisely for the faint of heart, but should not be prohibitive for a seasoned embedded developer. ;-)
- ac29 6y agoYou might be interested in ulab for FFT and other numpy-ish things: https://micropython-ulab.readthedocs.io/en/latest/ulab.html#fft-routines https://micropython-ulab.readthedocs.io/en/latest/ulab.html#...
- matt_trentini 6y agoEveryone is open to their opinion; in the meantime the company I work for uses it for mass market devices in the medical domain. ;)
- StavrosK 6y agoMicroPython is amazing, it runs on very tiny microcontrollers not much else runs on, and makes development of hobbyist embedded projects orders of magnitude easier than C. I backed it way back when, I think for the ESP8266 support, and have loved it ever since.
- hak8or 6y agoI wouldn't say "very tiny". For example, does it run (and can do something useful) on a 8 KB cortex M0 with 24 KB of flash?
- makapuf 6y agoFor that, maybe snek[1] would be more suited. [1] https://sneklang.org/ https://sneklang.org/
- wizzwizz4 6y agoSnek's documentation has errors. > Like Python, Snek doesn’t have an explicit Boolean type.
- matt_trentini 6y agoNo, an effective MicroPython environment requires 32KB RAM and a couple of hundred KB of flash (it's possible to use less but the compromises are not worth it IMO). So yes, it's not possible to use very small devices. Still, this means that MicroPython can run on reasonably small, reasonably cheap devices - and your development effort can be significantly reduced.
- deleted 6y ago[deleted]
- butz 6y agoFor rapid GUI application prototyping LVGL has micropython bindings: https://github.com/lvgl/lv_micropython https://github.com/lvgl/lv_micropython .
- pansa2 6y ago> MicroPython implements the entire Python 3.4 syntax Python 3.4 is now over 6 years old. Are there plans to add features from newer Python releases? Or perhaps the developers feel that Python's newer features wouldn't "pull their weight"?
- analog31 6y agoI'd be interested in knowing how much bigger Python has gotten since 3.4 time frame. If course it's not unthinkable that it could always get smaller if there's a lot of refactoring going on, but that might be wishful thinking.
- matt_trentini 6y agoResource usage is carefully considered when introducing new features; but there are cases where it has becomes smaller. The recent addition of LittleFS meant that a couple of KB more RAM was available at boot for example.
- matt_trentini 6y agoPython 3.4 is actually the baseline for MicroPython these days. Many other more modern features have crept in; such as f-string support that was recently added. And the asyncio support is a modern implementation too... Generally MicroPython can absorb modern Python features where the implementation can be shown to be efficient, particularly with low RAM costs.
- btgeekboy 6y agoI once built a METAR light map like this - https://slingtsi.rueker.com/making-a-led-powered-metar-map-for-your-wall/ https://slingtsi.rueker.com/making-a-led-powered-metar-map-f... However, I did it with an ESP8266 running MicroPython; I was impressed that such a small, cheap little computer was able to connect to the internet, retrieve XML, parse it (this step in particular), and update the state of each of the WS8211 lights with ease, all with some quick, easy-to-write Python.
- ficklepickle 6y agoI have an ESP8266 wired into my intercom buzzer for opening the door remotely[0]. It has been unreasonably stable and reliable. Many months, possibly into years, of consecutive uptime. I used the arduino IDE and modified demo code for a web server. The cheapo dev board had it's blue LED die (mercifully) but is still chugging along. It's crazy what these things can do. [0] https://jeremypoole.ca/posts/put-your-door-on-the-internet/ https://jeremypoole.ca/posts/put-your-door-on-the-internet/
- alpineidyll3 6y agoIn my experience, one should understand the c dependencies to use micro/circuit python for most of desired uses. Still great stuff. The mere decrease in linecount for simple algs has real value.
- TeeMassive 6y agoFor plumbing stuff together it's probably great. Anything lower level that requires performance or real time constraints will probably not do.
- halbritt 6y agoMicropython can do some real-time stuff. It's limited, but a bit easier in my experience than getting a Preempt-RT running on a Raspberry Pi.
- pansa2 6y agoMicroPython seems to be heavily focused on embedded systems. Is there any support for embedding it within an application, i.e. as a replacement for Lua? Or is there another lightweight Python implementation (or Python-like language) that supports this?
- vsgzusnex 6y agoIt's slightly more constrained for performance but maybe Starlark is what you're looking for? https://github.com/bazelbuild/starlark https://github.com/bazelbuild/starlark
- HALtheWise 6y agoIt should be supported, although I don't have any good examples of people doing it. There is work being put into making micropython into a powerful webasm package for frontend development. https://github.com/micropython/micropython/tree/master/examples/embedding https://github.com/micropython/micropython/tree/master/examp...
- as-j 6y agoWhy not just use Lua? :) yes I get it, Lua is yet another language to your stack. But so is MicroPython. We were looking for a higher lever than C language for an embedded Linux system* and one engineer was massively in favor of MicroPython. But it’s not python, it’s based on 3.4 so it’s like python but not. It has its own rules and particularities. When I hire a new engineer I’d rather say “here read this book and learn this language” than “ok we have this python work alike/fork, now learn all these exceptions.” It’s also not a good fit for embedded Linux system programming like Lua is. *) this is an in production, professional environment, which decision will have years of legacy support and ramifications.
- marktangotango 6y ago“Not quite python” is a subtle point many people miss and indeed can be an issue. Third party library support is also huge, does micropython support the cpython library ecosystem? In this case the plethora of lua libraries readily available via luarocks is a huge advantage.
- oaiey 6y agoLEGO ist using it for SPIKE Prime and their related upcoming 51515 robotics set. There is even an inofficial firmware for their regular Powered UP electronics enabling MicroPython.
- dang 6y agoIf curious see also 2014 https://news.ycombinator.com/item?id=7840566 https://news.ycombinator.com/item?id=7840566 also 2014 https://news.ycombinator.com/item?id=6996692 https://news.ycombinator.com/item?id=6996692 2015 https://news.ycombinator.com/item?id=9558969 https://news.ycombinator.com/item?id=9558969 2016 https://news.ycombinator.com/item?id=11181158 https://news.ycombinator.com/item?id=11181158 Many submissions but those seem to be the interesting threads.
- albertzeyer 6y agoThere was also the submission about Pycopy recently, a fork of MicroPython: https://news.ycombinator.com/item?id=23446721 https://news.ycombinator.com/item?id=23446721
- not_the_fda 6y agoNeat, but not very practical. To be of any use you still need board support to drive the I2C, SPI, etc which means you have to use C anyhow. You can buy one of their boards with the BSP but that's over $40, yikes. To use micropython you need at least an M4 class micro-controller so that a $5 or greater part. Or you could just stick with C and use a M0 class micro that costs < $1. A difference of $40 in BOM cost makes it only applicable to the hobbyist. Which is fine, but its just a toy.
- dybber 6y agoIt runs very well on ESP32.
- not_the_fda 6y agoI've done work for a couple of clients, converting a micropython implementation to C on and ESP32, that would disagree with that statement.
- jononor 6y agoIf they need you for that they probably would not have been able to write it themselves in C in the first place?
- matt_trentini 6y agoThe ESP32 port still has a few rough edges, particularly around peripheral control. But it's a popular device and the port is improving all the time.
- embedpythony 6y agoTo be fair, there are BSPs for cheap chips like Espressif microcontrollers and a myriad of minimal development boards. You don't need to buy a pyboard, and part of the reason those are so expensive is because they help fund the project's continued development. But it definitely does have issues with memory usage. Personally, I hope that it will become more viable as its development continues and RAM densities increase. I love the syntax and ease-of-use, but I don't love needing a $10 chip for a $1 task. Hopefully it'll be usable for non-trivial tasks on a $1 Cortex-M23 chip in a few years. It also really shines in educational environments. I see a lot of promise in the progression from MakeCode (primary school) to MicroPython (middle/high school) to programming "real computers" (high school/college). It's a natural progression, and understanding simple microcontrollers takes a lot of the scary "magic" out of learning about complex application processors. See, for example, the BBC micro:bit (which also has a MicroPython BSP).
- neilpanchal 6y agoMicroPython is stellar. If you're building an embedded system for people to hack and customize, make the highest level abstraction of the embedded system in MicroPython so that users can easily modify/patch/contribute/hack your system with ease. This is what Arduino and Arduino IDE did for millions of hobbyist, but it is time to ditch C/C++ for MicroPython. In this [1] PyCon talk by Matt Trentini, a demo of QR code generation proves that with plain C and with MicroPython bindings, the performance is identical - 11.5ms. MicroPython is slow, and if the QR code library was written in pure MicroPython, it would take 1500ms. Therefore, it is critical to put performance demanding code in C/C++ modules and compile a MicroPython bindings. I think this is one of the best things that's happened to embedded development in a long time. Lua is nice but IMO Python is even better :) There is also Async IO library support for MicroPython. So ISRs can trigger coroutines! [1] https://www.youtube.com/watch?v=437CZBnK8vI https://www.youtube.com/watch?v=437CZBnK8vI
- zackees 6y agoGreat so now in order to create a performant embedded app i need to write everything in two languages. We should make Rust compile to Arduino and other embedded devices and be done with it.
- embedpythony 6y agoIt already does! (As long as the target supports LLVM) https://rust-embedded.github.io/book/ https://rust-embedded.github.io/book/
- mlyle 6y agoThere's a real advantage to having an interpreter. Write your low-level/high performance code in whatever. Then write top-level logic-- and let your users script in-- micropython. I'm teaching a middle school class this year with micropython on embedded. I can't fit Rust in with everything else I'm teaching in one trimester. I've even written an IDE which runs in the browser (on chromebook, etc) so there's no external dependencies for them.
- 6y ago
- foxh0und 6y agoHave a few M5's, they're great little gadgets.
- FpUser 6y agoI've done quite a few firmware development projects (they're commercial type and deployed in fitness industry, police vehicles, etc). They type of thing they do, I have a hard time imagining doing it in Python.
- noobermin 6y agoDoes anyone have any experience beyond short programs/sketches with micropython? The most I've used it for is playing around with a microbit. How does it hold up?
- vinw 6y agoI’ve got esp32s running a simple API over wifi to control a strip of addressable LEDs, with scheduling and some other functionality. Had some interesting problems to solve along the way but it is a fun language to work with and micropython is very stable on esp32.
- askvictor 6y agoI've been trying to make a (toy) contact-tracing system on microbits with micropython, but keep hitting RAM and flash limits; the lack of being able to write in append mode severely limits it's usefulness as an offline datalogger
- keyme 6y agoHad it manage an Ethernet Phy IC via an MDIO interface, and an FPGA over SPI. The MDIO was bit-banged from micropython, and SPI is a built in feature. This was running on an ESP32 creating a WiFi to Gigabit Fiber bridge (obviously not at gigabit speeds). I never thought it would be that easy, but it converted the task of writing something that does MDIO, SPI, and WiFi (with a webserver) in C, to basically a day of work. Also the "feel" of running an interactive python shell on a tiny 1x3cm board as part of the initial bring-up process after manufacturing is just awesome. Controlling every IO "manually" via the interactive shell is so much better than seeing your prepared C code crash and burn, and only then start debugging it.
- teddyh 6y agoThere also exists a Python-like language for when you only have a few kb of memory, and can’t even run MicroPython. It’s called “Snek”: https://sneklang.org/ https://sneklang.org/
- cozzyd 6y agoThere was a good LWN article about Snek a while ago: https://lwn.net/Articles/810201/ https://lwn.net/Articles/810201/ But, my impression is that Snek is mostly for "learning" while MicroPython is intended to do "real work" (obviously those are not disjoint categories).
- SV_BubbleTime 6y agoThat’s cool. Hadn’t seen that one. What is a “few kb”? Because last I looked Micropython was like 256kB and the smallest JS interpreter that had foreign function interface was 53kB.
- teddyh 6y ago> What is a “few kb”? From the manual: > […] could fit on our existing Arduino Duemilanove compatible hardware. This machine has: > 32kB of Flash > 2kB of RAM […]
- snvzz 6y agoRemarkably, it has recently gained (still not mainlined) 68000 support: https://twitter.com/micko_mame/status/1256221039308267520 https://twitter.com/micko_mame/status/1256221039308267520
- D0zMe 6y agoPerhaps it would be useful to package it for mobile phones.
- skybrian 6y agoI'm more familiar with CircuitPython because I've bought a few boards that could run it, though I've stuck with Arduino so far. It seems to be a fork started by AdaFruit, but it looks like there are other vendor boards it works on like SparkFun, Teensy, and Arduino. What boards work with MicroPython? On their website, they only list their own?
- jennasys 6y agoYou have to find the version of MicroPython that has specifically been ported to your board. In addition to the PyBoard (STM32), there is ESP8266, ESP32, BBC Micro Bit (ARM Cortex-M0), and WiPy (CC3200)
- Anka33 6y agoNo {}, no deal
- fxj 6y agoCheck out uiflow from M5Stack. It is a web-IDE which uses micropython for ESP32. You can use the M5stack grove sensors. The IDE generates python code which can be used on any MicroPython Implementation (ESP8266, EPS32, Raspi, CircuitPython, Micro:Bit, you name it) and the python libs are all open source. https://flow.m5stack.com/ https://flow.m5stack.com/
- fxj 6y agoSeeedstudio provides ArduPy for their Wio Terminal which can generate micropython libs from Arduino C Libs. So you can script Arduino Code with micropython on the device. As IDE they provide plugins for MS VisualStudo Code. https://wiki.seeedstudio.com/ArduPy/ https://wiki.seeedstudio.com/ArduPy/
- fxj 6y agoMaixPy ported Micropython to K210 (a 64-bit dual-core RISC-V CPU with hardware FPU, FFT, sha256 and convolution accelerator). It includes a general-purpose neural network processor, which can do convolutional neural network calculation at low power consumption, for example obtain the size, coordinates and types of detected objects or detect and classify faces and objects. It can load TensorFlow Light Neural Nets. https://maixpy.sipeed.com/en/ https://maixpy.sipeed.com/en/
- syntaxing 6y agoThat is awesome! Unfortunately the K210 link on the site is giving me a certificate error so I'm a bit afraid clicking into it. Do you know if the library will work with (https://www.seeedstudio.com/Sipeed-Maix-Cube-p-4553.html https://www.seeedstudio.com/Sipeed-Maix-Cube-p-4553.html)?
- fxj 6y agoI think it should. I have the Maix-Go (https://www.seeedstudio.com/Sipeed-MAix-GO-Suit-for-RISC-V-AI-IoT-p-2874.html https://www.seeedstudio.com/Sipeed-MAix-GO-Suit-for-RISC-V-A...) and it works pretty well. I also own the m5stick-v which has the K210 builtin (https://m5stack.com/collections/m5-core/products/stickv https://m5stack.com/collections/m5-core/products/stickv). I connect to them via screen on linux and get a micropython prompt in an xterm and can use it interactively. There is also an IDE available. See also the docs at M5Stack: (https://docs.m5stack.com/#/en/quick_start/m5stickv/m5stickv_quick_start https://docs.m5stack.com/#/en/quick_start/m5stickv/m5stickv_...)
- matt_trentini 6y agoIt does; in fact with my Maix Cube it came shipped with it pre-loaded.
- nl 6y agoI'm literally at lunch on the way home from picking up a delivery of one of these.
- halbritt 6y agoThey really push the pyboard which is cool and all, but imho, the killer application for Micropython has been the ESP8266 port and now the ESP32. The original pyboard can be had for around $20 and used to be closer to $30. The ESP8266 is a couple dollars, and the ESP32 is just north of $5. Obviously, we're only talking about a handful of dollars, but for embedded systems, it matters.
- ngcc_hk 6y agoFpga version so cover the really open issue? Single global thread issue still around? And whilst I like ulisp it is tie down with arduino and hope this will go out. Trying the js microprocessor implementation and let these two compete at least.
- VectorLock 6y agoThe coolest application of Python on uCs that I've seen recently is in the custom mechanical keyboard space: https://github.com/makerdiary/python-keyboard https://github.com/makerdiary/python-keyboard I'm loving the thought of being able to customize my keyboard's functions by just dropping python files onto its USB drive. Looking forward to using this on my Dactyl-CC build.
- geophile 6y agoCan anyone comment on what parts of Python are not in MicroPython?
- fxj 6y agoHave a look at: MicroPython differences from CPython http://docs.micropython.org/en/latest/genrst/index.html http://docs.micropython.org/en/latest/genrst/index.html
- matt_trentini 6y agoThe language is surprisingly complete; bigger differences are found in library support, even standard library support. Libraries that are memory efficient are easy to port but many Python libraries assume vast amounts of memory so it can require significant effort to modify them to use few resources.
- liquidify 6y agoanyway to get wifi?
- matt_trentini 6y agoAlready available on some devices. Notably the ESP32 and ESP8266.
- IceWreck 6y agoIve used the nodeMCU (ESP8266). Its arduino compatible, costs around $3 and has WiFi
- ausjke 6y agoI think Lua is also and already great at embedded usage? Of course the more the merrier. tinygo, micropytho, lua, there were a few mini javascripts but I lost track any of them
- Waterluvian 6y agoCan someone help demystify this for me? If I got out a microscope and looked at cross sections of a pyboard, could an expert point out the sections of physical gates and other parts that implement each python bytecode?
- Kliment 6y agoNo - this is implemented in software on a general-purpose processor. You can't read flash contents optically with a microscope, so the software part is invisible. You can certainly identify the bits of the general-purpose processor though.
- wilsonfiifi 6y agoAnother great resource for micropython tutorials is Miguel Grinberg’s blog [0]. In fact his blog is a gold mine for Flask development as well. [0] https://blog.miguelgrinberg.com/category/MicroPython https://blog.miguelgrinberg.com/category/MicroPython
- KaiserPro 6y agoI've been doing microprocessor stuff since the basic stamp 2 came out. (not that I'm an expert, I've just been fiddling over a long amount of time) I know that previous me was very scornful of micropython (the original boards were pretty expensive and power hungry) However, the ESP* and SAM21 microprocessors have changed my opinion. Yes python is still wasteful. but I can now operate in the microamps, and for less than £7 Not only that, these micro controllers has a wealth of documentation and addons. I feel like I've discovered the arduino all over again.
- aitchnyu 6y agoHas anybody got requests and/or full HTTPS protection working?