Hacker News new | past | comments | ask | show | jobs | submit login
Ask HN: Getting into lower-level microcontroller coding
9 points by tombert on May 8, 2019 | hide | past | favorite | 9 comments
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.

This seems obscenely interesting to me, but I have no idea how I'd even start going about programming one of these things...does anyone have a good book recommendation or video series?

[1] https://news.ycombinator.com/item?id=19851903




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-...


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.


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.


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?


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.


Honestly, OTP isn't much different than writing for any other chip, the difference is just you only get one shot per chip. So if you made a mistake in your code and burn a chip, oops it is trash so you start over with a new one. Also, I kinda use machine and assembly language interchangeably, but in reality they do have some slight differences with assembly technically being slightly higher level than machine, just be aware some purists get on their rants about this, and literature can sometimes be confusing if you don't know there are a few differences.

You'll have to pick up their machine instructions and learn them, since it is RISC based they likely stuck close to one of the RISC based standards as there is no reason to reinvent the wheel. You can absolutely do it, I would just think it might make more sense to start just a little higher level first, then go here. But I totally respect jumping to the lowest level and working up as I have done that too.

To get started, I am sure they manufacture a programing/flash board, buy it and a bunch of chips. Find a problem to solve that makes sense given what you are working with, and learn their machine instructions. If you know how to program the basics are the same, except you have to manage everything, clock, RAM, register spaces etc. Lots of good books on embedded work, just remember that the chip you are looking at isn't really a micro processor, it is a limited micro controller.

I started off in Basic, C, Pascal and Motorola assembly (then x86) way back when, then kinda settled into C/C++ for low level and Javascript for pretty much everything else, except mobile. So how I learn these is just by doing exactly what I am suggesting to you, find a problem that seems fun to solve and just start working at it. Sometimes for my own sanity, I would write things in C to get a feel for what I wanted to do (just mocking up in/outputs), just helped me think a little higher level at first. I would also many times output the assembly using gcc as a way to give me some ideas, but usually that is just an idea since these small micro controllers aren't likely supported by any major compiler.

Good luck, this can be a ton of fun.


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) 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, 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/

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.


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.


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: