
Ask HN: Getting into lower-level microcontroller coding - tombert
I recently purchased a bunch of ESP controllers online to play with, and I more or less understand NodeMCU at this point.  However, per a discussion here [1] from yesterday, I saw that there exists 5 cent controllers.<p>This seems obscenely interesting to me, but I have no idea how I&#x27;d even start going about programming one of these things...does anyone have a good book recommendation or video series?<p>[1] https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=19851903
======
drtse4
If you've never done embedded development before I highly recommend the two
parts MOOC "Embedded Systems - Shape The World"[1].

The course is well structured, teaching the basics you'll need for those
boards that doesn't usually have an OS and requires a ~40$ components kit that
include a Texas Instruments board. Quite fun if you follow along and do all
the exercises.

[1] [https://www.edx.org/course/embedded-systems-shape-the-
world-...](https://www.edx.org/course/embedded-systems-shape-the-world-
microcontroller-inputoutput) , [https://www.edx.org/course/embedded-systems-
shape-the-world-...](https://www.edx.org/course/embedded-systems-shape-the-
world-multi-threaded-interfacing)

~~~
ultrasounder
Upvoting this as I just started following this course myself (archived but all
the material Is still available). The kit is self sufficient and with some
basic C programming skills one gets cut their teeth on all relevant real world
embedded design methodologies. I am also taking the NAND2TETRIS course in
parallel and can now start appreciating the hardware/software interface.
Highly recommend that course and the accompanying book.

------
davismwfl
This device is a one time programmable (OTP) device from what I saw, and it
has 79 instructions so you need to write assembly level code and write them to
the device using a specific programming device.

If you are getting familiar with embedded programming using too NodeMCU, I
doubt you'd find much fun in these types of devices as it is nearly as low
level as you can get. Assuming I read it correctly and these are OTP devices
then think of each time you "test" you are burning 5 cents, as you will use up
a chip as you can't reprogram it. When I did some OTP device programming I had
an emulator we wrote against and tested there first, then we would write to
the chip (still burned through them though as it is part of the process).

Also, these are the types of devices used for doing a single repetitive task
well while other more capable MCU's are doing other work and making larger
decisions. Typically these would not be the heart of any system, just an
ancillary chip offloading some very basic functionality that is very
repetitive and that has little to, ideally, no business logic at all.

~~~
tombert
I'd still like to play with them just to get a better understanding of
computers. I'm typically more of a math guy than hardware, but since I do
program for a living, understanding the guts of how these things work could be
really valuable.

How did you learn OTP programming?

~~~
nullwasamistake
Davismlfw knows his stuff. If you're more math than hardware you need to
become a hardware guy before messing with these.

As a start I would learn analog circuit design at a basic level. Followed by
digital design and layout. At any point in this, pour your mind into a micro
datasheet. Atmel or TI are easiest to read. You need to understand this stuff
at a pin = signal level and below to really work at that low a level
effectively.

This is why arduinos etc are so relatively expensive. It's a ton of work to
learn what's needed to design and build these boards + actually program them
usefully

Ideally you want to understand power electronics and DSP/signalling at a deep
level as well. If you don't know what the difference between level and edge
triggered is, for instance, you're going to have a bad time. Gray code,
busses, ohms law, network analysis. This is a deep but fulfilling rabbit hole.

------
ThrowawayR2
These ultra-low cost micro controllers are 8-bit processors. Programming them
is done at the machine language level and, from a modern perspective, is not
unlike attempting to build a house, one atom at a time.

Something optional you can start off with that will let you figure out if this
is something you want to invest your time in would be to get a copy of a semi-
educational game: "Human Resource Machine"
([https://www.gog.com/game/human_resource_machine](https://www.gog.com/game/human_resource_machine))
which teaches the concepts of machine language programming using a fun and
quirky aesthetic.

If you decide you want to dig deeper, you'll need to decide which processor
architecture you want to learn the machine language for initially. For a
beginner, something like the 6502 or Z80 used to power early home computers of
the '70s and '80s like the Apple II, TRS-80, Commodore 64 and so forth is IMO
a better choice because of the plethora of people familiar with them and
decades of documentation and tutorials available. (While modern industrial
8-bit microcontrollers, such as the one you linked to, are also an option,
documentation about them tends to be scarcer and geared towards professional
engineers.) Fortunately, modern computers are powerful enough to emulate these
tiny microprocessors easily and you can explore programming them in an
emulator.

An example of this is [http://www.6502asm.com](http://www.6502asm.com), which
allows you to write 6502 assembly language and execute it right in your
browser. A tutorial can be found at
[https://skilldrick.github.io/easy6502/](https://skilldrick.github.io/easy6502/)

Once you get some experience with writing machine language for one
microcontroller, you should know enough to pick up machine languages for other
microcontrollers without difficulty. At this point, you can start looking into
development boards for your processor of choice.

------
stevekemp
Honestly if you understand the NodeMCU / ESP8266 devices you're half way
there.

The difference with smaller chips is you often have to use odd/annoying
toolchains, or resort to assembly language. Since you say you're a programmer
I'm sure you can practice the basics on a real PC before scaling down.

e.g. Write some assembly language programs to invoke linux-syscalls, etc. Of
course on a smaller controller you won't have syscalls, but the interfacing
with external hardware will be familiar to you from the nodemcu - even if you
have to bit-bang your own I/O by hand.

Of course it goes without saying that the more popular your chosen chip is the
easier things will come; others will have written code, and the documentation
will be better.

------
nullwasamistake
If you're buying super cheap micros you need to learn circuit design and
layout. It's not that hard compared to programming, just different.

Below assembly, you need to understand busses, signaling, and maybe some
analog circuit design.

I'm very interested in this stuff as well but I haven't gone deep enough to
build my own board. It's a whole different game. Still fun but if you're not
an assembly programmer with experience in signal processing and circuit design
there's a lot to learn.

