Author Topic: Micropython for MCUs - is it real or experimental ?  (Read 18676 times)

0 Members and 1 Guest are viewing this topic.

Offline ez24Topic starter

  • Super Contributor
  • ***
  • Posts: 3082
  • Country: us
  • L.D.A.
Micropython for MCUs - is it real or experimental ?
« on: November 29, 2016, 06:19:20 am »
In an online intro course to MCUs, the instructor said that someday he will be talking about C/C++ and Python.  I did not think much about it until I came across this playlist by Adafruit.  It is 31 videos on micropython.



I am making an assumption that micropython is python programming for an MCU - right?

If so I was wondering if it can be an  alternative to C and Ardunio C++  ?   Could it be that it is like middle ground - better than Arduino language but easier than C for mentally challenged people?

Tomorrow I will start watching YT videos on micropython.

thanks
YouTube and Website Electronic Resources ------>  https://www.eevblog.com/forum/other-blog-specific/a/msg1341166/#msg1341166
 

Offline mtdoc

  • Super Contributor
  • ***
  • Posts: 3575
  • Country: us
Re: Micropython for MCUs - is it real or experimental ?
« Reply #1 on: November 29, 2016, 06:28:34 am »
Have a listen to this Amp Hour episode from 2 weeks ago and your questions will be answered.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: Micropython for MCUs - is it real or experimental ?
« Reply #2 on: November 29, 2016, 06:38:09 am »
It can be an alternative to Arduino if you only use Arduino API and no custom code at all. And alternative as in "only suitable for hobby and toys, not a real production".

Also, MicroPython sacrifices quite a bit of actual Python, so you will always have to be aware of what you are doing and how much memory those things will consume. On a plus side, you will have to learn how to write very efficient Python code, a skill that will be useful for real Python programming :)
« Last Edit: November 29, 2016, 06:39:46 am by ataradov »
Alex
 

Offline Berni

  • Super Contributor
  • ***
  • Posts: 4956
  • Country: si
Re: Micropython for MCUs - is it real or experimental ?
« Reply #3 on: November 29, 2016, 06:40:59 am »
You do realize that Arduino is just C with extra libraries added to make using hardware easier.

And its not like pyhton is that much easier, there are still plenty of complex things to wrap your head around. But it is a higher level language that is more comparable to C++.

The language that is best depends on the application. C is perhaps not the best choice for making big complex GUIs, but then again a a very high level language like pyhton might not be a good choice for 8 bit MCUs because it uses a lot of resources to do what it does and might not leave you with much memory left or eat too much CPU time. Its a matter of the right tool for the job.
 

Online Jeroen3

  • Super Contributor
  • ***
  • Posts: 4078
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: Micropython for MCUs - is it real or experimental ?
« Reply #4 on: November 29, 2016, 06:45:04 am »
Everything can be a suitable alternative for C/C++ if there will be proper cross-compiler.
Anything requiring an additional active translator or interpreter will have significant performance and space constraints.
However, for the scope of beginners training or arduino. This does not matter.

Back in high-school I've programmed a PIC with Java. It was slow, created a ginormous image compared to the tasks, but it was simple enough to understand. It came in Eclipse, with simulator. (that's why java)
 

Offline e100

  • Frequent Contributor
  • **
  • Posts: 567
Re: Micropython for MCUs - is it real or experimental ?
« Reply #5 on: November 29, 2016, 07:13:48 am »
It's a derivative of Python.
The mains problem is that it's relatively slow at read/writing pins which can make it difficult to write device drivers.
Only a small subset of the Python libraries have been ported to Micropython.

Usable for I2C/SPI/UART devices or slow speed peripherals.
The interactive prompt allows you to try things without going through a compile/upload cycle.

 

Offline RoGeorge

  • Super Contributor
  • ***
  • Posts: 6203
  • Country: ro
Re: Micropython for MCUs - is it real or experimental ?
« Reply #6 on: November 29, 2016, 11:13:07 am »
...an  alternative to C and Ardunio C++  ?   Could it be that it is like middle ground - better than Arduino language but easier than C for mentally challenged people?

There is no such thing like "Arduino language". Arduino IDE is just a repack of the GCC toolchain (GCC is a C/C++ compiler ported for almost any processor and microcontroller) with a few libraries for the MCUs and a small editor on top. Arduino is using both C/C++.

Arduino sketches are using C, C++ or a combination of both.
 
The following users thanked this post: EBRAddict

Offline e100

  • Frequent Contributor
  • **
  • Posts: 567
Re: Micropython for MCUs - is it real or experimental ?
« Reply #7 on: December 20, 2016, 02:27:28 pm »
There's an interesting talk given by Damien George, the creator of Micropython about the technical aspects of the implementation
It's free of hyperbole and explains when it would be a good or bad choice for projects.

« Last Edit: December 20, 2016, 05:01:22 pm by e100 »
 
The following users thanked this post: I wanted a rude username

Offline tszaboo

  • Super Contributor
  • ***
  • Posts: 7390
  • Country: nl
  • Current job: ATEX product design
Re: Micropython for MCUs - is it real or experimental ?
« Reply #8 on: December 20, 2016, 02:37:42 pm »
It's a derivative of Python.
The mains problem is that it's relatively slow at read/writing pins which can make it difficult to write device drivers.
Only a small subset of the Python libraries have been ported to Micropython.

Usable for I2C/SPI/UART devices or slow speed peripherals.
The interactive prompt allows you to try things without going through a compile/upload cycle.
A typical Python 2.7 interpreter was using some 10 MB of memory on linux the last time I checked it. Now, python is only useful, if you have the libraries, and the "infinite" memory and infinite processing power. i really dont see the point to run it without the operating system, and crippling it so you basically have to rewrite stuff.
 

Offline RGB255_0_0

  • Frequent Contributor
  • **
  • Posts: 772
  • Country: gb
Re: Micropython for MCUs - is it real or experimental ?
« Reply #9 on: December 20, 2016, 02:41:21 pm »
I think Lady Ada is sleeping with the creator as she's really pushing MicroPython in practically every video.
Your toaster just set fire to an African child over TCP.
 

Offline e100

  • Frequent Contributor
  • **
  • Posts: 567
Re: Micropython for MCUs - is it real or experimental ?
« Reply #10 on: December 20, 2016, 04:59:20 pm »
I think Lady Ada is sleeping with the creator as she's really pushing MicroPython in practically every video.

Selling a $45 pyboard is probably a lot more profitable than selling yet another Arduino derivative when you have to compete against a sea of cheap Chinese clones.
 

Offline diyaudio

  • Frequent Contributor
  • **
  • !
  • Posts: 683
  • Country: za
Re: Micropython for MCUs - is it real or experimental ?
« Reply #11 on: December 20, 2016, 04:59:35 pm »
I think Lady Ada is sleeping with the creator as she's really pushing MicroPython in practically every video.
lol
 

Offline Sal Ammoniac

  • Super Contributor
  • ***
  • Posts: 1673
  • Country: us
Re: Micropython for MCUs - is it real or experimental ?
« Reply #12 on: December 20, 2016, 07:00:53 pm »
I think Lady Ada is sleeping with the creator as she's really pushing MicroPython in practically every video.

Thanks. Now I'll have to find a way to purge that image from my mind.
Complexity is the number-one enemy of high-quality code.
 

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3785
  • Country: de
Re: Micropython for MCUs - is it real or experimental ?
« Reply #13 on: December 20, 2016, 07:49:46 pm »
Arduino sketches are using C, C++ or a combination of both.

Arduino libs are C++ and the code is all compiled as C++, so you have classes and what not. Of course, most people using this rarely venture farther than some basic C-like code with it.
 

Offline rob77

  • Super Contributor
  • ***
  • Posts: 2085
  • Country: sk
Re: Micropython for MCUs - is it real or experimental ?
« Reply #14 on: December 20, 2016, 08:24:08 pm »
micropython is perfect for small projects involving high level data processing and network connectivity. the nodemcu/esp8266 with micropython is an order of magnitude more usable than with the lua or arduino firmware.
 

Offline julianhigginson

  • Frequent Contributor
  • **
  • Posts: 783
  • Country: au
Re: Micropython for MCUs - is it real or experimental ?
« Reply #15 on: December 20, 2016, 11:25:38 pm »
I think Lady Ada is sleeping with the creator as she's really pushing MicroPython in practically every video.

well, that was unnecessary....
 
The following users thanked this post: janoc, benst, Bassman59, newbrain

Offline free_electron

  • Super Contributor
  • ***
  • Posts: 8517
  • Country: us
    • SiliconValleyGarage
Re: Micropython for MCUs - is it real or experimental ?
« Reply #16 on: December 20, 2016, 11:48:22 pm »
micropython is an interpreter ... like a java machine this is a python machine.
Professional Electron Wrangler.
Any comments, or points of view expressed, are my own and not endorsed , induced or compensated by my employer(s).
 

Offline rob77

  • Super Contributor
  • ***
  • Posts: 2085
  • Country: sk
Re: Micropython for MCUs - is it real or experimental ?
« Reply #17 on: December 21, 2016, 01:38:38 am »
micropython is an interpreter ... like a java machine this is a python machine.

