Using erlang on nerves

I am planning to start a new IoT project that should be able to run on simple and inexpensive single-board computers like a Raspberry Pi or something similar. Nerves is a logical choice to serve as a foundation in many ways, but I would really like to continue using Erlang and not switch to Elixir. Does anyone have experience using Erlang on Nerves and has this been documented?

4 Likes

Might https://atomvm.org/ (see also AtomVM Forum - Erlang Forums) be appropriate instead?

1 Like

I definitely plan to use AtomVM whenever possible. But for the backend more is needed and I want to be able to use Erlang OTP and applications like Cowboy and grpoc etc, etc.

2 Likes

Hi Frans,

I just using classical Erlang/OTP 25 on a Raspi5 CM for some weeks.
It works out of the box including rebar3 like on any other PC (Linux, Windows or whatever).

Some days ago I just compiled the gen_serial library
https://git.hq.sig7.se/gen_serial.git
for the serial ports. Even the C-part of the lib was working w/o complains on Rasperian.

I wrapped a gen_server around, so no hustles with the serial port up to now, even at 921600 Baud on 3.3 V level to a micro-controller (Propeller II …ok, thats a little bit exotic).

I was also heavily using the connection to MariaDB on the Raspi with:

good old software working very stable.

Things maybe totally different with a Raspi Zero or Raspi Pico.
But for a classical Raspi just use the official repos.

Markus

1 Like

I saw your post on the Elixir Forum and figured that I’d close the loop here. For better or worse, Nerves users tend to be more on the Elixir forum, so I think you did the best thing with posting there and you may already have your answer.

There’s an Erlang hello world example that illustrates the current integration:

  1. The base Nerves project needs to use mix for the embedded tooling, release creation, and Elixir.
  2. Erlang source code goes in the src directory like you’d expect
  3. You can also add pure Erlang projects or libraries in the mix.exs dependency list so if it’s possible to develop code in a platform agnostic way, you could do it in a separate directory and use a path dependency.
  4. Edit the rel/vm.args.eex file to change the shell to an Erlang one

While Nerves libraries are all written in Elixir, all functionality should be callable from Erlang. The libraries either don’t use macros or have a way of avoiding macros which should help. You may still want to wrap them to make them more ergonomic from Erlang.

Also, fwiw, Nerves originally was an Erlang project using rebar2, relx, and shell scripts. Obviously, that’s changed quite a bit, but it brings back some good memories for me. With the caveat that some things are require a lot of work (using rebar3 instead of mix for the base project), please post issues or PRs if there are things we could do to make life better for a mostly Erlang project.

4 Likes