3 ms·
Agreed, C/C++ can sometimes be a real pain to work with. I went a slightly different route however after seeing how much less I could do with an equally powerfu
by PMunch 5y ago
Agreed, C/C++ can sometimes be a real pain to work with. I went a slightly different route however after seeing how much less I could do with an equally powerful board running MicroPython and settled on Nim. It has a syntax that looks familiar to Python, but it's compiled through C/C++ so every board I could run C/C++ on I could run Nim on. It also meant I didn't have to rewrite all the libraries.
Recently I've been digging into creating a pure Nim ecosystem for microcontrollers after discovering just how much overhead Arduino and other generic C approaches are. The benefit Nim has here is that it is incredibly strong at compile-time execution. This means that I can write succinct Python-looking code which compiles to tiny binaries with great performance.
My biggest project in it so far is a keyboard firmware for a keyboard split in half. The whole project compiles down to about 4Kb with all the code for the port expanders and the layouts and special key macros I use. For comparison the Arduino code to blink an LED over one such port expander was about 3.8Kb and MicroPython can't even compile a hello world for the board I'm using.
- nyanpasu64 5y agoI wonder if Nim is better or worse suited for low-powered boards than TinyGo. Zig is probably not mature enough and insufficiently safer than C++ to satisfy you and your parent post's requirements though.
- PMunch 5y agoTinyGo has a list of explicitly supported devices. Nim can run on anything you can compile C for. I also can't see some of the more low-powered hobby devices such as the Digispark (Attiny85) or similar. Not sure if that's because TinyGo can't be run on them, or whether or not it's just no-one who has written a target for it yet. One huge benefit Nim has in this category is that it compiles to C. If your board can run C, it can run Nim. And don't let the Nim GC fool you, it can be disabled, or switched to the more modern ARC version which runs fine on microcontrollers (and if you don't use garbage collected memory it doesn't add any code to your project). Since it compiles to C you can easily wrap libraries and compile for pretty much anything. Zig can at least also wrap C code super easily, but I'm not sure how the overhead and targeting is for it.
- Chris2048 5y agoSounds great, are there any project pages towards this initiative? I'm also sceptical of HHLs on restricted devices i.e. mcus, but Arduino seems like the only game in town atm.
- PMunch 5y agoNothing about the entire ecosystem I was talking about. But my initial work on the keyboard firmware can be found here: https://github.com/PMunch/badger/tree/final https://github.com/PMunch/badger/tree/final. There are many different projects in Nim running on microcontrollers though, but not something on a common ecosystem. HHL?