The amazing $1 microcontroller (2017)
jaycarlson.net
jaycarlson.net
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.
I couldn't find a scenario where Wi-Fi would add value as opposed to BLE. It consumes more power, forces you to use TCP/IP, which pulls in lots of complexity without great solutions (you need to deal with pairing, security, etc), is more complex to set up... I could go on. Solutions like Thread are relatively recent (in fact I still don't know if licensing has become more reasonable).
BLE and Bluetooth Mesh give you tons of functionality with low power, in a complete solution. Do I really need my devices to have an IP address?
I guess this depends on what you're building, but in most cases this is about home automation, sensors, lighting, toys, etc.
I saw a few demos d went through their sdk samples a year and a half ago but those were pretty raw then
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.
That means if you are making a new gadget to send out to users, and hoping to make money on data collection, a subscription service, ad revenue, etc., the unit cost of the hardware is critical to the business case, even if it isn't much money overall.
Try telling investors "we made this weather station, and we will make money by selling data to NOAA".
The very first question will be "how much does each station cost", and "how much will NOAA pay". Nobody asks how many engineering hours you spent writing the code to fit on the microcontroller, because the assumption is that in any successful business that becomes irrelevant.
Perhaps investors should accept "Each weather station costs $1000, but we think we can get it down to $10". But most investors won't believe you if you say that...
But to be operative in this way, you must be talking about a very high volume. Millions of units, or close.
My point was not that cost never matters, just that $1000->$100 is not the same as $10->$1. If your weather station startup is using $10 microcontrollers, getting that down to $1 is probably not important. If you are building 10 million weather stations, it is important, but this is a pretty specific scenario that doesn't apply often.
We say something similar with PC pricing. The cost of a functional PC never stopped falling, but that stopped being as important once a certain threshold was reached. Projects like RasberryPi do take advantage of continued cost reductions, but Pi is marginal relative to earlier cost reductions cause an explosion of PC use cases.
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.
Putting WiFi on a sensor makes no sense when you still have to run a power wire.
If you think about it most current IoT stuff blows. You need power for the device. And then you're using shit like WiFi for data. And even worse shit like Bluetooth for configuration. Security is a big big problem because it's brittle and conflicts with consumers need for stuff to just work. PoE solves all of those issues.
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.
You might struggle to get an AA cell in them, though.
It's a matter of extent though, not absolutes. Hobby, experimental & light-commercial applications do not often need millions of units. If they don't, the difference between a $1 & $10 controller doesn't matter in the way the difference between $10 & $100 matters... in more cases than not. Other considerations (eg the dev already knows the more expensive platform, maturity, etc.) can easily override
High-volume swarm applications could change the reality. You need a nexus between low end and high volume. Swarms might be that. These aren't that common though, and "high volume and cheap" is usually a large company thing.
IE, if you browse around kickstarter, most microcontroller applications fit into OP's scenario. The cost of the microcontroller is not that operative. There are undoubtedly some exceptions.
This is a good point. I actually always sort by price when selecting components — not just to be cheap, but also because less expensive components are generally more popular and widely used, which means they are better support, better availability and better longevity.
But — to all those who worry about price — I would suggest looking back and checking how many devices you actually built in the past? Was it singles, tens, perhaps hundreds? At these price points, how much would you save using a $1 uC instead of a $5 uC? Is it tens of dollars? Perhaps hundreds?
Now compare that to the cost of your time spent developing and maintaining the software. At any reasonable hourly rate you pick for yourself, you're probably better off going with the uC that has good software out of the box.
If you decide to build your devices in commercial quantities, that's when price optimization begins to matter, and somebody will care about fractions of a penny. But that somebody won't be you: going beyond single thousands involves a different set of skills.
If you are producing a $40 microwave, smart bulb or somesuch... shaving dollars off component costs is operative. I think this supports your original point rather than detracts from it. This is the mass production game, a mostly big company game.
Microcontrollers have reached a cost point where the dynamic has inverted. The people who need to care about a new, cheaper-than-ever mc are large companies, not startups, hobbyists and niche product designers. There will be lots of exceptions, especially hobbyist use case... but generally.
There is such a thing as cheap enough.
I like the Nordic chips, the event system and DMA is very good. But even their events are abstracted out where you aren’t allow access to the ACTUAL interrupt, you get to send a callback that on ISR they promise to call for you with a context pointer when they allow it (SPI) and when they don’t you are in your own (GPIO event callbacks).
Yes, Nordic does take it “seriously”, but also heavy and complicated. I’d love to see a light implementation of their drivers instead of a HAL that is supposed to cover all models all time. No one actually switches chips like that.
The way I see it is a spectrum: on one end, you go bare metal and write your own startup code, TPM0_IRQHandlers and implement core stuff in assembly (been there, done that). On the other end, you run Linux and who knows what's happening on your extremely complex system and whether it will run at all the next day. I think Nordic is trying to find a balance inbetween.
Nrfx has some stupid decisions made in it. Like #if #define where if you don’t “enable” something the variables aren’t ever defined. Which means for me I have some SPI code that throws errors when SPI INST 2 isn’t enabled. My code is still valid, it’s just that variables that used to exist no longer do. Annoying. It doesn’t cost anything to “enable” the peripherals in preprocessor.
It’s ~47 instructions in the example I just checked to get a return from nrf_gpio_pin_read(some_pin) that’s not good. It also reminds me that nrfx and nrf aren’t the same and when you need to use one vs the other is anyone’s guess.
I do like their ASSERT() and use it for my own things. It’s report function is weak so i can overload it with one that reports to my other FreeRTOS threads.
Nordic isn’t bad, but they went a little overboard with the HAL. I don’t want “one code” that runs on all chips poorly. I want chip specific code that runs great and yes I’ll have changes to make if I switch chips, but that’s life!
Not only can’t you go bare metal with BLE and real complexity, but with a modern RTOS and knowledge of when you need a thread there is no reason to on chips with 48Mhz and 512kB Ram.
FWIW, I do recommend Amazon FreeRTOS but investigate their LTS version they are moving to if you look into it.
It's not official support for Rust but it's official support for LLVM upon which Rust is based, which works too.
Available libraries have certainly made the process much easier.
Having seen the complexity of BLE and Mesh, I would be very wary of using a vendor if I didn't see excellent software support. For example I wouldn't even consider Kinetis for wireless solutions, having seen how bad their SDKs were.
Hardware is relatively easy to get right, software is hard.
I'm working on a multi-year project with many subcomponents and I'm tired of vendors upgrading and obsoleting. Version x worked just fine for my needs. Version y gains me nothing and adds risk and time in testing.
For low quantities I do that too, but once you get into 100s of 1000s or millions of units, every $0.01 more profit takes out any developer cost. We are at a few dimes per mcu and it makes a massive difference compared to the previous mcu which was just over a $1; you can hire a boatload of developers for that and not even notice it.
Offtopic curious: from your profile: C64 BASIC, C64 Assembly, Logo, Pascal, C, C++, Scheme, Perl, Common Lisp, Clojure, ? => assume you use c/c++ for these controllers? I'm c or arm asm (our current controllers have 24kb free) but always interesting if people try to actually use anything else than c/c++. Like you say; maybe Rust, but it doesn't fit too nicely in your evolution => ? imho.
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...
Inside (I have no shame): https://www.dropbox.com/s/jep4rzz377h1svo/Photo%20Oct%2026%2...
Video: https://www.dropbox.com/s/45q3uk6cgw9ti46/Video%20Oct%2026%2...
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.
Do you have an hour to talk about pages?
1: https://news.ycombinator.com/item?id=19851744 2: https://observablehq.com/@tomlarkworthy/hacker-favourites-an...
Someone should sell them in packs of 100 on Amazon...
If I need them "ASAP" even tacking on the £17 DHL shipping for 2-4 day shipping they still come out much cheaper than purchasing locally, but I normally just choose "standard" postage which means it takes ~10days from ordering until I have the boards in my hands but drops the shipping cost to ~£4. (shipping costs vary based on size and weight of the order)
I've yet to use lcsc for components because I've been burnt in the past from ordering IC's from china and when ordering anything over the value of £15 I often get handed a £8 handling fee from the postal service to process a few quid of import VAT which always grinds my gears, so I tend to shop locally for components. But I do plan to give them a try at some point.
EDIT in ref to jlcpcb: Just keep their capabilities in mind and set your EDA/CAD software to mm and not mil to save headaches if you are planning to use BGA's in your design.
About LCSC, they are entirely legit and a very good source. I use them all the time.
I'm definitely testing them for my next boards.
Overall, I have a very good impression of them. If the price is acceptable for you, I would definitely recommend them. Shipping was very fast, too, the boards arrived within the week to Greece.
The way they have it, I need to know about how PCBs are fabricated to read it accurately.
https://aisler.net/help/getting-started/what-are-your-enviro...
Chinese PCB fabs are extremely dirty.
But the conversation from mils to mm introduced a rounding that just pushed him over the limits which then caused the automated DRC on the site to reject his board even though it was “in spec” according to the specs on the site (as they list both mm and mil).
And it’s not like you can just get them on the phone and get it nudged though even though some via are a few thousands of a mm out of spec but should be fine irl. The computer says no, so you gotta go back and redo a ton of traces, where a local shop running on higher margins will prob just push the order though after a brief phone call.
Surprisingly, they have beaten ~25% of the $1 microcontrollers.
It all adds up, or in this case it doesn't, and what's left is a pretty inexpensive chip.
The selling point with lines like STM32 or NXP is that they have lots of good documentation, Application notes etc.
Simple example, I was looking at trying a weird Chinese part with a hardware NN accelerator but the entire documentation available (Chinese or English) was 10x shorter than the documentation on the serial peripherals alone on an NXP part.
AVR8, MSP430 have the usual as, gcc, etc. toolchain. I don't know PICs as much, but I believe they too do have extensive open toolchains available.
No great loss in my opinion. PICs are old and slow, and the C programming experience is much worse than an STM32.
I'd say avr8, msp430 and stm32 cover the full range.
avr8 (atmega/attiny) is 8bit, very easy to understand, has excellent open ecosystem, the go-to if you don't need the other two. There's fancy new xmega stuff, but at that point, you'd look at stm32.
msp430 is 16bit, smaller rom/ram sizes but very low-power and excellent open ecosystem.
stm32 is 32bit, Cortex-M0+ based in current generation,
pic? attiny trounces pic12, atmega trounces pic16/18, msp430 trounces pic24 and stm32 trounces pic32.
Plus the free libraries that ST has made available are magical. Just - incredibly good. Best embedded C experience I've ever had. Yes using the chip in a more 'bare metal' scenario can be challenging (set 4 registers in the proper order with obtuse values to route the clock signal properly), but it's usually not necessary since the provided libs are so cohesive and comprehensive.
On the whole, though, you're absolutely correct. :)
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.
Just the other day I decided to try out these instructions to blink an LED: https://jonathanklimt.de/electronics/programming/embedded-ru...
Took about 10 minutes to get an LED blinking, about half of which was just figuring out what (C language) USB libraries I needed to install to get the "cargo flash" command to compile. I used to do a lot of microprocessor development in C and ASM. This is the easiest experience I've ever had in getting one up and running with fully open source tooling (many microprocessor vendors do have quite good closed-source tooling).
While I haven't actually done a real project yet, the hardware abstraction libraries look much safer to use than any of the C/ASM toolkits I've used. The reason being, the API's are designed to leverage Rust's borrow checker and other safety features to make sure errors in use and configuration of the hardware are caught at compile time.
Also worth reading: https://rust-embedded.github.io/book/
It would nice to run the mbed, or maybe some rust, on a $1.2(qty 10, [1]) chip with 64KB flash.
[1]https://lcsc.com/product-detail/GigaDevice_GigaDevice-Semico...
https://zeptobars.com/en/read/GD32F103CBT6-mcm-serial-flash-...
I haven't tried anything complicated with the peripherals though, and the thing is, STM32F103 chips are so cheap already. The design is over 10 years old, and ST is so good at making them that most "64KB" chips actually have 128KB of Flash.
The GD32V chips are very cool, though; they keep the STM32-alike peripherals, but they use a faster RISC-V CPU core (rv32imac).
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...
[2] http://www.mcmanis.com/chuck/robotics/projects/wsm.html Free PCB for that project to anyone who has postage ($1) :-) contact in my profile.
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.
So tools are what they should provide so that I can plug them in to whatever IDE I'm using.
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.
//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.
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.
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.
STM32F030F4 ($0.55@2500) -> STM32G030F6 ($0.49@2500):
* Clock speed: 48MHz -> 64MHz
* Flash memory: 16KiB -> 32KiB
* SRAM: 4KiB -> 8KiB
* CPU core: Cortex-M0 -> Cortex-M0+
The newer chips are also on a smaller process node, so they can run off of slightly lower voltages and use a bit less power.
They're incremental improvements, but time is starting to march on...
https://maker.pro/esp8266/tutorial/a-comparison-of-the-new-e...
I doubt that's the most efficient route these days, but it can still be fun. And there's lots of material on the likes of the Commodore 64.
Oh, and of course there's always Google: 'but how do you learn to work/program for microcontrollers?' gets lots of hits, I bet some of them are even good.
if(user_has_pressed_out_of_milk_button) {
...
} //??EDIT: Follow the better suggestion from harry8 below.
https://www.aliexpress.com/item/33059632653.html
I found that stupidly simple with many, many libraries to do things. WS2812 LED strips using FastLED is very popular and rightly so, great fun. Really quick and easy to start flashing lights in patterns. Then copy some wifi code so you can control it with your phone (or tablet or laptop). Mesh more than one. If you're just playing $3 is still very cheap.
And if you've just started learning C being arduino compatible with many step-by-step tutorials a search away is gold.
ESP8266 successor is ESP32. Also on Aliexpress, cheap and easy to get, ESP32-PICO-KIT and ESP32-DevKitC.
https://developer.arm.com/tools-and-software/open-source-sof...
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:
And the advantage that dirt cheap clone boards exist. There's huge starter kits in Aliexpress at $10-$20 range, with an arduino uno or mega2560 clone included.
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.
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.
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...
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.
Limit resource to
Sweep mental complexities
Away, like fall's leaves.Not really. If I manage to burn it out that $10 MCU just became a $20 MCU. And if I want it to run off a battery, extra peripherals and compute power I don't need don't help me any. And if I want to make more than one I want to to be cheap.
I burned out 3 NodeMCU boards in one day because I apparently know nothing about circuits (especially transistors) and kept effectively shorting a digital IO pin to ground.
Two of them appear to have blown voltage regulators. If I plug them into USB, the 3.3v pins give 0.25v on one board and 1.0v on the other. The third one appears to work fine, but I can't get it to accept flashes reliably. At least 90% of the time, it can't even open the COM port to flash (Says the device is busy). When it DOES actually flash, in the end it will often throw an error saying there was a hash mismatch, indicating the firmware was corrupted during the flashing process. I have had once or twice where it flashed with no errors, but my code appears to fail to run.
It's not like I'm gonna really notice the $13 I'm spending on Amazon to replace the boards (I know I can get them cheaper on AliExpress or some other Chinese site, but I wanted them in two days, not four weeks), but still I hate spending money I don't have to.
As an example, I made a flow measurement and alarm system for my home. I used an ESP8266 development board, which is damn cheap, at about 5 USD. I successfully completed the project.
However, I decided to explore options for commercialization, and that 5 USD became a huge cost increase for my overall system. So I am now trying to designin systems with MCUs that are less than 30 cents.
> and that 5 USD became a huge cost increase for my overall system.
The STM32F103C8 is a good example. If you buy a few dozen off of AliExpress or TaoBao, "blue pill" boards containing them and a microUSB connector cost less than $3 each.
They only run at 72MHz, and they don't have floating-point hardware, but the price point means that you can give them away without a second thought. When someone has an idea for a Halloween decoration, or a garden sensor, or a proof-of-concept, it's usually my first choice because it costs less than a coffee.
Once it stops getting rained on, and corroded, and coated in dust, and submerged, and fried by a squirrel who thought wires were edible...then you can reach for the top of the line.
But for a proxy, maybe you would want an actual microprocessor instead of a microcontroller. Pi Zero W or similar.
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
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.
these things will give you like 5KB/s in bandwidth, and that's after spending months figuring out how to get networking working on them. (I am assuming you have no embedded computing experience here)
In fact scratch that, none of these even have enough resources to handle TLS/SSL for one connection.
This one can run various flavors of Linux, of which I would suggest Armbian or DietPI.
https://www.friendlyarm.com/index.php?route=product/product&...
This one is more dedicated to networking, however it runs the proprietary RouterOS, although OpenWRT was ported with success.
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.