Convert Figma logo to code with AI

nerves-project logonerves

Craft and deploy bulletproof embedded software in Elixir

2,230
189
2,230
26

Quick Overview

Nerves is an open-source platform and set of tools for building and deploying embedded software for IoT devices using Elixir. It provides a complete framework for creating, managing, and updating firmware for various hardware platforms, focusing on reliability and ease of use for developers.

Pros

  • Streamlined development process for embedded systems using Elixir
  • Built-in support for OTA (Over-the-Air) updates
  • Extensive hardware support for various platforms (Raspberry Pi, BeagleBone, etc.)
  • Strong focus on security and reliability

Cons

  • Steep learning curve for developers new to Elixir or embedded systems
  • Limited community size compared to more mainstream embedded development platforms
  • Some hardware platforms may have limited support or documentation
  • Resource constraints on smaller devices may limit the use of certain Elixir features

Code Examples

  1. Creating a new Nerves project:
mix nerves.new my_project
cd my_project
export MIX_TARGET=rpi3
mix deps.get
mix firmware

This code creates a new Nerves project, sets the target hardware to Raspberry Pi 3, fetches dependencies, and builds the firmware.

  1. Configuring WiFi in a Nerves project:
config :nerves_network,
  regulatory_domain: "US"

config :nerves_network, :default,
  wlan0: [
    ssid: "your_wifi_name",
    psk: "your_wifi_password",
    key_mgmt: :"WPA-PSK"
  ]

This configuration sets up WiFi connectivity for a Nerves device.

  1. Implementing a simple LED blink example:
defmodule MyProject.Blinker do
  use GenServer

  @led_pin 18

  def start_link(_) do
    GenServer.start_link(__MODULE__, [])
  end

  def init(_) do
    {:ok, gpio} = Circuits.GPIO.open(@led_pin, :output)
    :timer.send_interval(1000, :toggle)
    {:ok, gpio}
  end

  def handle_info(:toggle, gpio) do
    Circuits.GPIO.write(gpio, 1 - Circuits.GPIO.read(gpio))
    {:noreply, gpio}
  end
end

This code implements a simple LED blink example using the Circuits.GPIO library.

Getting Started

To get started with Nerves:

  1. Install Elixir and Erlang
  2. Install the Nerves bootstrap: mix archive.install hex nerves_bootstrap
  3. Create a new project: mix nerves.new my_project
  4. Set the target hardware: export MIX_TARGET=rpi3 (for Raspberry Pi 3)
  5. Get dependencies: mix deps.get
  6. Build firmware: mix firmware
  7. Burn firmware to an SD card: mix firmware.burn

For more detailed instructions and advanced usage, refer to the official Nerves documentation.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Nerves

Backers on Open Collective Sponsors on Open Collective CircleCI Hex version

Craft and deploy bulletproof embedded software in Elixir

Nerves provides tooling and libraries for building small, self-contained software images using the rock-solid Erlang virtual machine hardware support of Linux, and happy development experience of Elixir for microprocessor-based embedded systems.

While the Nerves project provides base runtime libraries for hardware access and network configuration, nearly all of the Elixir ecosystem is available, including:

  • Phoenix and LiveView for interactive local web user interfaces
  • Elixir Nx for numerical computing and machine learning
  • Livebook for interactive code notebooks on your device
  • Scenic for local on-screen user interfaces

Or just keep it simple and use whatever libraries you need from the Hex package manager. Nerves only includes what you use so your embedded software can remain small.

Nerves uses the Linux kernel to support a large variety of hardware. It is not a Linux distribution, though, and contains little of what you would find on a typical embedded Linux system. Instead, it starts the Erlang runtime as one of the first OS processes and lets Erlang and Elixir take over from there. Not to fear, if you need something from Linux, Nerves provides a way to use most of the packages available through Buildroot.

Nerves Projects

Our project is spread over many repositories in order to focus on a limited scope per repository.

This repository (nerves-project/nerves) is an entrance to Nerves and provides the core tooling and documentation.

