
The amazing $1 microcontroller (2017) - appwiz
https://jaycarlson.net/microcontrollers/
======
jwr
Contrarian view: these days I don't care how much a microcontroller costs. In
quantities I'm designing for, it doesn't matter, and the cost is dwarfed by
the cost of my time writing the software.

I've spent a lot of time dealing with crappy and broken vendor libraries,
erratas, SDKs and toolkits where the vendor changes their entire strategy
every year or so, and I'm tired. At this point I wrote (I thnk) three I2C
libraries for various devices and systems (they're on github) — I should never
have to do that!

These days I mostly use Nordic chips — not only does almost every device I
design need BLE these days, but the chips are fairly nice, the SDK is
developed, maintained and supported, and there is a refreshing feeling of
sanity. Sure, a BMD-300 or BMD-350 module with an nRF52832 will be $10 instead
of $1 or $2, but I will save so much time and frustration, that it's
definitely worth it!

A vendor starting to officially support Rust might change my perspective, but
to this day I haven't seen any other vendor take software as seriously as
Nordic does.

~~~
dalbasal
Good points all.

I think this highlights how important adoption curves, cost curves and volume
are to the overall context.

Going from $1000 to $100 can put something into the hands of experimental,
hobby or light-commercial projects. It can enable new applications. These can
be fundamental to setting an overall direction. Going from $10 to $1 is
neither here nor there in those contexts. Cost, as you say, is virtually
irrelevant unless/until volume is very substantial.

Volume is not usually part of the early adopter game, and price, below a
certain threshold is only relevant at high volume. Price (below some
threshold) may never be a meaningful factor for a microcontroller built to
control commercial lighting systems or whatnot.

The old habit is that price _really_ matters. As prices dropped, this opened
up entirely new uses for microcontrollers. Applications that would have been
unreasonable at $100 became possible @ $10. That's not the dynamic anymore.

~~~
rckoepke
There are things I would build many of if they cost $2 instead of $20. Say a
medium-resolution 3D volumetric mapping of temperature and humidity in my
house becomes reasonable at $2/node, but not at $20/node. I think scale still
applies at this level, but fewer hackers are thinking in terms of swarms.
There are transformative applications at scale that could be interesting even
to individual hackers, but scale is its own niche, just as IoT in general is a
niche.

~~~
mkl
Interesting idea. How would you power a swarm like that?

~~~
jwr
Great point :-)

I don't know how to build an $2 device. Especially given that in any small
device I've designed, power management always took 30-60% of board space and
device cost. You reach the upper bounds if it uses a Li-Po battery.

There is a big gap between powering a hobby device from a bench power supply
and building an actual end-user solution.

EDIT: I'm reading the answers here and it's clear I did not clearly
communicate what I meant. Taping a board to a bunch of AA batteries is not an
actual end-user solution. Neither is hanging a couple of boards off a bunch of
wires. I was talking about products, something you might expect to pull out of
a retail box and use.

Those mentioning PoE clearly haven't designed a device that is powered with
IEEE 802.3af-2003 :-) (I have, and I have the battle scars to prove it). PoE
doesn't mean you can just connect the wires and call it a day.

~~~
michaelt
In a way designing a $2 device is simpler, as the low price means a low
component count.

Having built a Dash Button clone with an ESP8266:

1\. Choose a microcontroller that will run on <3 volts, and power it directly
from two AA batteries in series. You have neither the power budget nor the
financial budget for anything more complicated than that.

2\. Your microcontroller should spend 99.99% of its time in its lowest power
sleep mode. When sleeping, the microcontroller should consume <10μA and the
other, non-microcontroller circuitry should consume the same amount.

These are rock-bottom power levels, expect to remove any status LEDs, USB-
serial converter/in-circuit debugger chips, and even linear regulators
compared to a development kit.

You don't have to use an ESP8266 like I did - a more experienced guy might
have chosen an MSP430 or something similar.

3\. Given you can only leave sleep mode 0.01% of the time, i.e. 8 seconds per
day, if it takes 1 second to connect to wifi, send a message and get an
acknowledgement back, you can only do that 8 times per day. If you want to
update more often, you'll need something faster to connect and send a message.
This is why many smart home systems use 433MHz to a base station, rather than
using wifi directly.

