Skip to content

MicroscopeMaestro/NIRscanNano

Repository files navigation

NIRscanNano

Python driver, Flask web dashboard, and CLI scan tool for the TI NIRscan Nano near-infrared spectrometer (900–1700 nm).

Runs on Raspberry Pi 5 (ARM64). Simulation mode available for development without hardware.


Hardware

  • Device: TI DLP NIRscan Nano EVM
  • Interface: USB HID — VID 0451 / PID 4200
  • Host: Raspberry Pi 5 (or any Linux x86-64 / ARM machine)

Installation

1. System dependencies

sudo apt install libudev-dev libusb-1.0-0-dev python3-dev

2. Python dependencies

pip install flask numpy

3. USB access without sudo

sudo cp 99-nirscanner.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules
sudo udevadm trigger

Without this step, running as a non-root user gives USB open failed.

4. Select the right compiled library

The native _NIRScanner.so must match your platform:

Platform Command
RPi 5 / ARM64 (Python 3) cp lib/_NIRScanner.so.3 _NIRScanner.so
RPi (32-bit, Python 2) cp lib/_NIRScanner.so.2.pi _NIRScanner.so
Linux x86-64 (Python 2) cp lib/_NIRScanner.so.2 _NIRScanner.so

The repo ships with the ARM64 version already in place as _NIRScanner.so.


Web Dashboard

cd app
python3 main.py

Open http://<pi-ip>:5000 in any browser.

Features:

  • Connect / disconnect device
  • Live spectrum scan with Chart.js plot
  • Configure scan parameters (type, patterns, repeats, wavelength range, width)
  • Lamp on/off control
  • Hibernate / secure standby
  • Auto-fallback to simulation mode when device is not connected

Web API

All endpoints return JSON.

Method Endpoint Description
GET /api/status Device status, temp, humidity, version
POST /api/connect Connect to device (or simulator)
POST /api/scan Run scan, returns wavelength + intensity + reflectance
POST /api/config Update scan parameters
POST /api/lamp {"state": true|false} — lamp on/off
POST /api/hibernate {"state": true|false} — hibernation mode
POST /api/secure_standby Put device in standby
GET /api/latest_scan Return most recent scan data

CLI Scan Tool

# Real device (waits for USB connection)
python3 scan_tool.py

# Simulation mode — no hardware needed
python3 scan_tool.py --simulate

# Exit immediately if device not found
python3 scan_tool.py --no-wait

Prints ASCII spectrum chart, saves results to nir_scan_<timestamp>.csv.


Post-Processing App

cd processing_app
python3 main.py

Upload saved CSV files for NIR band analysis and visualization. Runs on http://localhost:5001.


Testing Without Hardware (Simulation Mode)

Both the web app and scan tool fall back to SimulatedNIRS when no device is detected. Simulated scans return realistic 228-point spectra (900–1700 nm) with randomized noise.

To verify the web app works in simulation:

cd app && python3 main.py &
curl http://localhost:5000/api/status
# → {"connected": true, "simulated": true, ...}

curl -X POST http://localhost:5000/api/scan -H "Content-Type: application/json" -d '{}'
# → {"success": true, "results": {"wavelength": [...], "intensity": [...], ...}}

Compile from Source

Only needed if the pre-built .so files do not match your platform.

# Python 3
./src/scripts/compile_py3.sh

# Python 2
./src/scripts/compile_py2.sh

Requires: swig, cmake, gcc, libudev-dev, libusb-1.0-0-dev

sudo apt install swig cmake gcc

Project Structure

_NIRScanner.so         active compiled library (symlink/copy)
NIRS.py                Python wrapper class
scan_tool.py           CLI scan utility
update_config.py       scan config updater
test.py                basic device connection test
test.ipynb             Jupyter usage examples
app/                   Flask live dashboard
processing_app/        Flask post-processing app
lib/                   compiled .so variants (x86, ARM32, ARM64)
src/                   C++ source + SWIG bindings
99-nirscanner.rules    udev USB rule

Credits

Native library and SWIG bindings by Weiwei Jiang.

About

TI NIRscan Nano Python driver, scan CLI, and Flask web app for Raspberry Pi

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors