The downsides are somewhat dramatic though - it’s, of course, a lot slower and hungrier for memory than the C equivalent code, but it’s also still missing a lot of API’s and fine grained control, at least for the ESP32. For instance, what finally made me switch to the ESP-IDF was complete lack of support for ADC2 on ESP32 in Micropython. Having to recompile the Micropython firmware to change a good chunk of the configuration parameters was also annoying because it takes a decent amount of time to compile and reflash firmware.
Bottom line is that Micropython is a great project for certain things - some home automation and simple sensors. On things where performance doesn’t matter or isn’t bottlenecked by the Python interpreter (like simple HTTP communication) it’s great. It also has a surprisingly robust open source driver ecosystem, provided you aren’t trying to do anything fancy with SPI.
It falls apart when you need to work with it professionally though. So use it to build and test your product, but rewrite it in C/C++ when it gets closer to ship time.
Indeed, it's helped deliver high-quality solutions quickly...
There is some steps necessary to go from "prototyping MicroPython" to "production MicroPython" and many people either forget about them, are not skilled enough to do them (which is fine, MicroPython is about onboarding people to embedded as well) or they feel like these steps make using MicroPython pointless.
Yes, true! I presented a lightning talk to colleagues on "Ingredients for Commercial MicroPython Success". One of the key points is "People are critical". Maybe folks here might find it useful:
My colleague gave a good talk on how we use MicroPython, as SOUP, in our devices:
(I typically am to scared to even use malloc on a microcontroller...)
But MicroPython's gc is fairly simple and easy to reason with. We've gotten a lot of value out of two useful tools/techniques: 1) Rendering memory use over long periods of time (micropython.mem_info(1) will output a text representation of how memory is used). It's pretty obvious when memory use starts expanding. 2) Turning the gc off in key unit tests so we can be sure critical sections do not allocate (an exception will be raised if memory is requested from the gc).
But, of course, memory use in any embedded application is critical.
Systems are typically fragile because of poor system design not language choice. I've worked on many C and C++ systems and there's nothing inherently more robust about them. Some would argue that the various ways you can trip over UB makes them more fragile...
That is definitely a factor! But I probably wouldn't pick C++ for a medical device now anyway - I would go with Ada or Rust.
> Systems are typically fragile because of poor system design not language choice.
Poor system design and language choice are both factors. You can work around language choice with a shit load of testing, but it's still much better to use a language that gives you stronger guarantees. Also the choice of language affects system design, so it's not like you can just ignore it.
For example even ignoring anything memory related, Rust's borrowing system pushes you towards code that has fewer bugs. Python... well, not so much!
If pointing out relevant and real differences between languages counts as "bashing" then I'm not sure how you are meant to discuss it.
Language choice does have an effect on program robustness. That's just a fact. And it's also pretty indisputable that Python lacks many features that help to write robust code.
Pretending that isn't true is immature and unprofessional.
It has some pros of course - having a REPL is good for experimentation, and it has a great library ecosystem for example. But neither of those are particularly important for commercial medical devices.
> Please explain what you think is important about commercial medical devices
I'm not exactly sure what you're asking here. Medical devices are often safety critical. They need to work extremely reliably. That's obvious; I think I must have misunderstood your question sorry.
I would like to as well, but that is very much not an option in most hardware projects at the time of writing of this comment. The ecosystem for these kinds of projects as a business in hardware is just too young to make it reliable enough to be shipping in a reasonable amount of time. Currently you really have very few choices in mainstream embedded programming for languages in a generic sense. You either work in c or c++, or you use micropython - and even micropython is young enough to invite some skepticism. No other ecosystem rivals these, though I do look forward to some promising commercial embedded Rust projects in the next few years.
(BTW, I can't vouch for NASA or SpaceX, but it's no secret that the European Space Agency has been working with MicroPython for many years.)
I don't disagree that reliability, repeatability and fast performance are (often) key; but our experience suggests that these can be (usually, if not always) achieved with MicroPython.
On the archmix, I managed to boot up and that’s about it. There was literally a REPL and I was able to blink the LED and then I couldn’t proceed further, where was I supposed to code?
Teensy: connect the board , fire up the teensyduino ide, choose an interesting example from the drop down menu, run it, rinse and repeat until you are familiar with idioms for all sorts of things, real hardware examples they do real things, real peripheral support in the form of examples
> rinse and repeat until you are familiar with idioms for all sorts of things
Except that the idioms you learn are really not suitable for anything but toy examples. Arduino is rotten from the core: "setup", "loop" and "delay" are the worst imaginable way to write embedded software, yet everyone coming from Arduino thinks this is how well written embedded software should look.
As I understand it, the ability to program Arduino in C was originally kind of an accidental feature of Arduino. The original Arduino downplayed C, and referred to the programming language as "wire." A few people (myself included) discovered that by simply ignoring those constructs, Arduino becomes a full fledged C development environment. But I think doing things "the right way" on a microcontroller really requires learning concepts that are not beginner friendly, like interrupts, and for that matter, electronics.
I agree with "delay", but why do you say setup and loop are the worst imaginable way to write embedded software?
Because there's neither abstraction nor ways to combine things. Say you have a device that needs to do two things, and you look up some examples of how to do each thing. Each example is going to have its own loop() function--but how do you combine them? There's no notion of tasks or threads. There's no abstraction for device drivers. Arduino is a system that paints you straight into a corner.
[edit to add] Any reasonable software environment needs to provide three things, quoting "Structure and Interpretation of Computer Programs" here :
* primitive expressions, which represent the simplest entities the language is concerned with,
* means of combination, by which compound elements are built from simpler ones, and
* means of abstraction, by which compound elements can be named and manipulated as units.
Arduino only provides the first.
The thing you are hating on is pretty much this file: https://github.com/arduino/ArduinoCore-avr/blob/master/cores...
Arduino is C++ with some boilerplate and a library.
Using Arduino will not magically rot your brain and make you unable to ever learn other things. It will however get you started quickly and therefore give you an in. I started using Arduino in a student job, then used Micropython, did my masters thesis on using Micropython on cubesats and now I run a team of 15 hardware engineers.
All of this happened because I got started with easy beginner tools. There was no one to teach me the "real" way. The people preaching the real way and railing against simple beginner stuff usually don't write tutorials, build easy to use devboards or write easy to use libraries.
CircuitPython is very nice for beginners, Adafruits tutorials are gold. Switching to MicroPython is very easy (CircuitPython makes some simplifications to be more beginner friendly, MicroPython aims to be as "professional" as possible).
Yeah, right. Now if i find out why it gives syntax error on a perfect part of code.
More accurately: it falls apart when you need it professionally :) Totally depends on the usecase.
As an aside, I really like Micropython and I spent a LOT of hours trying to make it work at a production level for my use case, but in the end I relented and had to write my software in C - it's not like I'm some low level language purist here. And it's not like my use case is what I would consider super edgy either - a fairly typical project with ESP32 where you wake sensors up on a very conservative basis (once per hour), take basic readings and send the data over HTTPS.
Works very well, but: it's still Python. Great, but dynamic so not the best suited for larger applications in my experience - no matter how well-architected the code is. Becomes just really hard to refactor without breaking anything.
Are you prototyping or manufacturing at scale?
What kind of sensors have you attached?
We use all manner of sensors; temperature, pressure, cap touch, photodiode detection, cameras.
Any of those that are passing would be a good board to choose to start with.
Several members of the community have been working on improving the embedded ecosystem: although I haven't played around with either yet, the nesper library (for the ESP32) and ratel (generic framework: tested for the Arduino/AVR) have been recommended.
If you are already in the industry, and part of the 90+% unwashed masses, then you already know this. If you are a student or hobbyist who hasn't clued into this reality yet, then there's no need for "language-choice anxiety". Play with whatever you want to play with, and once you graduate you should have no problem transferring that knowledge to whatever language your first real job actually pays you for (e.g. Java, Python, C#, etc).
From the last who is hiring thread:
Zig =0 mentions
Nim = 0 mentions
Julia = 2 mentions
C# = 4 mentions
C++ = 12 mentions
Rust = 13 mentions
Java = 18 mentions
Python = 50 mentions
The threads here are not indicative of the overall market and 1 mention != 1 job, but the numbers above are pretty much in line with the proportion of offers I am seeing elsewhere.
It is not even mentioned when looking for uncommon language mentions
It's the closest language to a static typed Python.
Also it uses GCC, which supports most microcontrollers.
Many languages (if it is AOT compiled and uses LVVM you can probably get it running on a uC) have POCs for running on an a uC, but often lack the HAL (libraries to use all the peripherals).
I think with current parts the only way would be to focus on RISC-V, but who knows. They might have better luck talking to vendors.
MicroPython - https://news.ycombinator.com/item?id=24166861 - Aug 2020 (147 comments)
MicroPython and the European Space Agency - https://news.ycombinator.com/item?id=9699798 - June 2015 (28 comments)
MicroPython: Python for microcontrollers - https://news.ycombinator.com/item?id=9558969 - May 2015 (19 comments)
MicroPython – Python for microcontroller - https://news.ycombinator.com/item?id=8177695 - Aug 2014 (17 comments)
1 comment is not a very big discussion
However, you're right about that case because the 1 comment was not that interesting. I'll take it out of the list above. Thanks!
Just this week I came across Swift for Arduino, and SwiftIO, both Swift language solutions for low level boards.
I'm looking forward to giving them a spin.
Edit: More specifically, the parser correctly ignores type hints.
I originally tried C using hardware debuggers and the whole 9 yards. It just took too long to get the toolchain setup and all the init required to get to a blinking LED (the helloworld of embedded). I also tried platformIO which looks very very cool but my boards weren't 100% supported. Next was the stm32 ide which helps you get a lot of the low level config off the ground but it still seemed the long way around. I also tried some of the hardware OS's like FreeRTOS but, again, not my cup of tea and "operating system" means something very different in the embedded world than what i'm use to.
i have a pi zero w and it really has my ears up too because i can run the same micropython there, can ssh to it directly, has a file system, runs linux etc. I have a really convenient pwm control board with an i2c interface so the non-realtime operating system on the pi zero isn't so much of an issue for what i do.
"So here we are two decades after Stackless Python was a thing, and instead of good concurrency support we have a never ending stream of simplistic language changes that increase complexity and fragment code and community. Python could have been so much more."
This is a great example of the politics that has ruined Python for more than two decades. It only got worse now that all dissenters have been purged by the mediocre rulers.
I mean, who wants anything but the fastest, leanest languages running on microcontrollers?
Me. I value speed and comfort of development more than micro-optimizations. Coincidentally this is why Electron is popular.
Seriously. That crap is a nightmare. Especially in production mode. Or maybe I just need more time with node, but trying to debug the main loop sans IDE is an act best described as excruciating. Once you start spawning new processes as well, you end up having to custom roll code to massage the port the spawn emits the inspect-brk for, which can end up getting quite complex if you have enough different entrypoints.
They're pretty simple and very creative, and the Raspberry Pi Pico is about the only Raspberry Pi device you can get hold of at the moment.
We've created an abstracted package called picozero, that makes turning on LEDs and reading sensors pretty simple in MicroPython. It's very easy to install and use, if you're using the Thonny editor - https://github.com/RaspberryPiFoundation/picozero
I recently wrote a Toit version of the lessons for the MakePython ESP32 starter kit. That makes it easier to start with Toit, but it also gives a nice comparison between the two.
Go is a great tradeoff, it's about as easy to learn and fast to write as Python for prototyping, while being a much slicker, faster, compiled language. But will the runtime fit a tiny MCU PROM?
edit: A Hello World written in Go and compiled with TinyGo is just 10kB!
It also works on Arduino Nanos, has builtin support for UART, SPI, I2C and PWM, and can also generate Linux binaries. This is a great find!
I remember using time.Format(time.RFC3339) in a project once. Seemed impossible to have such convenience on a microcontroller, and I probably paid a lot for it, but it did work perfectly.
It means we get a simple, nicely designed language with a great standard library, short development times, and small, performant binaries once compiled. Go on MCUs was out of question because of its runtime size. I'll keep an eye on this.
Been trying to find a 40%-ish keyboard with micropython so I can do the same with that, but no luck so far other than DIY jobs
Edit: Apologies, was thinking of CircuitPython, which it turns out is a fork of Micro Python. Not sure if micro can also output midi
Its a bit long winded but I tried to touch upon everything that a new entrant to the space would want to know to start playing with the board immediately.
I am not a natural public speaker so please excuse my verbal (or other) tics.
I have also linked the presentation PDF.  You can scan the entire PDF in less than 10 minutes to get the gist of the 45 minute+ YouTube video.
With hardware progress (ESP32 is 32bit/80MHz+), it seems another iteration happened: processing power is traded again for accessability/usability. In this case python.
I could see python becoming the predominant system for 32bit micro controllers. But for small 8bit systems that just read out a sensor and turns of a switch, that will stay in the realm of Arduino and C.
I used it for a little Windows macro program ( https://github.com/seligman/microkeys ) . I got it to a POC stage to solve the precise problem I have, basically I needed to be able to do some simple text parsing on whatever's in the clipboard and type out the results, so I'm happy. I'm always curious if it potentially fills a need for others as well.
I would still like to use micropython, but I need to figure out how to write certain pieces like the display lib in C.
I intend to have a try of both rust and tinygo.
Micropython is only ok on an esp32 with psram.
I use it on many devices (rp2040, nRF52, ESP32 and, professionally, on STM32). It's an effective platform on all of them.
If the alleged problem that micropython solves is complexity of actually coding microcontrollers, why settle for Python, which can only ever wrap/call native functionality that is hidden like a black box?
Is this really easy or useful at all?
A superior solution already exists called “Arduino” that removes most of the complexity of microcontroller development, comes with an ide and loader tool chain and you press a button and Bingo, your code is running directly on the metal of a variety of hardware, which these days includes some of the most powerful microcontrollers out there such as the teensy 4 and its iMX RT1062
I have an archmix with the identical microcontroller, but with a micropython runtime, it was sold by seeed studio and it sits in the box it came in as I never managed to do much with it.
There’s really no effective way of avoiding hardware with microcontrollers, as you expressly access it’s features with no operating system and only a HAL or CMSIS for an API, most of the time.
By the time someone wraps all hardware functionality in a scripting language, much developer time has passed and it’s likely that features are missing or broken, and basically the noobs are still out of luck waiting for all promised supported functionality and discouraged from learning anything about the actual hardware platform
I mean its almost irrelevant to the ability to handle serial, unless you are exec'ing raw serial, which is going to make everyone sad.
I have found that bitbanging in python a bit of an arse. Using the struct library isn't as forgiving (or dangerous) as it is in C. But on the flip side it does force you to properly define your binary serial protocol, unless you want loads of exceptions.
Arduino is grand, and fun. But where the python like languages shine is higher level stuff, like networking.
This is a nonsensical nonsequitur. The whitespace of the language you use has nothing to do with what communication it can do. Python works great for talking to my plotter over RS232.
Whenever I see someone complaining about Python's use of whitespace as syntax, I think to myself "This person poorly formats their code".
If you're properly formatting code, there's no reason to complain about it. You might occasionally copy/paste code from where that doesn't properly encode the whitespace, in which case yeah it might get messed up, but that's rare in my experience.