The Nerves core team maintains the projects in the nerves-project organization with the help of many in the Elixir community. Projects under other GitHub organizations are maintained by their respective organization, but listed here since they're so commonly used in conjunction with the core libraries and tools.

Framework / Core

NameDescriptionRelease
ErlinitReplacement for /sbin/init that launches an Erlang/OTP ReleaseGitHub release (latest SemVer)
Nerves.BootstrapThe Nerves new project generator and low level hooks into MixHex.pm
Nerves.RuntimeSmall, general runtime utilities for Nerves devicesHex.pm
NervesPackInitialization setup for Nerves devicesHex.pm
NervesSystemBRBuildroot based build platform for Nerves SystemsHex.pm
RingLoggerA ring buffer backend for Elixir Logger with IO streamingHex.pm

Example projects

NameDescriptionRelease
Circuits QuickstartTry out Elixir Circuits with prebuilt Nerves firmwareGitHub release (latest SemVer)
NervesExamplesSmall example programs using Nerves
Nerves LivebookDevelop on embedded devices with Livebook and NervesGitHub release (latest SemVer)

Hardware

These are the officially supported hardware ports. Many others exist in the community.

NameDescriptionRelease
NervesSystemBBBBase Nerves system configuration for the BeagleBone-based boardsHex.pm
NervesSystemOSD32MP1Base system for Octavo OSD32MP1Hex.pm
NervesSystemRPiBase Nerves system configuration for the Raspberry Pi A+ and B+Hex.pm
NervesSystemRPi0Base Nerves system configuration for the Raspberry Pi Zero and Zero WHex.pm
NervesSystemRPi2Base Nerves system configuration for the Raspberry Pi 2Hex.pm
NervesSystemRPi3Base Nerves system configuration for the Raspberry Pi 3Hex.pm
NervesSystemRPi3ANerves system for the Raspberry Pi 3 Model A+ w/ gadget mode and Raspberry Pi Zero 2 WHex.pm
NervesSystemRPi4Base Nerves system configuration for the Raspberry Pi 4Hex.pm
NervesSystemRPi5Base Nerves system configuration for the Raspberry Pi 5Hex.pm
NervesSystemVultrExperimental configuration for a Vultr cloud serverHex.pm
NervesSystemX86_64Generic Nerves system configuration x86_64 based hardwareHex.pm
NervesSystemGrisp2Base Nerves system configuration for the GRiSP 2Hex.pm
NervesSystemMangoPiMQProBase Nerves system configuration for the MangoPi MQ-ProHex.pm

Networking

NameDescriptionRelease
VintageNetNetwork configuration and management for NervesHex.pm
VintageNetWiFiWiFi networking for VintageNetHex.pm
VintageNetDirectDirect network connection support for VintageNetHex.pm
VintageNetEthernetEthernet support for VintageNetHex.pm
VintageNetMobileMobile connection support for VintageNetHex.pm
VintageNetQMIVintageNet technology support for QMI mobile connectionsHex.pm
VintageNetWireGuardWireguard VPN supportHex.pm

Hardware access

NameDescriptionRelease
Circuits.GPIOUse GPIOs in ElixirHex.pm
Circuits.I2CUse I2C in ElixirHex.pm
Circuits.SPICommunicate over SPI from ElixirHex.pm
Circuits.UARTDiscover and use UARTs and serial ports in ElixirHex.pm

SSH and Shell

NameDescriptionRelease
NervesMOTDMessage of the day for Nerves devicesHex.pm
NervesSSHManage an SSH daemon and subsystems on Nerves devicesHex.pm
SSHSubsystemFwupErlang SSH Subsystem for Nerves firmware updatesHex.pm
ToolshedA toolshed of shell-like IEx helpersHex.pm

Toolchain

Nerves provides a C/C++ cross-toolchain to ensure consistency builds on all supported host platforms. These are built using crosstool-ng and are similar to other GCC toolchains.

