26

This question asks, amongst other things, if there is a big learning curve between using Python on a Raspberry Pi to prototype an endpoint, and using a microcontroller.

Clearly there is a big improvement in power consumption (at the cost of reduced processor throughput) so there are good reasons to take the MCU approach for a product which needs to be battery powered.

One of the potential reasons to stick with a single-board computer which runs Linux is that there is no new software to learn (above python or similar) assuming the application can be written in a high level language (where there should be plenty of standard libraries).

On an embedded development platform, the likely choices are C++ (mbed or arduino), or micropython. My impression is that these are not significantly different or more complex than writing code to run under Linux - although the platforms do have individual advantages. Have I missed anything which is relevant to a software developer?

Specifically, I'm asking about IoT endpoints - so it's not essential to have the full resources of a Linux system for the applications I'm interested in here. It's also worth emphasising that power and latency considerations make the mcu implementation a hard requirement in this type of application.

6 Answers 6

12

Adding to George's comprehensive answer and point 2) hardware support. Even if the desired hardware (e.g. ethernet, WiFi, SD card) is added to the microcontroller/Arduino via shields or similar extension boards the libraries to operate them are putting quite a strain on the small memory (i.e. ATMEGA328 (a typical Arduino controller) has 32Kb of FLASH and 2Kb of RAM). Especially when combining multiple features (networking, display, SD card) this can be a severe limitation.

A few examples from the Arduino world:

Supporting an SD card and a simple filesystem (FAT):

  • SD cards (code size unknown but likely not that big an issue if hardware SPI is used), at least 512 bytes RAM buffer
  • Petit FAT FS requires ~ 2..4 kB FLASH and ~44 bytes of RAM

Using a matrix display:

Ethernet with TCP/IP protocol stack:

  • uIP: RAM requirements in the range of a typical packet size (>1 kB), though, single-chip Ethernet controllers typically come with on-chip buffer that can hold a few max sized Ethernet frames.

    It is possible to run the uIP implementation with as little as 200 bytes of RAM, but such a configuration will provide extremely low throughput and will only allow a small number of simultaneous connections. (Source.)

  • IP stack with TCP and UDP protocols for Arduino: minimum of 128 kB external memory

  • IP over serial interface: SerialIP ~9 kB FLASH and "enough" RAM

All in all, programming with those limitations requires quite a different approach and calls for optimisation with respect to program space and code size (FLASH), runtime data (RAM), and execution speed. This answer has it fleshed out nicely.

As the question specifically asks about the mbed platform it is of course noteworthy that it includes features most relevant to IoT, namely connectivity along with encryption, authentication, and authorization. It supposedly offers hardware support of Bluetooth Low Energy and IPv6 over Low power Wireless Personal Area Network. Though these connectivity features are only available on the listed development boards with typically >= 128 kB FLASH and >= 16 kB RAM. The smaller dev boards on the other hand include systems with as small microcontrollers as the ARM Cortex-M0+ Core with 16KB Flash, 4KB RAM (i.e. not that much more than medium sized Arduinos) without dedicated connectivity.

1
  • Resource constraints was the biggest gap in my assumptions - easy to forget most people develop without these issues most of the time. May 2, 2017 at 9:27
20

It depends on what you're trying to do.

  1. The biggest gap is that a microcontroller you mentioned (such as Arduino) does not run a multitasking operating system such as Linux. This means if your application depends on multitasking or multithreading, this may be much harder or even impossible to run on Arduino.

  2. The second gap is hardware support. For example, Raspberry Pi supports cameras, USB audio, ethernet, WiFi out of the box. None of that is supported directly by Arduino, and while you can use various shields (such as USB Host, Ethernet or WiFi), using them is not as straightforward as using networking on Raspberry Pi.

  3. The third gap is resources available. Most microcontrollers don't come even close to the resources Raspberry Pi offers. For example, even the first Raspberry Pi offered a CPU running at 700MHz with 256Mb of RAM and could be used with 32Gb of storage. A typical Arduino Uno based on ATMEGA328 is running at 16MHz, and has 32Kb of storage and 2Kb of RAM.

So using Raspberry Pi is definitely much easier for developers coming from PC. The main advantages of using microcontrollers are:

  • costs (a Chinese clone of Arduino Nano costs less than $2 a piece with shipping)
  • power consumption (microcontrollers could be optimized really well for low power consumption - important if you have to run on batteries);
  • real-time availability, i.e. ability to react on signal change in realtime;
  • size (Arduino Mini is twice narrower than Raspberry Pi Zero, and if you don't need that many pins, ATTINY85 size is less than a penny, and it works without a crystal).

If none of those are important, using Raspberry Pi definitely makes more sense.

5
  • 3
    Battery power, and no great resource requirement are the drivers for using an mcu - so I'm assuming a 10-100 MHz processor is enough. Valid point on using peripherals, although SPI is probably the mcu equivalent of USB. Apr 30, 2017 at 22:47
  • 2
    Just having a bus is not enough. Consider using WiFi on Linux, your app doesn't need any specific knowledge about it, same code which works with Ethernet will work with WiFi interface. This is not the case with microcontrollers, you'd have to use different libraries, learn how to use them, and change the code.
    – George Y.
    May 1, 2017 at 0:22
  • 1
    OK, didn't realise that using a different library would be much of a barrier. May 1, 2017 at 8:45
  • 2
    If you don't need many pins, you can get an ATtiny4 that is the size of a grain of rice :P
    – Nick T
    May 1, 2017 at 19:27
  • 1
    its apparently not much smaller than Attiny85 :) but you're right, if we're thinking non-DIP, even 85 is a fingertip.
    – George Y.
    May 1, 2017 at 22:55
9

YES, it is a big jump from programming in Python to programming using the typical C-based language tools on micro-controller. In fact, in many cases you may need to write some, if not all, of your application in assembly language.

As already pointed out in the other answers, micro-controllers are very much resource constrained and thus you lose all the conveniences of a Linux operating system and all the tools that you can run locally. Iterating with the Arduino IDE is very slow compared to running local scripts.

Although I have a great deal of professional experience with micro-controllers and microprocessors, I prefer to run my personal projects using RPi hardware with some Arduinos for real-time critical stuff. I have also dabbled with Beagle Bone Black and in some ways it is more convenient than using a RPi with one or more Arduinos.

9

Yes, big difference

The difference is like day and night, both in regards to hardware and software. No valid comparison at all.

When to use which

Use an Arduino, if...

  • Space constraints make a Pi infeasible.
  • The power usage of a Pi would be too much.
  • Money is an issue (especially if you need several or many individual controllers in your project, each one performing very simple logic only).
  • You want to get nitty and gritty and work on a much lower level for fun or for gaining knowledge.
  • You need extreme simplicity and/or 100% defined real-time behaviour and zero chance that something out of your control kills your program.
  • You do not need ethernet, difficult USB-host functionality (i.e., accessing hard drives; using it on the client side, e.g. as a HID device, is OK) and so on. Most of these can be fitted to an Arduino (verrry slooowly), but at a high cost in terms of RAM/EPROM and also functionality. As there is no preemptive multitasking, unblocking tasks gets quite complicated very quickly.
  • You are OK with the simplistic Arduino development IDE, or with digging much deeper (i.e., building the programs yourself), and - if you are not going for a USB-upload device like the Pro Micro - a bought or self-made development kit/burner.

In all other cases, a Pi is vastly more user friendly. The Pi is simply another (slow) computer.

Don't get me wrong. I own a Pi and use it for several Linux services in my network. I also frequently program Arduinos (Pro Micros mostly). Both are great, I like them the same, but they have very different usage scenarios.

On your question about difficulty - it is relative. The only time the Arduino got difficult for me were hard to debug timing issues, especially if combined with questionable electronics (i.e., EM interference, too long cables etc.). If you are firm in your language of choice (i.e., C for the Arduino IDE), then you should be able to hack any libraries you are employing. Still, it will always be more complex then a Pi, where you can for example use a scripting language of your choice for non-timing-critical things - those will always be more easy to develop and debug in.

2
  • I'm not asking which is the best development platform - my use case requires an mcu, primarily because of power constraints. I see the question wasn't too clear on this point though. May 2, 2017 at 9:18
  • All right, then the first part of the answer would suffice. I'll let the rest stand as "addendum" if you like.
    – AnoE
    May 2, 2017 at 13:30
7

I believe there are a few points that haven't been specified explicitly yet.

The development environment is completely different. You can actually develop Pi software ON the Pi—you can even use a GUI if you like. There are advanced debugging tools built in as well as—well an awful lot of what is available for any computer system.

The controllers are going to have to be developed/emulated on a separate computer then sent to the controller for final testing.

The Pi can run virtually any language you want to program it with, micro controllers will typically have one or two.

The Pi can run quite a few operating systems (Including windows IoT and a bunch of specialty systems), embedded controllers tend not to run an "Operating System" at all.

Also as far as runtime/OS goes—the Pi takes a few seconds to boot—if you want to actually do something in those first few seconds then the pi won't work for you. Also unless you went to some extreme measures to prevent any writing to storage whatsoever, you really shouldn't just remove power, you have to execute a "Shutdown" and wait a little bit. This may also limit some usages.

Another post-deployment point I haven't seen mentioned. I'm not sure how I'd be absolutely sure that I properly secured a Pi—that no agency has stuck a little piece of code somewhere that allows unauthorized access under certain circumstances—without removing it from all networking and disabling all wireless access mechanisms. Micro controllers are fairly easy to secure since you are writing nearly all the code running on the thing.

Of course, you could always develop your own Pi image with no real OS and take over the entire board/CPU which would pretty much make it into a hella-powerful/expensive micro controller with all the associated advantages/disadvantages. Someone has probably even done this already but I haven't looked for anything like that lately.

1
  • WRT your last paragraph, yeah, that's called bare-metal and few people do it but technically it is possible... welcome to the site!
    – Ghanima
    May 1, 2017 at 21:03
3

The difference between developing an application with a Pi can be very different or somewhat similar to developing an application with a microcontroller due to hardware differences as well as software development toolchain differences.

There are a wide range of microcontrollers available that are anywhere from 8 bit to 64 bit processors and having anywhere from a few K of RAM to a few gigabytes of RAM. More capable microcontrollers provide a more Pi like experience. Less capable microcontrollers do not.

And even with the Pi there are large differences between developing for the Windows 10 IoT operating system versus developing for Raspian, Mate, or other Linux based OS. Windows 10 IoT requires a development PC using a Visual Studio toolchain with remote debugger targeting the Universal Windows Program (UWP) environment. Development for Raspian or Mate can actually be done on a Pi with the tools available on the Pi.

The Constrained Application Protocol is used for small, constrained devices being used with the Internet of Things environment. To get an idea of the variety of microcontroller hardware and software, this page on the CoAP protocol implementation provides an idea of the environment it is targeting. It mentions the Contiki operating system which I have vaguely heard of along with better known OSs such as iOS, OSX, and Android. Programming languages mentioned are Java, JavaScript, C, C#, Ruby, Go, Erlang, Rust, and Python.

The tool chain used for development with microcontroller varies depending on the manufacturer as well as what kinds of resources are available from development communities and open source initiatives. In some cases you get a cross assembler, in other cases you get a C cross compiler, and in other cases you get a nice tool chain with all the bells and whistles and emulators and such similar to the Visual Studio toolchain for Windows 10 IoT.

The actual development environment for a microcontroller may involve using an EEPROM programmer and the software tools to create a new image and push it to the device or the device may have the necessary connectivity to allow a new image to be downloaded over a serial connection or over a network connection.

My impression is that most microcontrollers have a C cross compiler though the compiler may only support older standards such as K&R or maybe C98. C cross compilers often have non-standard keywords for microprocessor specific features for example the far and near keywords for pointers with the old 8080 and 8086 processors with their segmented memory.

There are also specialty languages that target microcontrollers such as FORTH programming language. These languages often have a run time design that targets the bare metal so that there is no operating system other than the language run time.

Operating system may range from practically non-existent to a bare bones Linux to a specialty OS such as freeRTOS or Windows Embedded or a full blown Linux or Microsoft Windows. See this SourceForge project MINIBIAN for Raspberry Pi. See as well this eBook, Baking Pi: Operating Systems Development which describes the development of a rudimentary OS for Raspberry Pi in assembler.

This article from Visual Studio Magazine, Programming the Internet of Things with Visual Studio, provides an overview of the many different devices available followed by an overview of using the Visual Studio IDE for development for Linux as well as Windows.

There's a huge and growing universe of off-the-shelf, programmable, networkable microcontroller devices available now. At a very low level you have a variety of simple 16- and 32-bit devices from a variety of traditional chip makers like Texas Instruments. (I played a bit with the SensorTag development kit and it's a lot of fun, making me think the Watch DevPack might be a great learning toolset, too.)

Some better-known microcontroller devices include Arduino, BeagleBoard and Raspberry Pi. These environments all have extensive community support and are ready to plug in to a huge number of ready-made external sensors, motors, servos and whatever else you might imagine. Adafruit, the electronics learning superstore founded by Limor "Ladyada" Fried, provides all sorts of peripherals for these boards, along with its own line of lightweight Feather development boards.

...

The most interesting universe of devices for developers familiar with the Microsoft .NET Framework and Visual Studio may be Windows 10 IoT Core-compatible environments. These are x86 and ARM-powered devices that support Universal Windows Platform (UWP) apps written in a variety of languages including C#, Visual Basic, Python and Node.js/JavaScript. Windows 10 IoT core supports devices including Raspberry Pi, Arrow DragonBoard 410C, Intel Joule and Compute Stick and MinnowBoard. There are also interesting product platforms, such as the Askey TurboMate E1 wearable.

A Specific Example of a Microcontroller application

This is an image of a microcontroller board from an automated coffee maker. This appears to be a standard component for automated coffee makers manufactured in China. The web site for the manufacturer is printed on the PCB.

The image is composed of two views. The view on the left is the back of the board containing the microcontroller and supporting circuitry. The view on the right is the front of the board with the LCD screen and a set of buttons which are used to set the current time and to perform actions such as programming a start time, etc.

The view on the right fits into a carrier which then fits into an opening in the front of the coffee maker. The switches on the lower PCB are actuated with rocker arm switches. The LCD, which seems to be special purpose, is used to display the current time and status as well as to display the user interface when changing the settings of the coffee maker. The red LED is used to indicate when the coffee maker is actually making coffee and to indicate when done by turning the illumination back off.

enter image description here

The microcontroller is an ELAN Microelectronics Corp EM78P447NAM (datasheet) which is an 8 bit microcontroller. Some of the basic stats show what a small and minimal device this is however it works nicely for its intended purpose. The intent is to develop software which is then downloaded into the write once ROM as a part of manufacturing.

• Low power consumption:

* Less then 2.2 mA at 5V/4MHz

* Typically 35 µA, at 3V/32KHz

* Typically 2 µA, during sleep mode

• 4K × 13 bits on chip ROM

• Three protection bits to prevent intrusion of OTP memory codes

• One configuration register to accommodate user’s requirements

• 148× 8 bits on chip registers(SRAM, general purpose register)

4
  • 2
    I don't think this addresses the question. Sure, some products are not well packaged, but that goes for an SBC too. Oct 15, 2017 at 17:23
  • 1
    @SeanHoulihane what I have tried to do with this answer is to provide a microcontroller viewpoint on the question, specifically that there are a wide range of devices that meet the microcontroller label. There is more to the OS landscape than Linux and there is more to the programming language than python or C. Oct 15, 2017 at 17:32
  • 1
    To me, you're just saying the MCU world is a mess. Which I feel is misleading. Oct 15, 2017 at 17:35
  • 1
    @SeanHoulihane I am sorry that your impression from my post is that the MCU world is a mess. Another interpretation is that the MCU world is one of many wonderful alternatives and opportunities however the reader brings their own biases and prejudices to any narrative. Oct 15, 2017 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.