Live data from Hacker News

MicroPython

micropython.org

21–30 of 152 posts

Re: MicroPython

#21
post #14

MicroPython 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?

It 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/examp...

Re: MicroPython

#23
post #14

MicroPython 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?

Why 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.

Re: MicroPython

#24

In 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.

For plumbing stuff together it's probably great. Anything lower level that requires performance or real time constraints will probably not do.

Re: MicroPython

#25
post #14

MicroPython 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?

Why would you want to replace Lua in this space? At least why replace with another dynamically typed, imperative scripting language, but without tail-call optimization? What would be the gain?

Re: MicroPython

#26
post #4
post #2

I 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.

Why 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.

There are a few reasons. Number one, stability issues from heap fragmentation.

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.

Re: MicroPython

#27
Neat, 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 A difference of $40 in BOM cost makes it only applicable to the hobbyist. Which is fine, but its just a toy.

Re: MicroPython

#28
MicroPython 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

Re: MicroPython

#29

Neat, 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 A difference of $40 in BOM cost makes it on…

It runs very well on ESP32.

Re: MicroPython

#30

MicroPython 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 g…

Great 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.

Post reply on HN