NameDescriptionRelease
nerves_toolchain_ctngCrosstool-NG integration for building Nerves toolchainsHex.pm
nerves_toolchain_aarch64_nerves_linux_gnu64-bit ARM toolchainHex.pm
nerves_toolchain_armv5_nerves_linux_musleabi32-bit ARM toolchain for older ARM processorsHex.pm
nerves_toolchain_armv6_nerves_linux_gnueabihf32-bit ARM toolchain for Raspberry Pi A, B, and ZeroHex.pm
nerves_toolchain_armv7_nerves_linux_gnueabihf32-bit ARM toolchain for most 32-bit ARMsHex.pm
nerves_toolchain_i586_nerves_linux_gnu32-bit Intel x86 toolchainHex.pm
nerves_toolchain_mipsel_nerves_linux_musl32-bit MIPS toolchainHex.pm
nerves_toolchain_riscv64_nerves_linux_gnu64-bit RISC-V toolchainHex.pm
nerves_toolchain_x86_64_nerves_linux_musl64-bit x86 toolchain using the musl libcHex.pm
nerves_toolchain_x86_64_nerves_linux_gnu64-bit x86 toolchain using GNU libcHex.pm

Miscellaneous

NameDescriptionRelease
boardidPrint out a platform-specific board serial numberGitHub release (latest SemVer)
NervesFWLoadersA collection of firmware loaders for boards with internal storageGitHub release (latest SemVer)
NervesHeartErlang heartbeat support for NervesGitHub release (latest SemVer)
ShoehornHelp handle OTP application failures and start orderHex.pm
UBootEnvRead and write to U-Boot environment blocksHex.pm

Upcoming

These projects are new or experimental and are in various stages of being ready to promote to the above categories.

NameDescriptionRelease
NervesLoggingRoute system log messages through the Elixir loggerHex.pm
NervesUEventSimple UEvent monitor for detecting hardware and automatically loading driversHex.pm
PropertyTableIn-memory key-value store with subscriptionsHex.pm
nerves_initramfsAn initramfs for early boot handling of Nerves devicesGitHub release (latest SemVer)
nerves_system_linterMix task to check Nerves system configuration filesHex.pm
nerves_systemsBuild scripts for maintaining multiple repositoriesunreleased
See outdated/inactive projects...
NameDescriptionRelease
nerves_ledsFunctions to drive LEDs on embedded systemsHex.pm
system_registrySerial nested term storage and dispatch registryHex.pm
system_registry_term_storageSimple term storage for SystemRegistryHex.pm
nerves_system_test
nerves_test_server

There is also a gravesite for old Nerves libraries at https://github.com/nerves-project-attic.

Host Requirements

  • Mac OS 10.13+ (High Sierra and later)
  • 64-bit Linux (tested on Debian / Ubuntu / Redhat / CentOS / Arch)
  • Windows 10 with Windows Subsystem for Linux 2
  • Elixir ~> 1.11

See Installation Docs for software dependencies.

Quick-Reference

Generating a New Nerves Application

mix nerves.new my_app

Building Firmware

export MIX_TARGET=rpi3
mix deps.get      # Fetch the dependencies
mix firmware      # Cross-compile dependencies and create a .fw file
mix firmware.burn # Burn firmware to an inserted SD card

Note: The mix firmware.burn target relies on the presence of ssh-askpass. Some users may need to export the SUDO_ASKPASS environment variable to point to their askpass binary. On Arch Linux systems, this is in /usr/lib/ssh/ssh-askpass

Docs

Installation Docs

Getting Started

Frequently-Asked Questions

Systems

Targets

User Interfaces

Advanced Configuration

Compiling non-BEAM code

Customizing Systems

Contributors

This project exists thanks to all the people who contribute.

Please see our Contributing Guide for details on how you can contribute in various ways.

Metal Level Sponsors

Metal level sponsors are companies that allow core team members to maintain and extend Nerves for a portion of each work week. Nerves is not a product of any one company. We also have a soft spot for supporting makers and hobbyists using the BEAM, and it would be difficult to do this without them.

[Become a metal level sponsor]

OpenCollective Backers

Thank you to all our monetary backers! Hardware costs money and without support, we wouldn't be able to support nearly as many devices. 🙏 [Become a backer]

OpenCollective Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

Copyright (C) 2015-2021 by the Nerves Project developers nerves@nerves-project.org