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.
- Device: TI DLP NIRscan Nano EVM
- Interface: USB HID — VID
0451/ PID4200 - Host: Raspberry Pi 5 (or any Linux x86-64 / ARM machine)
sudo apt install libudev-dev libusb-1.0-0-dev python3-devpip install flask numpysudo cp 99-nirscanner.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules
sudo udevadm triggerWithout this step, running as a non-root user gives USB open failed.
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.
cd app
python3 main.pyOpen 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
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 |
# 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-waitPrints ASCII spectrum chart, saves results to nir_scan_<timestamp>.csv.
cd processing_app
python3 main.pyUpload saved CSV files for NIR band analysis and visualization. Runs on http://localhost:5001.
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": [...], ...}}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.shRequires: swig, cmake, gcc, libudev-dev, libusb-1.0-0-dev
sudo apt install swig cmake gcc_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
Native library and SWIG bindings by Weiwei Jiang.