WilkinsMicawber
Posts: 11
Joined: Sun Jun 11, 2017 2:01 am

Is Python the only smart choice for micro-controllers?

Sun Jun 11, 2017 4:50 pm

I recently joined a robotics team at my University coming from a strong background in C#. I am under the necessity of learning Python in order to collaborate with the team, but I am wondering how wise it would be to use C# for my personal projects. I don't consider having to write my own C# libraries for basic things like IR signal reading, compass deciphering, and the like desirable, so I'm curious as to what the landscape is concerning library support in the different languages. In your experiences, are most libraries for microcontrollers coded in Python? Would it be more trouble than it's worth attempting to program mostly in C# as opposed to Python for robotics projects, in general?

Heater
Posts: 13678
Joined: Tue Jul 17, 2012 3:02 pm

Re: Is Python the only smart choice for micro-controllers?

Sun Jun 11, 2017 8:12 pm

Not only is Python not the only smart choice for micro-controllers it is a mind numbingly bad choice.

It's big, it's slow, it has non-deterministic run time, it's terrible at handling asynchronous events.

All the good stuff is written in C.

Having said that: If your compute engine is something like a Raspi which has the speed and memory to handle a programming system like Python then it may be a good choice for all the higher level, non-real time functionality.

A Raspi is not a micro-controller.

Personally I would do it in Javascript under node.js. Especially if there is a lot of communications going on in your system. JS is far better at handling asynchronous events and is far faster than Python.
Memory in C++ is a leaky abstraction .

Pithagoros
Posts: 580
Joined: Wed Nov 12, 2014 8:16 pm

Re: Is Python the only smart choice for micro-controllers?

Sun Jun 11, 2017 9:03 pm

I am not a fan of Python, though there are some aspects of it that I admire.
But it is huge in the enthusiast community which means loads of support, literature and libraries.

C# needs .net framework on WIndows doesn't it? Or does it compile down to something that can be used by microcontrollers? (yes I know about mono but......)

WilkinsMicawber
Posts: 11
Joined: Sun Jun 11, 2017 2:01 am

Re: Is Python the only smart choice for micro-controllers?

Sun Jun 11, 2017 11:36 pm

I was confused about the difference between a micro-controller and the raspberry pi, but now I have a better idea after reading some literature. I'm sorry.

C and C++ for microcontrollers, to be sure.
Last edited by WilkinsMicawber on Sun Jun 11, 2017 11:46 pm, edited 1 time in total.

User avatar
Douglas6
Posts: 4778
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Is Python the only smart choice for micro-controllers?

Sun Jun 11, 2017 11:40 pm

Heater wrote:Not only is Python not the only smart choice for micro-controllers it is a mind numbingly bad choice.
MicroPython is quickly making its mark. Don't end up on the wrong side of history.

WilkinsMicawber
Posts: 11
Joined: Sun Jun 11, 2017 2:01 am

Re: Is Python the only smart choice for micro-controllers?

Sun Jun 11, 2017 11:51 pm

Is there any reason to choose Python over other languages for higher-level systems like the raspberry PI? I'm trying to gauge how useful these libraries truly are. I'm hugely hesitant to become proficient in a language I have little interest in knowing.
Last edited by WilkinsMicawber on Sun Jun 11, 2017 11:59 pm, edited 1 time in total.

User avatar
Douglas6
Posts: 4778
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Is Python the only smart choice for micro-controllers?

Sun Jun 11, 2017 11:58 pm

No, none at all, really. Choose what you're comfortable with, and what you find the most support for.

mfa298
Posts: 1387
Joined: Tue Apr 22, 2014 11:18 am

Re: Is Python the only smart choice for micro-controllers?

Mon Jun 12, 2017 1:05 am

Douglas6 wrote:
Heater wrote:Not only is Python not the only smart choice for micro-controllers it is a mind numbingly bad choice.
MicroPython is quickly making its mark. Don't end up on the wrong side of history.
I'm not sure that makes it a good choice, MicoPython like Arduino is probably good at getting beginners going (I've not really used either but I'm aware of them) if you want to do more advanced stuff and get the most out of the limited resources then you're probably best spending a few days with the datasheet and using C / ASM. As always it's a trade off of ease vs performance!
WilkinsMicawber wrote:Is there any reason to choose Python over other languages for higher-level systems like the raspberry PI? I'm trying to gauge how useful these libraries truly are. I'm hugely hesitant to become proficient in a language I have little interest in knowing.
It really depends on what you're doing there's plenty of large systems / web apps written in the likes of Python or Ruby. As always it's a trade off between what you know (or want to learn), performance, ease of coding. Something like Python or Ruby will make writing something functional a lot easier than lower level languages but you may compromise some performance (although on modern computers that's usually less of an issue)

* I prefer Ruby over Python, there are plenty of other things you could also add in that list.

WilkinsMicawber
Posts: 11
Joined: Sun Jun 11, 2017 2:01 am

Re: Is Python the only smart choice for micro-controllers?

Mon Jun 12, 2017 1:13 am

Good to hear. I'll learn a bit of Python and plan to use C and C# for my personal projects.

Heater
Posts: 13678
Joined: Tue Jul 17, 2012 3:02 pm

Re: Is Python the only smart choice for micro-controllers?

Mon Jun 12, 2017 2:47 am

WilkinsMicawber,

No need to be sorry over the confusion of micro-controllers, micro-processors, etc. Now a days the demarcation lines are getting very blurry. What with high end micro-controllers now coming with 32 bit processors, lots of RAM and FLASH and lot's of speed. Sometimes with multiple cores. Conversely computers have shrunk into single chip SoCs like those in phones, tablets and of course the Pi.
MicroPython is quickly making its mark. Don't end up on the wrong side of history.
I know. MicroPython arrived at almost exactly the same time as Javascript on the STM32 micro-controllers, in the shape of the Espruino. https://www.espruino.com/

Personally I'd rather use languages that have proper standards behind them. I find Javascript a lot easier to work with when there is a lot of juggling of asynchronous events to be done.

I don't know about ending up on the wrong side of history. Javascript has massive support and adoption now a days.
Memory in C++ is a leaky abstraction .

User avatar
Gavinmc42
Posts: 3921
Joined: Wed Aug 28, 2013 3:31 am

Re: Is Python the only smart choice for micro-controllers?

Mon Jun 12, 2017 2:52 am

It depends on what "microcontroller" you end up using on the bot.
How complex are the bots? Python seems to indicate bots are more than just a "microcontroller"

For robotics probably C/C++ is going to be the best choice.
Not because it's the "best" language but because there is more support and tools.
You may end up using OpenCV which is C++ based but does have other language interfaces.
http://opencv.org/

C/C++ requires compiling etc
Python is easy to use to do simple stuff quickly.

Lots of AI/Machine learning stuff is C/C++.
ARM's Compute library is C++ based.
https://arm-software.github.io/ComputeLibrary/v17.03.1/

Java, Go and Rust might be worth looking at too for stuff like this.
https://www.tensorflow.org/
https://github.com/autumnai/leaf

There are some advantages to using Go/Rust, higher level so less coding.
You won't be running these on a microcontroller, you can run them on Pi's.
The smart choice is learn them all as they all run on Pi's.
Unlike some microcontrollers which might be stuck with just C.

My personal bots are/will be Ultibo based, just because Linux is big and bloated (which is good?).
I just don't like having/maintaining so many dependencies.
So I use Free Pascal and no "OS" - https://ultibo.org/
Almost no support, so I have to learn everything but that is the whole point.
Pi's are for learning.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Heater
Posts: 13678
Joined: Tue Jul 17, 2012 3:02 pm

Re: Is Python the only smart choice for micro-controllers?

Mon Jun 12, 2017 3:12 am

Where is all this "bloat" in Linux that I keep reading about?

If I install Raspian Lite on my Pi I end up with a machine with more free space on it's SD card than my applications will ever need. Similarly more free RAM than my applications will ever need. And similarly for available processing speed. I see no reason to be worrying about bloat.

I don't worry about dependencies in the OS. That is what the package manager does for me. And it does it very quickly and reliably.

I can imagine situations where it would be nice to get Linux out of the way and hit the hardware more directly. But so far when I have the need to do that it's easier to use a micro-controller instead. A Propeller for example.
Memory in C++ is a leaky abstraction .

User avatar
Gavinmc42
Posts: 3921
Joined: Wed Aug 28, 2013 3:31 am

Re: Is Python the only smart choice for micro-controllers?

Mon Jun 12, 2017 3:52 am

If I install Raspian Lite on my Pi
You tried doing update/upgrade on 4.4 Jessie Lite recently?

Only 1.3GB when I have Pikrellcam installed for my security Pi's, leaves the rest of the 16GB card for images etc.
That's only 4 days in my neighbourhood.
MotionEye OS can do similar with <500MB
PiCore <100MB
Ultibo maybe < 10MB (no camera support yet so this is moot)

I worry about size when I have to back up project images, 8GB every time?
I don't worry about dependencies in the OS. That is what the package manager does for me. And it does it very quickly and reliably.
That's great unless you are behind a firewall that does not allow external access for Pi's.
I went to Pi's when Pic32's cost too much to add Ethernet shield.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

tpylkko
Posts: 382
Joined: Tue Oct 14, 2014 5:21 pm

Re: Is Python the only smart choice for micro-controllers?

Mon Jun 12, 2017 5:40 am

mfa298 wrote:
Douglas6 wrote:
Heater wrote:Not only is Python not the only smart choice for micro-controllers it is a mind numbingly bad choice.
MicroPython is quickly making its mark. Don't end up on the wrong side of history.
I'm not sure that makes it a good choice, MicoPython like Arduino is probably good at getting beginners going (I've not really used either but I'm aware of them) if you want to do more advanced stuff and get the most out of the limited resources then you're probably best spending a few days with the datasheet and using C / ASM. As always it's a trade off of ease vs performance!
Many of these new microcontrollers that run with Python are performance monsters. So optimizing resources like that is not as important any longer. Also they have wireless periferials like LTE-M, LoRa or Sigfox and I am not sure how easy it would be to control these with C or assembly. Also they usually have REPL so you can use them in interactive mode which is not anything you absolutely need but nice nevertheless. Micropython also is very stripped down and not like Python at all. Yet another advantage is time, when you are putting together loads of devices, it is nice if you just "script" them, and not write idiosyncratic ASM for them.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23918
Joined: Sat Jul 30, 2011 7:41 pm

Re: Is Python the only smart choice for micro-controllers?

Mon Jun 12, 2017 12:28 pm

Gavinmc42 wrote:
If I install Raspian Lite on my Pi
You tried doing update/upgrade on 4.4 Jessie Lite recently?

Only 1.3GB when I have Pikrellcam installed for my security Pi's, leaves the rest of the 16GB card for images etc.
That's only 4 days in my neighbourhood.
MotionEye OS can do similar with <500MB
PiCore <100MB
Ultibo maybe < 10MB (no camera support yet so this is moot)

I worry about size when I have to back up project images, 8GB every time?
I don't worry about dependencies in the OS. That is what the package manager does for me. And it does it very quickly and reliably.
That's great unless you are behind a firewall that does not allow external access for Pi's.
I went to Pi's when Pic32's cost too much to add Ethernet shield.
Don't conflate the distribution with the Operating System. Different things.

The distro might have bloat, but Linux the OS doesn't.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I think it’s wrong that only one company makes the game Monopoly.” – Steven Wright

Heater
Posts: 13678
Joined: Tue Jul 17, 2012 3:02 pm

Re: Is Python the only smart choice for micro-controllers?

Thu Jun 15, 2017 6:48 pm

Gavinmc42,
You tried doing update/upgrade on 4.4 Jessie Lite recently?
Sure. Just now did it again. No problem, hardly takes anytime.

The end result is:

888Mbytes used of my 16GB SD card. I'm not going to worry about that. Should have just got an 8GB card.

57MBytes memory used. 867Mbytes free. I'm not going to worry about that.

CPU usage, less than 2%. And that is when top is running. I'm not going to worry about that.

If the is any "bloat" in there it's not causing any problems.

Of course if I find that there are some packages installed that I will never use then I may well remove them.
Memory in C++ is a leaky abstraction .

User avatar
Gavinmc42
Posts: 3921
Joined: Wed Aug 28, 2013 3:31 am

Re: Is Python the only smart choice for micro-controllers?

Fri Jun 16, 2017 1:50 am

PiCore Linux OS comes with Micropython as standard.
It is not too bad, faster than shell script anyway :lol:
Much, much less than 888MB, I usually test it on very old (reliable, single layer, big micron ) 128MB SD cards.
Yep top 2% is normal for me too.

Heater, was that update/upgrade from new install of old 4.4 or just another progressive update?
I think I need new SD cards, my old ones seem to have issues.
Might have to start getting industrial grade SD's.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

Heater
Posts: 13678
Joined: Tue Jul 17, 2012 3:02 pm

Re: Is Python the only smart choice for micro-controllers?

Fri Jun 16, 2017 3:14 am

Gavinmc42,

That was an update on the Raspbian Lite of 2017-04-10 that I installed on a new Pi yesterday.

Where on earth do you buy 128MB SD cards? The smallest I have in my junk pile is 4GB.

PiCore Linux OS sounds interesting. Not so much because it is tiny but for it's running from RAM, read only boot media.

Is there anyway to run node.js, install git and so on with PiCore?
Memory in C++ is a leaky abstraction .

ghans
Posts: 7876
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Is Python the only smart choice for micro-controllers?

Fri Jun 16, 2017 4:57 am

Does the official Linux CLR even work under Raspbian ? I know that Mono is available , but hasn't Microsoft
released their offficial Linux source code recently ?

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

User avatar
rpdom
Posts: 15419
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Is Python the only smart choice for micro-controllers?

Fri Jun 16, 2017 5:37 am

Heater wrote:Where on earth do you buy 128MB SD cards? The smallest I have in my junk pile is 4GB.
I haven't seen anywhere other than eBay for cards that small recently, but I have plenty of 2GB and 1GB SD cards and even a 16MB one.

User avatar
Gavinmc42
Posts: 3921
Joined: Wed Aug 28, 2013 3:31 am

Re: Is Python the only smart choice for micro-controllers?

Fri Jun 16, 2017 7:52 am

I sort of inherited two Kingmax Platinum 128MB SD's with the job 8yrs ago :o
256/512MB Micro SD's I get from old phones and MP3 players.

Single Level Cell cards seem to be more reliable, but pretty much useless for Raspbian because they are small capacity.
Most of my original 2-8GB SD cards are smashed, cheap cards, cheap plastic, except for the 128MB's.
MicroSD's are much tougher, but my Raspbian Dev Pi3's boxes boot 32GB USB sticks.

If it is on this list it will work with PiCore, Node and Git are there.
http://tinycorelinux.net/9.x/armv6/tcz/
The TC desktop is not bad, more usable than pretty.

With shell script and Micropython lots can be done with 700+MHz Pi's :lol:
I really only need busybox-httpd.tcz as the only extra install, it does the web serving.
Linux + busybox, er not that secure :oops:
Hence the porting to Ultibo.

Read only boot PiCore, yep rock solid, runs for years and it boots fast.

16MB would be nice for Ultibo, but I think 256MB uSD is the smallest SLC now :lol:
Maybe SPI FRAM/MRAM/eeprom booting?

Having trouble with my early 4-8GB uSDs with Raspbian now, they get recycled to piCore boxes :D

Linux CLR, is that .NET stuff?
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

YCN-
Posts: 246
Joined: Fri Jun 10, 2016 3:18 pm

Re: Is Python the only smart choice for micro-controllers?

Fri Jun 16, 2017 7:58 am

tpylkko wrote: Also they have wireless periferials like LTE-M, LoRa or Sigfox and I am not sure how easy it would be to control these with C or assembly.
Well I read the whole topic and I just would like to add something, it's particularly easy to use Sigfox (and I guess Lora) with C since it's not anymore than using a AT modem. So that's definitively not a concern.

But I really don't get that Micro Python stuff. I don't get in what way it would be good to have some python where you can use C in a microcontroller?
I don't understand what people love about python, it's boring, it's messy, it's not precise, it's slow. C is designed the only good compromise with ASM. Why people are so obsessed with Python...? it doesn't makes sense to use it in the embedded world.
It's not even easier than C when it comes to do some really embedded stuff, like memory mapping or io stuff, or IRQ...

YCN-

User avatar
rpdom
Posts: 15419
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Is Python the only smart choice for micro-controllers?

Fri Jun 16, 2017 8:13 am

YCN- wrote:But I really don't get that Micro Python stuff. I don't get in what way it would be good to have some python where you can use C in a microcontroller?
C is complicated. I prefer to use the native assembler for micro-controller type stuff.

User avatar
Gavinmc42
Posts: 3921
Joined: Wed Aug 28, 2013 3:31 am

Re: Is Python the only smart choice for micro-controllers?

Fri Jun 16, 2017 8:25 am

I use Pi's for IoT stuff, sensor data loggers and webserving the data

I can ssh in remotely from 100kms away, edit some shell or python and it all keeps on working while I am doing this.
Micropython is not fast but it is a small text file, it can still toggle GPIO at 40KHz.
LoRa has slow data rate, so just updating a small text file, shell script or Micropython or Lua is quick.
I let Linux handle the lower level stuff.

C is great if you don't need to modify code or change stuff in a micro controller.
With Pi's which run faster than microcontrollers, interpreted languages can be useful.
Oh and Python does not need compiling, which can take time.
With C it is edit/compile/test/debug, edit/compile/test/debug, .......
You do that enough times you get annoyed with how long things take :lol:
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

timrowledge
Posts: 1287
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: Is Python the only smart choice for micro-controllers?

Fri Jun 16, 2017 5:38 pm

Or you could run Smalltalk on your Pi, log in remotely, have a real development environment and get all the benefits of a well designed live-coding system. You too can debug the debugger whilst modifying the compiler to fix a problem with your code. It's fun!

Generally a Pi is not a great choice for use as a micro controller, not because it can't do it but because it is probably way more than you need. For small simple jobs use an ESP8266 and have that talk to a Pi set up with mqtt or a similar system.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

Return to “General discussion”