4\. A $2 budget won't include a case until you're making fairly serious
volumes. Repurpose something you were throwing out, or wrap it the circuit in
electrical tape, or go over budget but declare victory as you could hit the
target in larger volumes.

~~~
twic
For cases, matchboxes are ~20p a go: [https://www.ebay.co.uk/itm/SET-50-PLAIN-
WHITE-EMPTY-MATCHBOX...](https://www.ebay.co.uk/itm/SET-50-PLAIN-WHITE-EMPTY-
MATCHBOXES-WITH-DRAWER-FOR-CRAFT-FAVOURS-ADVENT-7080-/391442753163)

You might struggle to get an AA cell in them, though.

------
lttlrck
I have such a soft spot for PICs, specifically the 16F84

20 odd years ago when I didn't know any better and work was boring I built a
universal remote control - and put it in a PSX controller case. This was all
coded in assembler which I still have, programmed with a DIY adapter that ran
off a parallel port. So much fun. I used this for a few years.

Outside:
[https://www.dropbox.com/s/0w9c61e3mfdc3lw/Photo%20Oct%2026%2...](https://www.dropbox.com/s/0w9c61e3mfdc3lw/Photo%20Oct%2026%2C%2008%2023%2058.jpg?dl=0)

Inside (I have no shame):
[https://www.dropbox.com/s/jep4rzz377h1svo/Photo%20Oct%2026%2...](https://www.dropbox.com/s/jep4rzz377h1svo/Photo%20Oct%2026%2C%2008%2028%2024.jpg?dl=0)

Video:
[https://www.dropbox.com/s/45q3uk6cgw9ti46/Video%20Oct%2026%2...](https://www.dropbox.com/s/45q3uk6cgw9ti46/Video%20Oct%2026%2C%2008%2039%2010.mov?dl=0)

The video was made earlier in the year, I was curious if it still worked....
not so shabby.

Version 2 had a touch screen. That's still lying around somewhere.

~~~
iainctduncan
Oh me too! Springer had an amazing book on PIC16F84 programming that was my
self taught low level coding education. Pre-Arduino, the PICs were the bomb,
you could order free samples, download the compiler free, and build a
programmer for like $20 in parts. Fond memories!

~~~
woadwarrior01
Me too! My dad bought me a PicStart Plus and a bunch of PIC16F84s for my 15th
birthday. I tried to badger him into buying me the Hitech-C compiler, but he
never budged, so I was stuck with assembly. But that was a good thing, in
hindsight. :)

~~~
iainctduncan
btfsc ftw! ;-)

------
cristoperb
Last year's discussion of this article[1] is the 7th most favorited Hacker
News submission ever[2].

1:
[https://news.ycombinator.com/item?id=19851744](https://news.ycombinator.com/item?id=19851744)
2: [https://observablehq.com/@tomlarkworthy/hacker-favourites-
an...](https://observablehq.com/@tomlarkworthy/hacker-favourites-analysis)

~~~
dang
There was also a big thread at the time:
[https://news.ycombinator.com/item?id=15633785](https://news.ycombinator.com/item?id=15633785)

------
egsmi
$1. Ouch. Too rich for me. I use $0.03 MCUs!
[https://hackaday.com/2019/09/09/everything-you-wanted-to-
kno...](https://hackaday.com/2019/09/09/everything-you-wanted-to-know-about-
padauk-mcus-and-more/)

~~~
azinman2
I’d love to know how it can so cheap to make and still be profitable? What
environmental / labor horrors need to occur?

~~~
nfriedly
It looks like they mostly drove the price down by reducing functionality.
There are no "fancy" interfaces like UART or i2c. There's only 64 bytes of
RAM. The chips are one-time programmable which is cheaper than flash memory,
and there's only 512 bytes of program space. The CPU is pretty limited too -
it doesn't even have an instruction to multiply two numbers. There's no
debugging interface on the chip, instead you buy a simulator device that
behaves like the chip, but has reprogrammable memory and a debugging
interface.

It all adds up, or in this case it doesn't, and what's left is a pretty
inexpensive chip.

------
noncoml
Big fan of STM32 family for the simple reason that you can use mature open
source tools, i.e. gcc toolchain, or even clang, for development.

~~~
bgorman
Isn't that the case for virtually all embedded ARM chips?

~~~
sitkack
No. If you look at an STM32 manual, they can be > 1k pages as you need that
much information including the errata to truly use a part. MCUs with < 100
page manuals will rely on YOU finding the bugs and working around them.

~~~
duskwuff
Even with STM32, there are some peripherals that can be difficult to use
without careful reference to the application notes, errata, and/or ST's sample
code. The I2C peripheral on the STM32F1 is a prime example -- if you don't
read/write certain registers in precisely the right order, the peripheral will
lock up or return incorrect data.

On the whole, though, you're absolutely correct. :)

~~~
sitkack
In further agreement, part of getting to know a new MCU is to breakdown your
project into a series of small conformance test suites and at the same time,
trying to get into the mind of the peripheral designers. Delays in config
registers, changes not becoming visible until some other action. Weird
interrupt behavior, timers, capture compare, reset, brown out, etc. They all
have issues, and one can't just assume that _anything_ works. Everyone blinks
and LED, sometimes multiple times on the same project. The firmware you use to
debug the chip and the system is the stuff that keeps you sane.

Design systems for visibility and debugability. Multiple color leds, extra
serial ports, extra flash to dump memory to, an external control MCU that can
handle DFU, serial port access, monitoring, etc. Use the largest memory part
that has the same pinout. Building a project that is going to ship qty < 100
with the smallest, most resource constrained parts is a foolish thing. Spend
an extra $2 and get >256KB of ram. Get remote debugging working in the first
week. Automate relentlessly.

------
ChuckMcM
It is truly amazing what you can get these days.

If the author had compared an Cortex M0+ part [1] there are lots available for
< $1.

For me, the ability to use command line gcc and editor on Linux to program and
debug these things is the real win. I know the new kids all want a fancy IDE
but I get from starting vim on a blank screen to running blink in about the
same amount of time it takes eclipse to start up.

Back in the day (2002) I like the PIC16F628 and even designed a board for
it[2] but pretty much now I can't stand to program them.

[1] From 2012 -- [https://www.electronicproducts.com/a-look-at-
cortex-m0-and-m...](https://www.electronicproducts.com/a-look-at-
cortex-m0-and-m0-microcontrollers/#)

[2]
[http://www.mcmanis.com/chuck/robotics/projects/wsm.html](http://www.mcmanis.com/chuck/robotics/projects/wsm.html)
Free PCB for that project to anyone who has postage ($1) :-) contact in my
profile.

~~~
danellis
> I know the new kids all want a fancy IDE

What makes you think it's "new kids" that want to use IDEs? They're an
incredible useful tool, even more so for experienced developers.

~~~
jononor
Experienced people usually want to use their preferred IDE. The IDE experience
easily available for microcontrollers is usually 1-3 specific IDEs provided by
the vendor - rarely the same thing.

------
ncmncm
What I want to know about a microcontroller is, (a) can I use Make/Gcc/Gdb to
develop for it without a lot of guesswork, and (b) what is its interrupt
latency? The article only hinted at (b) for a couple of them, and said
practically nothing about (a). IDEs are a trap.

~~~
jhallenworld
I recommend STM32CubeMX: this is a GUI tool that creates a gcc/ makefile
project for any of their micros- so you only have to use it once to set up an
example "hello world" project. No IDE is needed (older versions only generated
code for IDEs, but no longer).

If you follow the comments in the generated source code you can keep your code
separated from their code. The advantage is that you can reconfigure your
project later- for example to change microcontrollers, or enable new
peripherals.

~~~
SV_BubbleTime
I tried but HATED my code being stuffed between comment blocks of

//USER CODE GOES HERE//

There were four or five of those blocks in my main alone. It’s a dumb thing
but was driving me nuts.

If you break your code away from there’s ASAP it’s probably better.

------
justinclift
As the article itself is undated, it's hard to tell how old this info is.

Looking at some of the follow up comments at the bottom of the article,
they're from 2017 onwards.

So, the article itself may be becoming dated at this point.

~~~
elasticventures
This article is very out of date.

I used it for research in a project month ago and found many of the chips it
mentions are end of life / discontinued now. The prices of those chips (if
available) are actually higher due to their shortages.

Realistically very few fresh project starts look at the cost of the controller
(in fact most EE's are completely abstracted from it) and put more
consideration toward E2E LTMC costs which includes things like firmware
updates, wifi or network diagnostics, etc. I see a lot of companies going
towards Linux-os and RaspberryPI-esque clones simply for the ease of
development and debugging -- except when power, heat or space are important
factors.

At this point the Amtel ATMega & STM32 chips pretty much dominate the
hackerspace projects thanks to the libraries and strong ecosystems. As near as
I can tell all the other vendors are a rounding error in marketshare of new
product starts. __Note: I 'm excluding things like auto and appliances along
with other entrenched industries who probably consume a ton of those $1 chips
because they've already invested heavily in them 10+ years ago.

------
torgoguys
I've read this article before and it is great, but needs a [2017] tag.

------
ilaksh
Seems like he didn't mention ESP8266 or anything like that. At that time it
wasn't $1, but I do see some around that price on Aliexpress now.

~~~
teleforce
The latest version ESP32-S2 costs $1 (99 cents to be exact), and now supports
LCD interface and USB OTG!

[https://maker.pro/esp8266/tutorial/a-comparison-of-the-
new-e...](https://maker.pro/esp8266/tutorial/a-comparison-of-the-new-
esp32-s2-to-the-esp32)

------
sunsetSamurai
Dumb question, but how do you learn to work/program for these things? any
reading material I can look at? I started learning C this week and this looks
very interesting.

~~~
embedawayz
You can write ordinary C code to run on them. You just need a separate
compiler/linker/etc. because they have a different CPU architecture than your
computer. For an ARM Cortex-M chip, you can use the `arm-none-eabi` GNU
toolchain:

[https://developer.arm.com/tools-and-software/open-source-
sof...](https://developer.arm.com/tools-and-software/open-source-
software/developer-tools/gnu-toolchain/gnu-rm/downloads)

But when you write a program for a microcontroller, you don't have an OS
kernel, so your code needs to include drivers for anything that you want to
communicate with.

It's a little outdated, but I like this introduction to STM8 chips (which this
article also mentions) as a quick crash course on embedded C:

[https://lujji.github.io/blog/bare-metal-programming-
stm8/](https://lujji.github.io/blog/bare-metal-programming-stm8/)

~~~
nerfhammer
term is "cross-compiler"

[https://en.wikipedia.org/wiki/Cross_compiler](https://en.wikipedia.org/wiki/Cross_compiler)

------
aequitas
I think the IDE's are highly overrated. Some may provide good product specific
documentation, autocomplete, flashing and debugging. But most of the times
they are highly opinionated programs with their own quirks and annoyances you
need to work around to get your code running on a chip. I would be sad to have
to turn down a good chip because it has a bad IDE.

I much more prefer good support for opensource framework's like platformio[0].
This way it hardly matters which specific chip I'm using, my workflow is
mostly the same. And I can use the same editor, tools and methods I already
use for developing all my other code without having to learn the quirks of new
tools.

[0] [https://platformio.org/boards](https://platformio.org/boards)

------
snvzz
This article left me wondering: Are there no options left with 68000 family
CPU?

~~~
duskwuff
Not in this price range. The only parts from that family left in production
are the ColdFire series, which are more expensive (starting at around
$1.60@1k) and have unimpressive characteristics compared to other options (50
MHz with poor IPC, limited memory size, minimal peripherals). And even those
are on their way out -- the product line hasn't been updated in ages, and NXP
has shifted its focus to ARM.

~~~
AnimalMuppet
Still, $1.60 isn't bad for a 68000. Some of the chips in the article are spins
on the 8051, so the 68000 is a big step up from them. Now, true, you can get
every peripheral imaginable in an 8051 spin, and often for that $1 price, but
the 68000 has a lot more functionality as a CPU.

------
Lerc
It frustrates me that the AVR architecture is so good and yet so poorly
speced, I would really like to see something that had the RAM size and Clock
speed of some 32 bit controllers. Sometimes when you want to just throw some
bytes around, 8-bit is best.

It would have been fun if Logic Green had made a high end variant of the
lgt8f328 were they stuffed it full of RAM (like 48k) It has more one clock
instructions than the ATMega and 32MHz from an internal osc.

------
rkagerer
I was just looking at this article the other day, and wondering if there's an
update or if anyone knows of a good, similar rundown for 2020.

------
pacoverdi
The site must be running on a $1 microcontroller, it takes 30s to display
anything but a spinner :)

------
zoobab
WCH CH552G programmable chip is 30 cents:

[http://www.zoobab.com/ch552g-blink](http://www.zoobab.com/ch552g-blink)

------
baybal2
I'm surprised to see Padauk MCUs being overlooked

~~~
smarx007
Padawhatnow? This should answer your question why it was overlooked.

And here is a link to the same author covering Padauk MCUs for people like me
who have never heard about those despite having a degree in an embedded-
related field: [https://jaycarlson.net/2019/09/06/whats-up-with-
these-3-cent...](https://jaycarlson.net/2019/09/06/whats-up-with-these-3-cent-
microcontrollers/)

~~~
baybal2
They are very big in the under $1 category

------
flyinglizard
This article is great, but misses the mark by focusing on this arbitrary $1
price point. For a hobbyist, a dollar or ten is all the same. These very cheap
chips are intended for high volume applications, far from the realm of DIY.

If you’re doing a hobby project, take something off the top of the line.
Having all those peripherals and compute power is just one thing less to worry
about.

~~~
ethbr0

       Limit resource to
       Sweep mental complexities
       Away, like fall's leaves.

~~~
polishdude20
Beautiful

------
rimliu
Can anyone recommend some resources for the absolute beginners?

------
nickthemagicman
Do any of these have the ability to be used as a forward proxy?

~~~
tyingq
ESP32 would likely be the easiest path. WiFi on the boards, and an available
ssh client library.

But for a proxy, maybe you would want an actual microprocessor instead of a
microcontroller. Pi Zero W or similar.

~~~
coronadisaster
You can use an ESP8266 as a wifi router for up to 8 clients at 5mbps each I
think which is really impressive so it should be able to do that... I used
that for the kids in the car so that they can play games together

[https://github.com/martin-ger/esp_wifi_repeater](https://github.com/martin-
ger/esp_wifi_repeater)

~~~
squarefoot
There's a partial port on the ESP32. It seems lacking many features over the
ESP8266 one, though the project is a lot younger.

[https://github.com/martin-ger/esp32_nat_router](https://github.com/martin-
ger/esp32_nat_router)

I recall that somebody found that the ESP8266 (no info about the ESP32) can
talk directly to Ethernet devices, albeit it lacks a proper PHY with
magnetics.

[https://github.com/cnlohr/espthernet](https://github.com/cnlohr/espthernet)

It could be handy to avoid using the same WiFi subsystem both to connect to
the WAN and to accept connections from all clients, which I believe has a huge
performance impact.

Now what if we wanted to overcome the speed and number of users limitations by
connecting two or more ESP boards in a magnetic-less way, either crossing tx
and rx pairs in case of two chips, or using a switch chip such as the RTL8306
to connect more than two ESPs? I think it would be possible. More as an
exercise though, since costs would raise to reach many already made products.

------
ineedasername
Edit: I forgot about inexpensive arduino nano boards. I'll leave my original
incorrect comment below though.

Is this supposed to be geared towards hobbyist? If so, the $1 cost is sort of
irrelevant if you have to spend $20 to $100 on programmers, development board,
etc., when you can get a Pi Zero for & micro sd card for about $10 and be up &
coding in an hour.

~~~
thisgoodlife
No, you don't need $20 programmers. I played with attiny85 microcontrollers in
my pet projects. A $2 Arduino Nano is all it takes to program the chip.

~~~
sgt
Arduino Nano seems to be closer to $20 rather than $2. Where did you get that
figure from?

~~~
krallja
Arduino is open-source. AliExpress has clones for under $2.

~~~
sgt
For just one unit I will just buy the original, I think, and support the
project.

~~~
snvzz
If you really want to overpay for what's basically a commodity these days, to
support a project that was already wildly successful a decade ago and has
outside growth several times the size of the original project... go ahead.