python, perl, ruby, lua... most of high level languages are interpreted , that's a fact ;) no-one says interpreted languages are good for everything, but interpreted languages are great for many projects. not good for high speed IO bit banging, but even if you need high speed IO you still can write your own library/module in a low level language and use it from the interpreted language ;)
 

Offline hans

  • Super Contributor
  • ***
  • Posts: 1641
  • Country: nl
Re: Micropython for MCUs - is it real or experimental ?
« Reply #18 on: December 21, 2016, 12:02:28 pm »
I can see this useful for a couple of things:

- Opening up the market even further for CS people to play with hardware (makes sense for Adafruit)

- Provide a scripting environment on a MCU, which can be useful for some general purpose boards, although it seems Micropython is a "one all be all" firmware of your MCU

- Quick & dirty projects that don't care about wasted resources and violation of the "no mem alloc" guideline on MCU's.

There are some niches and I might try it out someday, but for me it's applications are quite limited.
 

Offline julianhigginson

  • Frequent Contributor
  • **
  • Posts: 783
  • Country: au
Re: Micropython for MCUs - is it real or experimental ?
« Reply #19 on: December 21, 2016, 12:12:56 pm »
I left myself 24 hours to scratch my head on micropython, and while it seems like a really cool thing they have managed to get working, well, I really don't get it. As in, why would anyone use it - beyond playing about with it and toggling LEDs - to build something? even a prototype?

it seems that there's going to be a learning curve for this, even to people who use python regularly... so ... why would someone learn micropython when they could just learn c, and be working with a language that will give them so much more scope to grow past toggling a LED? (Then again that's also my argument about arduino/processing... ) 
 

Offline rob77

  • Super Contributor
  • ***
  • Posts: 2085
  • Country: sk
Re: Micropython for MCUs - is it real or experimental ?
« Reply #20 on: December 21, 2016, 01:46:24 pm »
I left myself 24 hours to scratch my head on micropython, and while it seems like a really cool thing they have managed to get working, well, I really don't get it. As in, why would anyone use it - beyond playing about with it and toggling LEDs - to build something? even a prototype?

it seems that there's going to be a learning curve for this, even to people who use python regularly... so ... why would someone learn micropython when they could just learn c, and be working with a language that will give them so much more scope to grow past toggling a LED? (Then again that's also my argument about arduino/processing... )

for example you need a wifi connected remote sensor - with an esp8266 and micropython you will have it up in running in few minutes. timers, network sockets, IO libraries - all are available in micropython... so what you need is "describe the functionality" in a nice object oriented way...  instead of "write the core functionality" in C, the most expensive part of every small project is the human effort, so if you can write your firmware in few lines of python code an save a day or two of coding and debugging, then why not ? . as mentioned it's ideal for small projects or standalone components of bigger ones.
 
The following users thanked this post: thm_w

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: Micropython for MCUs - is it real or experimental ?
« Reply #21 on: December 21, 2016, 04:34:37 pm »
so if you can write your firmware in few lines of python code an save a day or two of coding and debugging, then why not ?
Because no one just makes simple Wi-Fi connected sensors each and every day. And when you need to add some real functionality, you will have to scrap that day of work and start writing things in real languages.

So all you've got is a fast satisfaction, but no actual result.
Alex
 
The following users thanked this post: julianhigginson

Offline free_electron

  • Super Contributor
  • ***
  • Posts: 8517
  • Country: us
    • SiliconValleyGarage
Re: Micropython for MCUs - is it real or experimental ?
« Reply #22 on: December 21, 2016, 05:29:53 pm »
The nice thing is that micropython comes with a full blown networking stack , encryption and the whole hoopla. All the annoying crap nobody wants to deal with is already handled. you don't need to muck with libraries.

Here is a nice task to do : pick a cpu, slap on wifi and bluetooth. hook up a temperature/humidity/voc sensor. send data to a logging server. scatter 20 of these things around a building.

let's look at a few things:
- development time
- development tools
- cost of the hardware

i can do it with an epsressif ESP32 ( 180 MHz SOC with wif and bluetooth embedded ) and a bosh BM280 environmental sensor. hardware cost  : 4 to 5$

Development time : open i2c port , read bytes , send them through json packager and blast them into a socket instance. It's all there. the whole program is barely 30 lines of code. including network protection and encryption.

Development tools needed : a computer with a terminal program. i don't need no stinking compiler , no stinking debugger, no stinking ide , no stinking jtag dongle. no stinking wires no stinking serial port.

i can write, edit, trace directly over the bluetooth or wifi serial port emulator. firmware is updated over the air.

Try doing that with your devtools.

It may not work for all cases but for small systems that do processing at the node and send data to an aggregator :perfect.
Professional Electron Wrangler.
Any comments, or points of view expressed, are my own and not endorsed , induced or compensated by my employer(s).
 
The following users thanked this post: rob77, Howardlong, newbrain, julianhigginson, I wanted a rude username

Offline tszaboo

  • Super Contributor
  • ***
  • Posts: 7390
  • Country: nl
  • Current job: ATEX product design
Re: Micropython for MCUs - is it real or experimental ?
« Reply #23 on: December 21, 2016, 08:06:51 pm »
i can do it with an epsressif ESP32 ( 180 MHz SOC with wif and bluetooth embedded ) and a bosh BM280 environmental sensor. hardware cost  : 4 to 5$
IDK, but I have trouble sourcing the ESP32 for the moment.
It will run this micropython? Out of the box?
 

Offline julianhigginson

  • Frequent Contributor
  • **
  • Posts: 783
  • Country: au
Re: Micropython for MCUs - is it real or experimental ?
« Reply #24 on: December 22, 2016, 12:42:17 am »
The nice thing is that micropython comes with a full blown networking stack , encryption and the whole hoopla. All the annoying crap nobody wants to deal with is already handled. you don't need to muck with libraries.

But surely at some point - SOMEONE has to get drivers for the processor up and runnning? someone has to get libraries included, compiling, and more importantly thoroughly debugged.

the executive for python has to be able to run on the chip, talk to any on chip peripheral you need, manage memory allocation, map any sleep commands that the "OS" supports to the specific sleep functionality of the processor...

So in this case, if I have a processor that someone's gone and spent a bunch of time adding all this stuff in and getting it working, then yeah. I guess it'd be cool (but god help me if there's any bugs under that huge rug that literally all the hardware has been swept under!)

Compare to freeRTOS which also gives you this stuff, with its own API for the features that will be about the same as the micropython hardware API. except freeRTOS is years older, and so years more developed, with support all over the place for numerous chips (actively supported and encouraged for use by most cortex M manufacturers!) And if you have a problem with FreeRTOS, it's all there in your project to dig into and look at if needed


Quote
Here is a nice task to do : pick a cpu, slap on wifi and bluetooth. hook up a temperature/humidity/voc sensor. send data to a logging server. scatter 20 of these things around a building.

let's look at a few things:
- development time
- development tools
- cost of the hardware

i can do it with an epsressif ESP32 ( 180 MHz SOC with wif and bluetooth embedded ) and a bosh BM280 environmental sensor. hardware cost  : 4 to 5$

you can use these parts with a C compiler, too.

Quote
Development time : open i2c port , read bytes , send them through json packager and blast them into a socket instance. It's all there. the whole program is barely 30 lines of code. including network protection and encryption.

working with FreeRTOS will be similar.

Quote
Development tools needed : a computer with a terminal program. i don't need no stinking compiler , no stinking debugger, no stinking ide , no stinking jtag dongle. no stinking wires no stinking serial port.

mbed might be OK for a simple toy application like this... and that's a similar deal.
hell, it already has example apps from microsoft and IBM for sending this kind of data vial MQTT or HTTP REST(or AMQP with azure) all the way to azure or watson.

OK, it wont support ESP32 specifically, as that's some weird non-ARM architecture. But maybe the Realtek part will get mbed support some time? otherwise, use nearly ANY arm cortex part with a $2 ESP8266 module.

Quote
i can write, edit, trace directly over the bluetooth or wifi serial port emulator. firmware is updated over the air.

Try doing that with your devtools.

OK, now using serial port debugging from inside your python application, you try tracing what happens when the I2C driver compiled into the executive messes up underneath your python code for some reason, and you can only read zeros from your sensor...

or the memory allocation code screws up in some funny way on your particular target?

Or the way the generic OS sleep functionality is mapped to the specific features of your particular target is not right for some specific setting that the executive picks without telling you when you call a generic sleep/wait function?

And having all the relevant code for even looking at what might actually be happening under your application locked away in a separate project that you have no direct access to, no easy way to trace into it from your application code, and no experience with the language it's written in?
 :box:

Quote
It may not work for all cases but for small systems that do processing at the node and send data to an aggregator :perfect.

Don't get me wrong - I really love fast prototyping capabilities in modern software dev offerings... and I may even get a micropython dev board to play with some time.... My main issue is this is so far removed from normal embedded tools, that you're really going out on a limb just to learn it and really limiting your options when something goes wrong. For similar effort, you could just learn an embedded development language and basic techniques that have been proven over literally 5 decades of use.

To me, as neat a solution as it may be, it just looks like "IoT toy for web developer who wants to think they're a hardware person" same deal as that Tessel javascript board. It may be neat, beautiful, and elegant, but at the end of the day, it's a neat beautiful elegant cage.
« Last Edit: December 22, 2016, 03:44:27 am by julianhigginson »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf