A Nerves application for the Arduino VENTUNO Q, built on nerves_system_arduino_ventuno_q. It serves a one-page dashboard on port 80 that exercises the board:
- Cameras: live previews from Raspberry Pi cameras on the three CSI connectors, with auto exposure.
- Microcontroller: the STM32's pins, analog inputs, PWM, RGB LEDs, LED matrix, I2C buses and pulse trains, driven through arduino_router_ex.
- System: CPU, GPU and NPU state with checks you can run, temperatures, network throughput and the firmware slot.
Start from it for your own application: each part is a module you can keep or drop.
You need Elixir 1.20 with Erlang/OTP 29, nerves_bootstrap, fwup and an SSH
key in ~/.ssh (id_rsa, id_ecdsa or id_ed25519), which the firmware
authorises.
export MIX_TARGET=arduino_ventuno_q
mix deps.get
mix firmwareOn a board that runs Arduino's Ubuntu, install Nerves with
mix firmware.install arduino@<board-ip> (see the system's README, which also
covers the debug UART). On a board that runs Nerves, update it with:
mix upload <board-ip>Then open http://<board-ip>/ or http://nerves.local/.
The system comes from GitHub. Without a prebuilt release of it, mix firmware
builds it first, which takes a few hours and about 30 GB. To build against a
local checkout of the system, set VENTUNO_Q_SYSTEM_PATH to it.
Settings that belong to your machine, such as Wi-Fi credentials or other SSH
keys, go in config/local.exs, which git ignores:
import Config
config :vintage_net,
config: [
{"usb0", %{type: VintageNetDirect}},
{"eth0", %{type: VintageNetEthernet, ipv4: %{method: :dhcp}}},
{"wlan0",
%{
type: VintageNetWiFi,
vintage_net_wifi: %{networks: [%{ssid: "my-network", psk: "secret", key_mgmt: :wpa_psk}]},
ipv4: %{method: :dhcp}
}}
]rootfs_overlay/boot/cameras.cfg names the camera on each connector, as the
system expects. This example has Global Shutter Cameras on Camera 0 and
Camera 1 and an HQ Camera on Camera 2:
set ventuno_q_cameras=imx296-imx296-imx477
Change it to match your cameras: each field is none, imx296 or imx477.
NervesExampleVentunoQ.Camera routes each sensor from its CSIPHY through a
CSID and a VFE, sets its mode and frame rate, and starts camstream
(c_src/camstream.c), which reads raw Bayer frames and returns JPEG previews
at half resolution, each 2×2 Bayer cell giving one pixel. For the IMX296 and
IMX477 it takes the white balance, colour matrices and tone curve from Raspberry
Pi's libcamera tuning files (c_src/tuning.h); other sensors get a grey-world
balance. The auto exposure runs in Elixir: it scales exposure × gain towards a
target level, exposure first, with each sensor's gain law. A preview streams
only while it is on screen in a dashboard.
At start, NervesExampleVentunoQ.Mcu installs arduino_router_ex's io
sketch on the STM32 (it flashes only when the sketch differs) and the
dashboard's Microcontroller section drives it. Each control is one library call:
| Control | Call |
|---|---|
| Pin mode, output | ArduinoRouterEx.IO.mode/2, write/2 |
| Pin level | ArduinoRouterEx.IO.read/1 |
| PWM | ArduinoRouterEx.IO.pwm/2 (D3, D5, D6, D9, D11) |
| Watch | ArduinoRouterEx.IO.subscribe/2 |
| Analog inputs | ArduinoRouterEx.IO.analog_read/1 (12 bits) |
| RGB LEDs | ArduinoRouterEx.IO.write/2 on LED1_R to LED4_B |
| LED matrix | ArduinoRouterEx.Matrix.draw/1 |
| I2C scan | ArduinoRouterEx.IO.i2c_transfer/4, a one-byte read per address |
| I2C transfer | ArduinoRouterEx.IO.i2c_transfer/4 |
| Pulse train | ArduinoRouterEx.PulseTrain.start/2, stop/0 |
The RGB LEDs light when their pin is low. The pulse train and PWM on D3 and D5 share one timer: while a train runs, the dashboard leaves those pins to it, and they are inputs again after it stops.
config/runtime.exs also puts the microcontroller's pins and buses behind
Circuits, as the "mcu" GPIO controller and the "mcu-i2c0" to "mcu-i2c2"
buses, next to the SoC's own:
{:ok, led} = Circuits.GPIO.open({"mcu", "LED1_G"}, :output)
Circuits.GPIO.write(led, 0)The NPU check runs a QNN model on the Hexagon NPU with Qualcomm's AI Runtime
(QAIRT). Qualcomm's licence lets you ship QAIRT inside your firmware but not
on its own, so this repository does not contain it. scripts/setup-npu.sh
downloads it with the system's fetch-qairt.sh (2.6 GB, which accepts
Qualcomm's licence), builds the SDK's example model for the board, and writes
both into rootfs_overlay_qairt/, which the next mix firmware includes:
export MIX_TARGET=arduino_ventuno_q
mix deps.get && mix compile
scripts/setup-npu.sh
mix firmwareWithout it, the dashboard shows QAIRT as not installed and the rest works.
The dashboard is a static page (assets/dashboard.html) on a JSON API, which
NervesExampleVentunoQ.Dashboard lists: status, camera previews (MJPEG and
JPEG), the GPU and NPU checks, and every microcontroller control. For example:
curl http://nerves.local/api/mcu
curl -X POST -H 'content-type: application/json' -d '{"r": false, "g": true, "b": false}' \
http://nerves.local/api/mcu/leds/1| Module | Role |
|---|---|
NervesExampleVentunoQ.Dashboard |
HTTP routes |
NervesExampleVentunoQ.Status |
board state from procfs, sysfs and Nerves KV |
NervesExampleVentunoQ.Sampler |
CPU load and network throughput |
NervesExampleVentunoQ.Checks |
GPU and NPU checks |
NervesExampleVentunoQ.Cameras, Camera, MediaGraph, Bayer |
camera pipelines and previews |
NervesExampleVentunoQ.Mcu |
the microcontroller |
The code is under the Apache License 2.0, the documentation under CC-BY-4.0,
and c_src/tuning.h, from Raspberry Pi's libcamera, under BSD-2-Clause:
LICENSES/ has the texts and REUSE.toml says which applies where.