6 ms·
You definitely don't have to write your own an OS. You use existing tools, for example FreeRTOS. It's surprisingly simple. With a microcontroller, you can have
by dcposch 11y ago
You definitely don't have to write your own an OS. You use existing tools, for example FreeRTOS. It's surprisingly simple.
With a microcontroller, you can have a pretty much complete understanding of the whole machine.
All you need is a basic knowledge of C, and most of the people who would solder stuff to a Raspberry Pi already have that or are willing to learn.
Say you're making a thermostat. By convention, you leave address 0x0 empty, since dereferencing the NULL pointer is bad form :) At address 0x4 you have a int containing the target temperature. At address 0x8 you have a int containing the current measured temperature. Your whole app uses 8 bytes of memory, plus a few more for the stack.
You write a loop. It reads a few GPIOs, updates those two values, does a bit of logic to decide whether to turn on the heat, then writes one more GPIO to turn the heater on or off. GPIOs are "general purpose IO", metal pins that can be individually set to, say, +5V or 0V.
The beauty of this is that if you write it cleanly and debug it and test it once, it will work perfectly forever.
It will never throw up a popup that says "a new version of Ubuntu is available". It will never ask you to download 80MB of Java. It will never auto update. The server will never go down, because there is no server.
It feels totally different from typical software development. You're writing a bit of C, but you're not making an "app" with all the complexity and flakiness that entails. You're creating an embedded device.
And a wise man once said... "Hardware eventually fails. Software eventually works."
---
PS, here's a fire alarm that runs Linux.
https://www.youtube.com/watch?v=BpsMkLaEiOY https://www.youtube.com/watch?v=BpsMkLaEiOY
Complexity is cheap now. You can get a full Linux PC with systemd, X11, Gnome, DBus, Java installed, the full works for $5 and in a tiny form factor. You could make a thermostat that way---but just because you can doesn't mean you should!