Is MicroPython the right hammer for my nail?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Is MicroPython the right hammer for my nail?

Post by kevinkk525 » Mon Apr 26, 2021 3:40 pm

Well I already used micropython at work for quick prototyping and a simple board to control a simple car part for demonstrational purposes.
While developing the same program in c++ might have cost me multiple days, in micropython I was done after a single day (it was a small program).

I think micropython might be good in any prototyping environment as you get results significantly faster and if changes are requested, you can implement those more easily.
Once prototyping is done, you can still switch to c++ for performance or security or whatever reasons.

Additionally micropython is very close to python so learning one benefits the other. And since python is an extremely popular language, this might be a good introduction.
I wrote multiple programs at work with python and a lot of our software had at least a python compatible extension capability so I could write a lot of python scripts to make our work easier.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: Is MicroPython the right hammer for my nail?

Post by stijn » Mon Apr 26, 2021 7:32 pm

grodstein wrote:
Mon Apr 26, 2021 3:25 pm
I'm not particularly good at, e.g., USB device drivers.
You shouldn't be though. Correct me if I'm wrong but apart from some usecases being layed out by others this thread reads like you having a particular problem on Windows and others saying 'hey I have no problem, all good' :P

So perhaps it would be better to tackle that first. I.e. take a step back and imagine you didn't have that problem and your board just worked under Windows, would you still ask the question whether MicroPython is the right hammer? I might be wrong here, but it seems to me that this driver (?) problem is like *the* thing holding you back. In order not to let that skew your views on what MicroPython can and cannot mean for you I'd personally just try to get that fixed first. For example by asking on this forum. Or creating an issue at github.com/micropython. Or trying another computer. Seeing the number of 'just works' reports it is not unlikely that you just had bad luck with a particular combination of OS/driver/other hardware installed/...

Christian Walther
Posts: 169
Joined: Fri Aug 19, 2016 11:55 am

Re: Is MicroPython the right hammer for my nail?

Post by Christian Walther » Mon Apr 26, 2021 9:31 pm

grodstein wrote:
Sun Apr 25, 2021 11:19 pm
To Christian: I have heard about CircuitPython. What I've not seen, though, is an in-depth comparison between them. For example, I've heard that CircuitPython supports a single API across all devices, rather than tuning a different API to each device. Clearly simpler to use, but at some performance cost. What I've not heard, though, is any attempt to quantify how much that performance cost is, or specific examples of where that cost is. Do you have any?
No, I don’t know of any direct comparison between CircuitPython and MicroPython, other than https://circuitpython.readthedocs.io/en ... icropython. I don’t have any measurements, but I doubt that there is a significant performance penalty to CircuitPython’s unified hardware API compared to MicroPython’s historically grown ones. The differences are elsewhere. Regardless, if performance is your main concern, then neither CircuitPython nor MicroPython are the right tool for you. In an educational context, I don’t see why it should be, though.

The question about industrial/commercial use of MicroPython comes up every now and then. Here are some threads: It doesn’t seem to be as clear-cut as you make it. Sometimes performance and power usage is not what matters. Sometimes ease (and therefore cost) of development matters.

For the record, I’m a hobbyist (as far as MicroPython is concerned), I mainly use macOS, not Linux, and I have taught MicroPython/CircuitPython workshops to a wild mix of users of Windows, macOS and Linux, with no experience of any one of them being better suited than any other (for my use cases).

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Is MicroPython the right hammer for my nail?

Post by pythoncoder » Tue Apr 27, 2021 7:33 am

@grodstein Coming late to this party I thought I'd throw in a couple of observations.

Re commercial use. As someone who developed commercial firmware since 1975 I am certain that, had MicroPython and the hardware to support it existed, I would have used it. Not all commercial applications have production runs of 1000++. Some, like test jigs, are one-offs. Others have small production runs. MicroPython would have saved untold hours of development time. I would still have used C/C++ for cases that required it. Horses for courses.

Re CircuitPython. It is quite a different product aimed at beginners with ease of use as a main priority. It achieves this with distinction.

MicroPython requires a higher degree of experience, but offers vital features such as hard IRQ's and uasyncio. The latter is essential for most non-trivial firmware applications. If you plan to develop anything of any complexity, or anything requiring fast realtime performance, it is worth acquiring the skills to use MicroPython.

For realtime performance it is also necessary to consider your choice of host hardware.
Peter Hinch
Index to my micropython libraries.

grodstein
Posts: 13
Joined: Tue Dec 01, 2020 6:23 pm

Re: Is MicroPython the right hammer for my nail?

Post by grodstein » Tue Apr 27, 2021 1:00 pm

as many mentioned, it is also easily possible to use thonny ide for programming which would make it a lot easier. Kevin Köck
Thanks, Kevin; that is indeed my plan.
Well, I have to say that building your own version of MicroPython is more challenging, but your students won't have to do that once you have. John Ellis
Exactly. that's why I'm starting to believe that MicroPython will actually work for this class.
However, and forgive my possible misunderstanding, isn't ulab a module that you can use with standard MicroPython? John Ellis
That is not my understanding. At least, the docs seem to say that rebuilding the firmware is necessary (since ulab is written in C). But I've not gotten to that point yet, so if somebody knows for sure that I'm mistaken that would be good to know.
it seems to me that this driver problem is like *the* thing holding you back. Perhaps it would be better to tackle that first. I.e. take a step back and imagine you didn't have that problem and your board just worked under Windows, would you still ask the question whether MicroPython is the right hammer? Stijn
You're guessing correctly :-). For me personally, that's my largest source of frustration. Second-most is that the documentation seems (to me at least) to have the flavor of being written largely by hobbyists in their spare time :-). That's not meant as a flame, just as a statement that it's human nature for people (especially unpaid people) to target documentation at people like themselves. And since my background is CPU design rather than embedded, it's often a bit mysterious to me. But not terminally so.
I'd personally just try to get that fixed first. For example by asking on this forum. Stijn
Sigh... I did just that, of course -- with the result that nobody could offer any help with anything except for Linux. That's exactly what first sent me down the road of wondering who the real target of MicroPython is. So, e.g., the MicroPython documentation often references a document called "Care and feeding of Pythons at the Redmond Zoo" for dealing with Windows. The document does not have a date on it; however, one might guess its age from the fact that its list of the available Windows O/S's does not mention the existence of Windows 10. In my case, I'm lucky that I have the backing of an IT department that will set me up on Linux, and then (as John Ellis mentions above) the students don't have to deal with these issues.
Well I already used micropython at work for quick prototyping and a simple board to control a simple car part for demonstrational purposes.
While developing the same program in c++ might have cost me multiple days, in micropython I was done after a single day (it was a small program). Kevin Köck
Fair point; people in industry make quick prototypes all the time.
The question about industrial/commercial use of MicroPython comes up every now and then. Here are some threads:
viewtopic.php?t=7911
viewtopic.php?t=7134
viewtopic.php?t=4259
It doesn’t seem to be as clear-cut as you make it. Sometimes performance and power usage is not what matters. Sometimes ease (and therefore cost) of development matters. Christian Walther
Thanks. Those were quite interesting.
Not all commercial applications have production runs of 1000++. Some, like test jigs, are one-offs. Others have small production runs. MicroPython would have saved untold hours of development time. Peter Hinch
Agreed; it will be interesting to see what happens in a few years. For now, it seems like the appropriate summary is "some industrial usage where short development times outweigh speed or power concerns."

Thanks, all!
/Joel

User avatar
jcf
Posts: 60
Joined: Wed Mar 03, 2021 11:14 am

Re: Is MicroPython the right hammer for my nail?

Post by jcf » Tue Apr 27, 2021 1:59 pm

Kevin has already mentioned Thonny as a programming IDE, I find it very useful and easy to use with ESPs or the Pico.

User avatar
karfas
Posts: 193
Joined: Sat Jan 16, 2021 12:53 pm
Location: Vienna, Austria

Re: Is MicroPython the right hammer for my nail?

Post by karfas » Tue Apr 27, 2021 8:36 pm

introduction-to-engineering course for first-year students. They're straight from high school and may or may not have any programming experience at all -- this is their first semester of university. The goal is to have them learn a bit of programming and build some fun projects
You might be able to work around the Windows driver problem using boards with preconfigured network access, and using WebREPL or FTP. WebREPL should work in most recent Browsers - even on Windows.

Regarding "the right hammer":
I can only partial imagine what you will teach in an "engineering course". ~40 years ago. we had a 8085 board, an assembler and a handful of resistors and LEDs. I was maybe 15 at that time and it was (at least for me) "fun". And I still have an idea what a C pointer really represents.
A python layer over a complex API like ESP-IDF over a really capable, but also very complex ESP32 with three CPUs doesn't look for me like an environment to learn "engineering" (whatever this means) basics.

Teaching "programming" is an entire different area - this can be done without any embedded device and with almost the same "fun" factor. Give them some games to build. Space Invaders, Snake, Tetris.... all require some real-time (or at least fast) handling of keystrokes and are logical not too difficult, given today's programming languages.

BTW, I'm not sure if (micro)python is the right language to start with. Simple, short programs are easy, but sometimes I wish I had chosen a language with consistent syntax for programming my ESP32 modules. Maybe FORTH :-)

Regards,

Thomas
A few hours of debugging might save you from minutes of reading the documentation! :D
My repositories: https://github.com/karfas

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: Is MicroPython the right hammer for my nail?

Post by stijn » Wed Apr 28, 2021 6:21 am

grodstein wrote:
Tue Apr 27, 2021 1:00 pm
In my case, I'm lucky that I have the backing of an IT department that will set me up on Linux, and then (as John Ellis mentions above) the students don't have to deal with these issues.
Fair enough, but my point really was: there is a discrepancy between your experience and all others here and I don't know the root cause, but it sounds like your situation is an outlier and 'normally' things just work on Windows. As confirmed by others in this thread and e.g. a colleague of mine who has a couple of boards using Windows to get his son started with programming and has no problems at all. Not sure if I understand it corectly but if your plan now is to 'set up on Linux' and that entails a ton of work just to get linux running to talk to external hardware over a serial link, that sounds quite extreme to the engineer in me when the alternative seemingly more efficient solution is to drill down as to why things aren't working in the current situation (a solution which could include just getting another board on another PC to doublecheck :P Still less time/money). Also because it would be a mistake to assume that switching OS is a 100% guarantee of none of the current problems (and no new ones being introduced). Then again, I might just be misjudging the effort that takes.
karfas wrote:
Tue Apr 27, 2021 8:36 pm
Regarding "the right hammer":
I can only partial imagine what you will teach in an "engineering course". ~40 years ago. we had a 8085 board, an assembler and a handful of resistors and LEDs. I was maybe 15 at that time and it was (at least for me) "fun". And I still have an idea what a C pointer really represents.
A python layer over a complex API like ESP-IDF over a really capable, but also very complex ESP32 with three CPUs doesn't look for me like an environment to learn "engineering" (whatever this means) basics.
Actually a fair point, but it depends on what you do with it. When I had courses ~20 years ago we'd do similar things: program a PIC16 in assembly to control a robot. Great fun indeed, and the same level of fun and sense of engineernig can be achieved easily with MicroPython. As far as 'engineering' goes I'd tend to agree that it won't go into the real details, but the OP is talking about an introductory course so that is no problem likely. I mean, this is their first year, they'll barely know Ohm's law let alone microcontroller architecture.

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Is MicroPython the right hammer for my nail?

Post by kevinkk525 » Wed Apr 28, 2021 7:08 am

I'd also say that times have changed and people have changed. 20 years ago even the games were really difficult and you needed lots of time to progress and lots of retries. So 20 years ago people were apparently more willing to put lots of effort into something to achieve little.
Nowadays I'd say it's more like people expect things to work with as little effort as possible. If you have to retry stuff in games a few times, you look up the solution on the internet. If something doesn't quite work right away, people lose patience and do something else.
I think the examples of pic16 and assembler are nice, but almost no student today will go through the hassle of putting that much effort into it just to get a tiny result. Sure, I learned assembler at university too and it was more or less fun spending 20 hours for something micropython can do in less than one but I would have never used that at home for fun. And it was nothing I'd remember because I may need it at work.
So I think it would be better to forget about experiences 20 years ago, students (in my opinion) aren't like that anymore and you need something very easy that is very rewarding. Especially for students in their first semesters who know almost nothing about programming and electronics.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

2e0byo
Posts: 2
Joined: Tue May 04, 2021 4:41 pm

Re: Is MicroPython the right hammer for my nail?

Post by 2e0byo » Tue May 04, 2021 5:10 pm

Whether it's the right hammer for your nail or not, it's a jolly useful hammer to have in the drawer.

An observation from the student's point of view:

The first programming language I ever liked was PIC18 assembler. (More fun that PIC16, and memory access is easier). Nothing I wrote in assembler is still in use, 10 or 15 years down the line. I can't *read* it any more without thinking very hard. Stuff in C is, but the context switch to maintain the code is quite big if you only touch C once a month. Python/asyncio is easy (at any rate compared to C or even a simple assembler like PIC18); so easy that if your fridge dies you can cobble together a new controller in an evening.

I still largely remember the C++ we did when I was studying engineering, but I ended up in the humanities. Python is easy enough not to need remembering. I think there's a lot of value in students realising how much plug-and-play engineering is possible; they might actually do it when they think 'I could mend/repair/extend that'. And if it's an essential learning experience, they can even use pointers to mess up the stack if you let them near @viper :D

Post Reply