
WEST nrf52840 hydrophone node
mmontee/nrf52840_openWSN_sensor_node
This projects goal is to implement a acoustic sensor node using the XIAO nrf52840 and openWSN.

This projects goal is to implement a acoustic sensor node using the XIAO nrf52840 and openWSN.
XIAO AUDIO is an open-source printed circuit board by mmontee, from the mmontee/nrf52840_openWSN_sensor_node repository on GitHub, published under the MIT licence. It is a 2-layer board of 22 × 52 mm with 39 parts on 40 nets, routed with 242 tracks and 37 vias.
It is built around the AP62150Z6, ENS160-BGLT and BQ25185DLHR, with the NSR0320MW2 and S2B-PH-SM4-TB among its other parts. Its parts include 12 resistors, 9 capacitors, 5 ICs, 4 diodes and 3 connectors. It belongs with the audio and music and sensors and measurement boards of this library.
This project builds upon the foundation of the West_Lab_Hydrophone_Data_Logger. The initial objective was to integrate the nRF52840 into the existing hardware architecture, with the long-term goal of migrating all signal processing tasks from the Teensy 4.0 to the nRF52840. This consolidation of processing onto a single microcontroller is expected to yield significant power savings while decreasing the complexity, size, and cost of each sensor node.
The ultimate aim is to create a wireless acoustic sensor network using the XIAO nRF52840 and OpenWSN. In the current transitional phase, a Teensy 4.0 with a Teensy Audio Adaptor Board captures and processes acoustic signals, and samples are saved to an SD card. The output is passed through the wireless network to a central root node. This root node does not perform sensing; instead, it passes information to an LTE-M modem, which uses MQTT to send the processed data to a cloud storage solution.
A critical aspect of the final transition will be to incorporate appropriate signal conditioning hardware to replace the functionality of the Teensy Audio Adaptor Board.
The existing West Lab Hydrophone Data Logger PCB.
The existing West Lab Hydrophone Data Logger with an LTE-M modem.
Battery life estimates for the data logger without the XIAO nRF52840.
Battery life estimates for the data logger with the XIAO nRF52840.
Battery life estimates for a data logger with only the XIAO nRF52840 (Teensy 4.0 and Audio Adaptor Board removed).
Battery life estimates for the root node without a Teensy 4.0.
Battery life estimates for the root node with a Teensy 4.0.
The integration of the XIAO nRF52840 wireless mote introduces a significant power cost, primarily during idle periods.
The Root Node hardware is configured for constant availability and processing power rather than battery longevity. Its battery life is extremely limited.
Fortunately, foundational work has been completed in OpenWSN's nRF52840-DK implementation, which can be found in the develop_FW-893 branch. In this project, the nRF52840-DK is used as a programmer and debugger for the XIAO nRF52840 board.
This guide will step through the processes of:
This guide assumes you have the following hardware:

git clone https://github.com/openwsn-berkeley/openwsn-fw
git checkout develop_FW-893

cd openwsn-fw/projects/nrf52840-DK/
nrf52840_dk.emProject
Programming is done via the JTAG/SWD interface on the nRF52840-DK, which is exposed through the onboard J-Link debugger.
The connections are illustrated below.

We created the necessary connections using two methods:


Two changes must be made to the firmware to configure it for the XIAO nRF52840 platform: the UART and LED pin assignments must be updated.
bsp/uart.c. The image below shows the correct values for the XIAO nRF52840.

bsp/leds.c. The image below shows the correct values for the XIAO nRF52840.


Assuming the necessary connections are established between the XIAO nRF52840 and the nRF52840-DK:
03oos_openwsn as the active project by right-clicking its name in the "Project Explorer".



This project modifies openserial.c to execute functions when specific UART messages are received. Sensor nodes receive processed signal information from an external source (like the Teensy) and pass this data to the root node. The root node's UART output is then parsed by another device.
Incoming UART messages are parsed within openserial.c using a set of flags from openhdlc.h and command characters (cmdByte) defined in openserial.h, as shown below.
Flags
cmdBytes
Valid messages must be preceded by an HDLC_FLAG, begin with a valid command byte, contain the payload, and be terminated with a second HDLC_FLAG.
A message coming into openserial should have the form:
<HDLC_FLAG><cmdByte><payload><HDLC_FLAG>
We send information into the node using the following format, where '~' is the HDLC_FLAG, 'D' is the cmdByte, and '1234567890' is example data:
Example: ~D1234567890~
After a valid message is parsed, it is passed to a switch statement that acts on the received cmdByte. This byte triggers a specific action. Below, the code passes the incoming data as that action or does nothing if the node is the root.
Once the data is on the data bus, it can be read by a custom application (e.g., `uinject`) that will create a UDP packet containing the data to be passed over the network.
This document describes a low-level driver for the nRF52 Successive-Approximation Analog-to-Digital Converter (SAADC) peripheral. The driver is designed for simplicity and provides a blocking (synchronous) API for single-channel ADC conversions.
It is specifically tailored with pin definitions corresponding to the analog pins on the Seeed Studio XIAO nRF52840 board but can be adapted for other nRF52-based hardware.
adc_config_t) to set all major parameters.adc_sample() function waits for the conversion to complete before returning, simplifying application logic.The driver exposes three main functions for controlling the ADC.
void adc_init(const adc_config_t* config)Initializes the SAADC peripheral with the specified settings. This function must be called before any sampling can occur.
config: A pointer to a constant adc_config_t structure containing the desired ADC settings.bool adc_sample(uint16_t* result)Performs a single, blocking ADC conversion on the channel configured during initialization.
EVENTS_END interrupt flag. It then copies the conversion result from the internal buffer to the user-provided location. To save power, it stops the ADC after the sample is complete.result: A pointer to a uint16_t variable where the ADC conversion result will be stored. The value's range depends on the configured resolution (e.g., 0-1023 for 10-bit).true: If the conversion was successful.false: If the ADC was not initialized or the result pointer is NULL.void adc_uninit(void)Disables and powers down the SAADC peripheral to save energy.
adc_init() call is required before any new samples can be taken.Configuration is handled via the adc_config_t struct and several enum types.
adc_config_t StructureThis structure holds all the necessary parameters for the adc_init function.
typedef struct {
adc_resolution_t resolution;
adc_oversample_t oversample;
adc_reference_t reference;
adc_gain_t gain;
adc_acqtime_t acq_time;
adc_analog_input_pin_t pin;
} adc_config_t;adc_analog_input_pin_tSelects the physical analog input pin on the XIAO nRF52840.
| Enum Value | XIAO Pin | nRF52 Pin | nRF52 AIN |
|---|---|---|---|
ADC_PIN_A0 | A0 | P0.02 | AIN0 |
ADC_PIN_A1 | A1 | P0.03 | AIN1 |
ADC_PIN_A2 | A2 | P0.28 | AIN4 |
ADC_PIN_A3 | A3 | P0.29 | AIN5 |
ADC_PIN_A4 | A4 | P0.04 | AIN2 |
ADC_PIN_A5 | A5 | P0.05 | AIN3 |
adc_resolution_tSets the bit resolution of the conversion. Higher resolution provides more precision but takes longer.
ADC_RESOLUTION_8BITADC_RESOLUTION_10BIT (Common default)ADC_RESOLUTION_12BITADC_RESOLUTION_14BIT (Requires acquisition time ≥ 10µs)adc_oversample_tEnables hardware averaging to reduce noise. The ADC takes multiple samples and averages them into a single result.
ADC_OVERSAMPLE_DISABLEDADC_OVERSAMPLE_2X, _4X, _8X, _16X, _32X, _64X, _128X, _256Xadc_reference_tSelects the voltage reference for the conversion.
ADC_REFERENCE_INTERNAL: Internal 0.6V reference.ADC_REFERENCE_VDD_DIV_4: Uses VDD / 4 as the reference.adc_gain_tSets the gain for the internal pre-amplifier. The total input voltage range is determined by V_Reference / Gain.
| Enum Value | Gain | Input Range (with 0.6V VREF) | Input Range (with VDD/4 VREF) |
|---|---|---|---|
ADC_GAIN_1_6 | 1/6x | 0 - 3.6V | 0 - 6.0V (e.g., if VDD=3.3V → 0-4.95V) |
ADC_GAIN_1_5 | 1/5x | 0 - 3.0V | 0 - 5.0V (e.g., if VDD=3.3V → 0-4.125V) |
ADC_GAIN_1_4 | 1/4x | 0 - 2.4V | 0 - 4.0V (e.g., if VDD=3.3V → 0-3.3V) |
ADC_GAIN_1_3 | 1/3x | 0 - 1.8V | 0 - 3.0V (e.g., if VDD=3.3V → 0-2.475V) |
ADC_GAIN_1_2 | 1/2x | 0 - 1.2V | 0 - 2.0V (e.g., if VDD=3.3V → 0-1.65V) |
ADC_GAIN_1 | 1x | 0 - 0.6V | 0 - 1.0V (e.g., if VDD=3.3V → 0-0.825V) |
ADC_GAIN_2 | 2x | 0 - 0.3V | 0 - 0.5V (e.g., if VDD=3.3V → 0-0.4125V) |
ADC_GAIN_4 | 4x | 0 - 0.15V | 0 - 0.25V (e.g., if VDD=3.3V → 0-0.206V) |
Note: The actual input voltage range is limited by VDD. For example, with ADC_GAIN_1_6 and VDD at 3.3V, the effective input range is 0V to 3.3V. The most common setting for measuring a voltage from 0 to VDD (e.g., 3.3V) is to use ADC_REFERENCE_INTERNAL and ADC_GAIN_1_6.
adc_acqtime_tSets the acquisition time for the sample-and-hold capacitor. Longer times are needed for high-impedance sources.
ADC_ACQTIME_3USADC_ACQTIME_5USADC_ACQTIME_10USADC_ACQTIME_15USADC_ACQTIME_20USADC_ACQTIME_40USHere is a complete example of how to initialize, configure, and read from an analog pin.
#include "adc.h"
#include <stdio.h> // For printing
int main(void) {
// 1. Configure the ADC
// This example configures the ADC to read a voltage between 0-3.6V
// on pin A0 with 10-bit resolution.
const adc_config_t my_adc_config = {
.resolution = ADC_RESOLUTION_10BIT,
.oversample = ADC_OVERSAMPLE_4X, // Use 4x oversampling for better stability
.reference = ADC_REFERENCE_INTERNAL, // Use internal 0.6V reference
.gain = ADC_GAIN_1_6, // Use 1/6 gain (effective input range is 0.6V * 6 = 3.6V)
.acq_time = ADC_ACQTIME_10US,
.pin = ADC_PIN_A0
};
// 2. Initialize the ADC
adc_init(&my_adc_config);
// 3. Main loop to sample the ADC
while (1) {
uint16_t adc_raw_value;
This document describes adcread, a simple application component for the OpenWSN operating system. Its purpose is to periodically read an analog sensor using the adc driver and make the latest reading available to other parts of the system.
The application integrates with the OpenWSN kernel's opentimers service to schedule non-blocking, periodic ADC sampling. This makes it an efficient, low-power way to monitor a sensor.
ADC_READER_PERIOD_MS).adcread_get_value()) for other modules to retrieve the latest sensor data.adc peripheral driver, separating the application logic from the hardware-specific details.The adcread application exposes two public functions.
void adcread_init(void)adc driver with static settings defined within adcread.c. It then creates and schedules a periodic timer that will trigger an ADC reading.opentimers_init() has been successfully executed.uint16_t adcread_get_value(void)uint16_t representing the latest raw ADC conversion result.
Unlike the driver, the application's configuration is hard-coded within the adcread.c file for simplicity. To change these settings, you must edit the source file and recompile.
The following settings are applied in adcread_init():
// Statically defined configuration within adcread.c
adcread_vars.adc_config.resolution = ADC_RESOLUTION_12BIT;
adcread_vars.adc_config.oversample = ADC_OVERSAMPLE_DISABLED;
adcread_vars.adc_config.reference = ADC_REFERENCE_INTERNAL; // 0.6V reference
adcread_vars.adc_config.gain = ADC_GAIN_1_6; // Input range = 0.6V / (1/6) = 3.6V
adcread_vars.adc_config.acq_time = ADC_ACQTIME_10US;
adcread_vars.adc_config.pin = ADC_PIN_A0; // Reads from XIAO pin A0The sampling rate is controlled by a preprocessor macro:
// Defines the period for reading the ADC in milliseconds
#define ADC_READER_PERIOD_MS 5000 // Read ADC every 5 secondsHere is how to integrate and use the adcread application within the OpenWSN framework.
Call adcread_init() from the main system initialization function (e.g., in openwsn.c's openwsn_init function), ensuring it is called after the kernel services are available.
// In openwsn.c or your main application file
#include "adcread.h"
void openwsn_init(void) {
// ... other initializations
board_init();
scheduler_init();
opentimers_init();
// ... other initializations
// Initialize the ADC reader application
adcread_init();
// ... more initializations
scheduler_start();
Other application modules (e.g., a data packet creation module like `C6T` or a custom application) can get the latest sensor data by calling adcread_get_value().
// Example in another module that needs the sensor data
#include "adcread.h"
void send_sensor_data_task(void) {
uint16_t sensor_value;
// Get the latest value from the ADC reader app
sensor_value = adcread_get_value();
// Now, 'sensor_value' can be added to a packet payload
// to be sent over the 6LoWPAN network.
// ...
For error logging via openserial_printLog, ensure that COMPONENT_ADCREAD is defined in the opendefs.h file alongside other component IDs.
For certain applications, you might need to capture a rapid burst of samples. The following method uses a blocking loop to monopolize the CPU and capture samples as fast as the hardware allows, without yielding control to the OpenWSN scheduler.
Using a blocking loop in a cooperative OS like OpenWSN is dangerous and should be handled with extreme care.
This is achieved by creating a function that enters a tight `for` loop, calling `adc_sample()` in each iteration.
1. Define buffer and state variables:
First, define the buffer size in adcread.c and add necessary state variables to `adcread_vars_t`.
// adcread.c
#define ADC_BURST_BUFFER_SIZE 256 // Capture 256 samples per burst2. Create the blocking capture function:
This function will contain the blocking loop. After the capture is complete, it schedules a separate, non-blocking task to process the data, which is a safer way to handle potentially long computations.
// adcread.c -- function prototypes
void _adcread_process_task_cb(void); // Task to process data after capture
void adcread_capture_burst_blocking(void); // Public function to initiate a burst
// Public function with the blocking capture loop
void adcread_capture_burst_blocking(void) {
if (!adcread_vars.initialized || adcread_vars.burst_in_progress) {
return; // Exit if not ready or another burst is active
}
adcread_vars.burst_in_progress = true;
// Stop the periodic timer to prevent interference
opentimers_stop(adcread_vars.timer_id);
// --- START OF BLOCKING SECTION ---
// This loop takes full control of the CPU. No other tasks will run.
for (uint16_t i = 0; i < ADC_BURST_BUFFER_SIZE; i++) {
adc_sample(&adcread_vars.burst_buffer[i]);
}
// --- END OF BLOCKING SECTION ---
// Now that the time-critical capture is done, schedule a
// non-blocking task to process the data.
scheduler_push_task(_adcread_process_task_cb, TASKPRIO_ADC);
Sending a large buffer of raw samples over the network is inefficient. Processing the data on the mote first and transmitting only the result reduces network traffic and saves energy. The `_adcread_process_task_cb` function is the ideal place for this computation, as it runs as a standard, non-blocking OpenWSN task.
Example Processing Task:
// adcread.c -- processing task
void _adcread_process_task_cb(void) {
uint32_t sum = 0;
uint16_t min_val = 0xFFFF;
uint16_t max_val = 0x0000;
// Iterate through the collected samples
for (int i = 0; i < ADC_BURST_BUFFER_SIZE; i++) {
uint16_t sample = adcread_vars.burst_buffer[i];
sum += sample;
if (sample < min_val) {
min_val = sample;
}
if (sample > max_val) {
max_val = sample;
}
}
// Calculate the average
uint16_t average_val = (uint16_t)(sum / ADC_BURST_BUFFER_SIZE);
// Store the processed result in the main variable
// This makes it available via the standard adcread_get_value() function| Qty | Value | Footprint | References |
|---|---|---|---|
| 5 | 4.7k | Resistor_SMD:R_0603_1608Metric_Pad0.98x0.95mm_HandSolder | R11, R12, R13, R14, R15 |
| 3 | 10k | Resistor_SMD:R_0603_1608Metric_Pad0.98x0.95mm_HandSolder | R2, R4, R7 |
| 3 | 10uF | Capacitor_SMD:C_0603_1608Metric_Pad1.08x0.95mm_HandSolder | C3, C6, C8 |
| 3 | NSR0320 | Diode_SMD:D_SOD-323 | D1, D2, D3 |
| 2 | 1uF | Capacitor_SMD:C_0603_1608Metric_Pad1.08x0.95mm_HandSolder | C4, C5 |
| 2 | TestPoint | TestPoint:TestPoint_Pad_D1.0mm | TP1, TP2 |
| 1 | 100k | Resistor_SMD:R_0603_1608Metric_Pad0.98x0.95mm_HandSolder | R3 |
| 1 | 100n | Capacitor_SMD:C_0603_1608Metric_Pad1.08x0.95mm_HandSolder | C2 |
| 1 | 100nF | Capacitor_SMD:C_0603_1608Metric_Pad1.08x0.95mm_HandSolder | C9 |
| 1 | 10n | Capacitor_SMD:C_0603_1608Metric_Pad1.08x0.95mm_HandSolder | C7 |
| 1 | 1k | Resistor_SMD:R_0603_1608Metric_Pad0.98x0.95mm_HandSolder | R8 |
| 1 | 22uF | Capacitor_SMD:C_0603_1608Metric_Pad1.08x0.95mm_HandSolder | C1 |
| 1 | 2N7002 | Package_TO_SOT_SMD:SOT-23 | Q1 |
| 1 | 3.3uH | Project_Library:NRS4018T3R3MDGJ | L1 |
| 1 | 470 | Resistor_SMD:R_0603_1608Metric_Pad0.98x0.95mm_HandSolder | R16 |
| 1 | 52.3k | Resistor_SMD:R_0603_1608Metric_Pad0.98x0.95mm_HandSolder | R1 |
| 1 | AP62150Z6 | Package_TO_SOT_SMD:SOT-563 | U5 |
| 1 | BQ25185DLHR | Project_Library:WSON10_DLH_TEX | U2 |
| 1 | Conn_01x05_jst_zh | Connector_JST:JST_ZH_B5B-ZR_1x05_P1.50mm_Vertical | J1 |
| 1 | Connector_BarrelJack | Connector_BarrelJack:BarrelJack_Wuerth_694102107102_1.0x3.9mm | J2 |
| 1 | ENS160-BGLT | Project_Library:XDCR_ENS160-BGLT | U4 |
| 1 | LED | LED_SMD:LED_0603_1608Metric_Pad1.05x0.95mm_HandSolder | D5 |
| 1 | MntHole | MountingHole:MountingHole_3mm_Pad_Via | H1 |
| 1 | S2B-PH-SM4-TB | Project_Library:JST_S2B-PH-SM4-TB | P1 |
| 1 | SHT4x | Sensor_Humidity:Sensirion_DFN-4_1.5x1.5mm_P0.8mm_SHT4x_NoCentralPad | U6 |
| 1 | addrJumper | Jumper:SolderJumper-3_P1.3mm_Bridged12_RoundedPad1.0x1.5mm | JP1 |
| 1 | ~ | Project_Library:XIAO_ESP32 | U3 |

mmontee/nrf52840_openWSN_sensor_node
This projects goal is to implement a acoustic sensor node using the XIAO nrf52840 and openWSN.

AnmolS-EE/ESP32-IOT-PCB
A comprehensive, multi-sensor IoT telemetry dashboard built around the Freenove ESP32-WROOM development board. This custom KiCad printed circuit board (PCB) integrates precision environmental sensing, analog ambient…

SREERAJSVT/AIQPCB
An IoT-enabled multisensor platform for real-time monitoring, visualization, and predictive analysis of indoor air quality (IAQ) parameters





protolux-electronics/soleil_hardware
Hardware design files for Soleil, an open source power management and sleep control board for Raspberry Pi

It measures 22 × 52 mm and has 2 copper layers, 1.6 mm thick.
39 parts, built around the AP62150Z6, ENS160-BGLT, BQ25185DLHR and NSR0320MW2. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.
From the mmontee/nrf52840_openWSN_sensor_node repository on GitHub, at the commit this page was made from: the board is Hardware/XIAO_AUDIO/XIAO_AUDIO.kicad_pcb and its schematic Hardware/XIAO_AUDIO/XIAO_AUDIO.kicad_sch. PCBKit opens the board in the browser, with nothing to install.
Its repository publishes it under the MIT licence: you may reuse it on that licence's terms (keep the author's notice, and for a copyleft licence share your changes alike).