News for hackers. Stuff that matters.
Re:MicroPython – Python for Microcontrollers by SOLAR_FIELDS on Wednesday June 08, 2022 @02:35AM (#31664061)
I did a lot of product development using Micropython over the past year or so. There are certain things it is very good at - one is rapid prototyping. For instance it’s a lot easier and faster and less verbose to quickly get some http server communication going on the ESP32 in Micropython rather than the C equivalent.

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.

Re:MicroPython – Python for Microcontrollers by samwillis on Wednesday June 08, 2022 @02:49AM (#31664152)
I had a similar experience, however the “native” and “viper” code emitters do a very good job of allowing you to optimise performance bottlenecks. It’s a lot like Cython.

https://docs.micropython.org/en/kookaberry/reference/speed_p...

https://docs.micropython.org/en/kookaberry/reference/speed_p...

Re:MicroPython – Python for Microcontrollers by matt_trentini on Wednesday June 08, 2022 @07:22AM (#31665763)
The company I work for uses MicroPython commercially to build medical devices. It hasn't fallen apart for us.

Indeed, it's helped deliver high-quality solutions quickly...

Re:MicroPython – Python for Microcontrollers by turbinerneiter on Wednesday June 08, 2022 @07:48AM (#31665943)
You have to have the right people. They have to like Python and want to use it, but not because they think "C is too hard". They have to be happy writing Python code and confident enough to write modules in C and work on MicroPython itself.

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.

Re:MicroPython – Python for Microcontrollers by matt_trentini on Wednesday June 08, 2022 @10:27AM (#31667854)
> You have to have the right people.

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:

https://docs.google.com/presentation/d/e/2PACX-1vR3DJk-dNTvE...

Re:MicroPython – Python for Microcontrollers by RobertDeNiro on Wednesday June 08, 2022 @11:32AM (#31668864)
Re:MicroPython – Python for Microcontrollers by matt_trentini on Wednesday June 08, 2022 @11:42AM (#31669041)
Yes, but that doesn't give you a free pass. :)

My colleague gave a good talk on how we use MicroPython, as SOUP, in our devices:

https://www.youtube.com/watch?v=YovngSLXoxw

Re:MicroPython – Python for Microcontrollers by cozzyd on Wednesday June 08, 2022 @11:12AM (#31668532)
Can you guarantee you never run out of ram? Or do you just restart regularly?

(I typically am to scared to even use malloc on a microcontroller...)

Re:MicroPython – Python for Microcontrollers by matt_trentini on Wednesday June 08, 2022 @11:34AM (#31668907)
Managing memory use is one of the key concerns, particularly if you require long uptimes. Memory fragmentation can be a serious issue if you ignore it.

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.

Re:MicroPython – Python for Microcontrollers by IshKebab on Wednesday June 08, 2022 @10:56AM (#31668282)
That's worrying. I can't think of a less appropriate application for something as fragile as Python.
Re:MicroPython – Python for Microcontrollers by matt_trentini on Wednesday June 08, 2022 @11:12AM (#31668531)
The MicroPython interpreter is very robust and well tested. We test our devices extensively. You need to pay attention to gc performance, memory use and fragmentation but this isn't our first rodeo!

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

Re:MicroPython – Python for Microcontrollers by IshKebab on Wednesday June 08, 2022 @11:49AM (#31669161)
> 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!

Re:MicroPython – Python for Microcontrollers by ok_dad on Wednesday June 08, 2022 @04:15PM (#31673369)
Bashing Python, or language-bashing in general, makes you sound like an immature and unprofessional programmer. Python is perfectly fine when used in the proper way by a knowledgeable professional, and Rust can be a dangerous tool when used by a beginner. It takes the knowledge of a tool to use it properly and safely; just because someone hit themselves on the head with a hammer doesn't mean hammers are inferior to nail guns and unsafe, they still have their uses in several areas where nail guns aren't the best choice.
Re:MicroPython – Python for Microcontrollers by IshKebab on Wednesday June 08, 2022 @05:22PM (#31674408)
Sure, Python has its place. But that place is not where you need the software to work extremely reliably.

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.

Re:MicroPython – Python for Microcontrollers by ok_dad on Wednesday June 08, 2022 @05:42PM (#31674697)
Please explain what you think is important about commercial medical devices, because having worked in the industry I can tell you the FDA is the hurdle and it's going to be as hard to convince them that C or Rust or Ada is safe to use for a medical device as it would be to convince them that Python was safe, and in the process you will certainly be ensuring there are safety controls for each item on the software FMEA, whatever your chosen ecosystem.
Re:MicroPython – Python for Microcontrollers by IshKebab on Thursday June 09, 2022 @11:54AM (#31682785)
I'm talking about actually making reliably devices, not just satisfying regulations.

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

Re:MicroPython – Python for Microcontrollers by SOLAR_FIELDS on Friday June 10, 2022 @08:15PM (#31700748)
> 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.

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.

Re:MicroPython – Python for Microcontrollers by Mascobot on Wednesday June 08, 2022 @04:13PM (#31673346)
I agree. Using MicroPython in medical applications is with all due respect worrisome. It's not meant to be for crucial tasks and definitely not optimal at all for MCUs. It's really meant to be for simple, hobby applications. It's too high-level (synonym of inefficient) for MCUs. C and Assembly are the way to go for these critical applications (that's why NASA & SpaceX use C and assembly in embedded electronics). Reliability, repeatability and fast performance is key.
Re:MicroPython – Python for Microcontrollers by matt_trentini on Wednesday June 08, 2022 @11:13PM (#31677215)
Thanks for telling us what MicroPython is for. :P

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

Re:MicroPython – Python for Microcontrollers by a2800276 on Wednesday June 08, 2022 @05:22AM (#31664998)
One thing to add from my experiences: it's dramatically more accessible to beginners than Arduino and way more useful for building one-offs/prototypes as well.
Re:MicroPython – Python for Microcontrollers by iostream24 on Wednesday June 08, 2022 @06:29AM (#31665377)
My personal experience was the opposite. I own two identically equipped boards: the Seeed Studio ArchMix and the Teensy 4.1

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? Bad experience.

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

Re:MicroPython – Python for Microcontrollers by a2800276 on Wednesday June 08, 2022 @07:03AM (#31665636)
I agree that the user experience, onboarding etc. are very well executed for Arduino (and especially for the ESP32 port of uPython could use some polishing)...

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

Re:MicroPython – Python for Microcontrollers by analog31 on Wednesday June 08, 2022 @08:38AM (#31666373)
Indeed, those obstacles are easy to overcome, but someone has to point a beginner in the right direction.

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.

Re:MicroPython – Python for Microcontrollers by noedig2 on Wednesday June 08, 2022 @08:47AM (#31666465)
> "setup", "loop" and "delay" are the worst imaginable way to write embedded software

I agree with "delay", but why do you say setup and loop are the worst imaginable way to write embedded software?

Re:MicroPython – Python for Microcontrollers by jdcarter on Wednesday June 08, 2022 @09:23AM (#31666942)
> 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 [1]:

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

[1]: https://mitpress.mit.edu/sites/default/files/sicp/full-text/...

Re:MicroPython – Python for Microcontrollers by turbinerneiter on Wednesday June 08, 2022 @10:40AM (#31668049)
You don't have to use `setup` and `loop` tough. We use Arduino as a library in C++ using PlatformIO as tooling. Best of both worlds.

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.

Re:MicroPython – Python for Microcontrollers by a2800276 on Wednesday June 08, 2022 @12:58PM (#31670283)
But these `setup`, `loop` and `delay`, as well as the terrible "IDE" are central to the "simple" user experience of Arduino and are, imo, false friends. Teaching people busy loops and blocking behavior from day 1 is counterproductive because you'll have to unteach them later and jump through hoops to avoid them. Arduino libs are strongly optimized for "easy", not efficiency and flexibility.
Re:MicroPython – Python for Microcontrollers by turbinerneiter on Wednesday June 08, 2022 @03:56PM (#31673128)
I did just fine and so are millions of other people.

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.

Re:MicroPython – Python for Microcontrollers by dTal on Wednesday June 08, 2022 @08:52AM (#31666526)
Why are "setup()" and "loop()" bad? setup() is just main().
Re:MicroPython – Python for Microcontrollers by turbinerneiter on Wednesday June 08, 2022 @07:52AM (#31665968)
You need to buy a Pyboard from MicroPython, or Adafruit Express board for CircuitPython. Then you get a bunch of onboarding tutorials.

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

Re:MicroPython – Python for Microcontrollers by hulitu on Thursday June 09, 2022 @04:33AM (#31678883)
> One thing to add from my experiences: it's dramatically more accessible to beginners than Arduino and way more useful for building one-offs/prototypes as well.

Yeah, right. Now if i find out why it gives syntax error on a perfect part of code.

Re:MicroPython – Python for Microcontrollers by codetiger on Wednesday June 08, 2022 @04:59AM (#31664862)
Yes, I have been using MicroPython on ESP32 and RPi Pico. For projects like home automation, it was super easy and handy. When I started building a game console using RPi Pico (https://github.com/codetiger/GameTiger-Console), I had to rewrite as Python interpreter takes a lot of memory and leaves very little for the application. In my case, I had to avoid using Framebuffer on MicroPython. After switching to C++, its all in your control and take lot of time to write the same simple things
Re:MicroPython – Python for Microcontrollers by pjmlp on Wednesday June 08, 2022 @06:59AM (#31665605)
I think what used to be BASIC / Assembly relationship back when hardware comparable to ESP32 used to take a whole desk, is now Python / C++ instead.
Re:MicroPython – Python for Microcontrollers by stinos on Wednesday June 08, 2022 @06:03AM (#31665237)
> It falls apart when you need to work with it professionally though

More accurately: it falls apart when you need it professionally :) Totally depends on the usecase.

Re:MicroPython – Python for Microcontrollers by SOLAR_FIELDS on Friday June 10, 2022 @08:46PM (#31700912)
A fair point, but is it an inaccurate statement to say it falls apart when most need it professionally? I can easily accept that MicroPython makes sense for certain use cases, but to recommend it generally for people when I feel like I wasted many hours down the rabbit hole seems to be a bad idea - and I feel like your comment implies it's something like 50/50. So perhaps it's more accurate to say that there are a few pointed use cases when Micropython makes sense to ship with, but at least 80% (and I feel like I'm being very generous here with that number) of people are going to want to go the c/c++ route at the time of writing this comment in 2022, though I could see that changing in the future.

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.

Re:MicroPython – Python for Microcontrollers by nuclearnice1 on Wednesday June 08, 2022 @06:20AM (#31665325)
What did you end up using MicroPython for?
Re:MicroPython – Python for Microcontrollers by stinos on Thursday June 09, 2022 @03:23AM (#31678448)
Frontend for writing behavioral experiments. So backend runs C++ signal processing etc, graphics display, or whatever we need, all of that has bindings for MicroPython.

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.

Re:MicroPython – Python for Microcontrollers by matt_trentini on Wednesday June 08, 2022 @06:53AM (#31665542)
My company uses it for medical device development, ama if it will help!
Re:MicroPython – Python for Microcontrollers by nuclearnice1 on Wednesday June 08, 2022 @07:31AM (#31665827)
Very cool.

Are you prototyping or manufacturing at scale?

What kind of sensors have you attached?

Re:MicroPython – Python for Microcontrollers by matt_trentini on Wednesday June 08, 2022 @10:46AM (#31668141)
Manufacturing at scale. Though these are medical - not consumer - devices so we're not talking hundreds of thousands of units. Think high-quality, injection molded, moderately sophisticated devices. Typically hundreds and up to several thousands of units, depending on the project.

We use all manner of sensors; temperature, pressure, cap touch, photodiode detection, cameras.

Re:MicroPython – Python for Microcontrollers by R0b0t1 on Wednesday June 08, 2022 @03:25PM (#31672703)
Did you try running it on top of Zephyr?
Re:MicroPython – Python for Microcontrollers by matt_trentini on Thursday June 09, 2022 @04:19AM (#31678798)
I don't personally use the Zephyr port, though it has plenty of potential. But it's worth sharing that the Renode folks have put together a MicroPython on Zephyr dashboard to show that at least 90 of their simulated boards appear to reach the REPL:

https://zephyr-dashboard.renode.io/dashboard-micropython.htm...

Any of those that are passing would be a good board to choose to start with.