Thanks to visit codestin.com
Credit goes to github.com

Skip to content

A comprehensive Arduino library in C++ for interfacing with RadiaCode radiation detection devices via Bluetooth Low Energy (BLE).

License

Notifications You must be signed in to change notification settings

mkgeiger/RadiaCode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

RadiaCode Arduino Library

RadiaCode

Arduino ESP32 Version License: MIT

A comprehensive Arduino library for interfacing with RadiaCode radiation detection devices via Bluetooth Low Energy (BLE). Designed for ESP32, but can easily ported to other BLE-capable microcontrollers.

πŸ“‹ Features

  • Comprehensive Device Control: Full access to RadiaCode device functionality
  • Real-time Data Acquisition: Monitor radiation levels, dose rates, and more
  • Spectrum Analysis: Analyze radiation energy spectrum data
  • Memory Optimized: ESP32-friendly memory management for stable operation
  • Error Handling: Robust error detection and reporting
  • User-friendly API: Intuitive interface for device interaction

🧩 Supported Hardware

  • Devices: RadiaCode-102, RadiaCode-103, RadiaCode-103G, RadiaCode-110
  • Microcontrollers:
    • ESP32

⚑ Quick Start

Installation

Using Arduino IDE Library Manager

  1. Open Arduino IDE
  2. Go to Sketch β†’ Include Library β†’ Manage Libraries
  3. Search for "RadiaCode"
  4. Click Install

Manual Installation

  1. Download this repository as a ZIP file
  2. In the Arduino IDE, go to Sketch β†’ Include Library β†’ Add .ZIP Library
  3. Select the downloaded ZIP file
  4. Restart the Arduino IDE

Basic Usage

#include <RadiaCode.h>

// Replace with your device's MAC address
const char* bluetoothMac = "11:22:33:44:55:66"; 

// Create RadiaCode instance
RadiaCode* radiacode = nullptr;

void setup(void)
{
  Serial.begin(115200);
  while (!Serial && millis() < 5000);

  Serial.println("Connecting to RadiaCode device...");
  radiacode = new RadiaCode(bluetoothMac);

  if (radiacode != nullptr)
  {
    String serialNum = radiacode->serialNumber();
    if (serialNum.length() > 0)
    {
      Serial.print("Connected to device: ");
      Serial.println(serialNum);
    }
  }
}

void loop(void)
{
  if (radiacode == nullptr) return;

  // Read radiation data
  std::vector<DataItem*> data = radiacode->dataBuf();

  // Process data
  for (DataItem* item : data)
  {
    // Check type without dynamic_cast for efficiency
    if (item->type == TYPE_REAL_TIME_DATA)
    {
      RealTimeData* rtData = static_cast<RealTimeData*>(item);
      Serial.print("Count rate: ");
      Serial.print(rtData->count_rate);
      Serial.println(" CPS");

      Serial.print("Dose rate: ");
      Serial.print(rtData->dose_rate * 10000.0f); // Convert to Β΅Sv/h
      Serial.println(" Β΅Sv/h");
    }
  }

  // Clean up data objects
  for (DataItem* item : data)
  {
    delete item;
  }
  data.clear();

  delay(1000);
}

πŸ“š Examples

The library includes several examples to get you started:

  • Basic: Simple connection and data reading
  • Spectrum: Acquire and visualize radiation spectrum data
  • Test: Test communication with the device

πŸ› οΈ API Reference

Main Classes

Class Description
RadiaCode Core class for device interaction
BytesBuffer Buffer management for protocol data
Spectrum Energy spectrum data handling

Key Methods

Method Description
dataBuf() Get real-time radiation measurements
spectrum() Get current radiation spectrum
spectrumAccum() Get accumulated spectrum
setAlarmLimits() Configure alarm thresholds
getTemperature() Get device temperature

Full Documentation

For detailed API documentation, see the RadiaCode API Reference.

πŸ“ˆ Spectrum Analysis

The library provides comprehensive tools for analyzing radiation spectrum data:

// Get spectrum data
Spectrum spectrum = radiacode->spectrum();

// Access spectrum parameters
uint32_t duration = spectrum.duration_sec;
float a0 = spectrum.a0;
float a1 = spectrum.a1;
float a2 = spectrum.a2;

// Process spectrum data
for (int i = 0; i < spectrum.size(); i++)
{
  uint32_t counts = spectrum.at(i);
  float energy = spectrumChannelToEnergy(i, a0, a1, a2);
  Serial.printf("Channel %d: %d counts, %.2f keV\n", i, counts, energy);
}

πŸ”„ Memory Optimization

The library is optimized for ESP32 and other microcontrollers with limited memory:

  • Uses static shared buffers to minimize heap fragmentation
  • Efficient data structures to reduce memory usage
  • Stack-friendly implementations to prevent overflow
  • Safe bounds checking throughout the codebase

πŸ“„ License

This library is released under the MIT License.

πŸ‘¨β€πŸ’» Author

Markus Geiger

πŸ”— Links

The implementation of this RadiaCode library in C++ was inspired by the cdump Python RadiaCode library (https://github.com/cdump/radiacode). I wanted to adapt it for Arduino platforms, mainly for the ESP32 (which supports BLE). Because RadiaCode does not publish the API documentation the only chance to implement this library was by studying the cdump Python library and reverse engineering the bluetooth protocol. Therefore are still some open points to be clarified, to be defined and to be done. So don't see the library implementation status as 100% complete and fully functional. But the main functions and beyond that work fine. Please feel free to improve the library and report also bugs. The usage of this library is therefore at your own risk. I assume no liability whatsoever.

About

A comprehensive Arduino library in C++ for interfacing with RadiaCode radiation detection devices via Bluetooth Low Energy (BLE).

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published