https://github.com/Niminem/narduino
Write and flash Arduino firmware with Nim using your favorite IDE with ease!
The Arduino CLI powers the Arduino IDE and other official tooling. narduino provides abstractions on top of it (and the Nim compiler) so you can build firmware in Nim from any editor. Your Nim code is translated to C++, placed into a standard Arduino sketch, and arduino-cli then compiles that sketch for your board and flashes it.
All from a single command: narduino flash --src:examples/blink.nim
This repo is both a CLI tool AND a library. I've wrapped the vast majority of the Arduino API as well as providing templates to remove FFI boilerplate.
A simple example looks like this (blinks the internal LED on an Arduino UNO):
import narduino
setup:
pinMode(LED_BUILTIN, OUTPUT)
loop:
digitalWrite(LED_BUILTIN, HIGH)
delay(1000)
digitalWrite(LED_BUILTIN, LOW)
delay(1000)
The toolchain (functions) powering the CLI is also provided as a library so you can create your own tooling if you wish.
An example:
import narduino/toolchain
# board discovery
let boards = listBoards() # all detected ports + matching boards
let active = getActiveBoard() # the single connected board (fqbn + port)
# core management
ensureCoreInstalled(active.fqbn) # install the board's core if missing
# build & flash
let sketchDir = createSketch("blink.nim") # nim -> c++ -> sketch dir
upload(sketchDir) # compile & upload via arduino-cli
The Arduino CLI itself supports A LOT of boards and 3rd party Cores (packages). As long as it supports your board you can use this repo easy peasy. See https://github.com/Niminem/narduino#supported-boards for more details.
---
I started getting into electronics and embedded systems recently. I didn't want to write in c++ nor did I want to use their IDE but I was willing to do it. I started exploring what was out there for Nim because I knew it HAD to be possible to use Nim's cpp backend and VSCode.
Everything I found was really old and fickle and just... janky.
I learned that Arduino has a CLI that powers their IDE and began exploring the possibility of using that. Works like a charm!
Figuring out how to compile Nim projects in a way that actually worked took some time, but was nearly as complicated as I thought. Knowing what I know now, I was even able to programmatically detect which cpu architecture your board uses and define that architecture when compiling Nim- pretty neat!
Anyways guys, I hope you enjoy. I did not port the USB / WIFI stuff from the API yet because I don't have a board to test them. PRs accepted otherwise it'll be a little while before I can get to it. Wrapping these functions are pretty straightforward anyway. Seems like the Arduino team really took their time to make the APIs as simple as possible.