This app records Basler or USB camera video with synchronized Arduino TTL outputs (gate, barcode, 1 Hz sync), and logs metadata.
- Basler and USB camera support (Basler via Pylon, USB via OpenCV)
- Live view with optional ROI cropping
- Recording with FFmpeg (GPU or CPU encoders)
- Per-frame metadata logging (timestamp, exposure, GPIO line status when available)
- Arduino TTL I/O via pyFirmata with live TTL plot
- Metadata templates saved to JSON plus TTL history saved to CSV
- Windows 10/11
- Python 3.10+ (recommended: Anaconda or Miniconda)
- FFmpeg in PATH
- Arduino with a Firmata sketch flashed (recommended:
StandardFirmata)
Optional (Basler cameras only):
- Basler Pylon SDK +
pypylon(camera drivers)
Create a fresh environment and install dependencies:
conda env create -f environment.yml
If you are using a system Python:
python -m venv .venv
.\.venv\Scripts\activate
pip install -r requirements.txtFFmpeg is used for encoding and saving video. The app uses raw frames piped to FFmpeg, so FFmpeg must be on PATH.
Option A (static build):
- Download a static build from https://www.gyan.dev/ffmpeg/builds/ (full or essentials).
- Extract to a folder like
C:\ffmpeg. - Add
C:\ffmpeg\binto your PATH.
Option B (BtbN build):
- Download a release from https://github.com/BtbN/FFmpeg-Builds/releases
- Extract and add
binto PATH.
ffmpeg -versionThe app supports these encoders:
h264_nvenc(NVIDIA GPU)h264_qsv(Intel QuickSync)libx264(CPU)
Notes:
h264_nvencrequires a compatible NVIDIA GPU and recent drivers.- If GPU encoding fails, switch to
libx264in the UI.
python main.py- Open Arduino IDE.
- Load
File > Examples > Firmata > StandardFirmata. - Flash it to the Arduino.
- Use the CamApp UI to scan and connect to the correct COM port.
Pin mapping is configured directly in the app (Gate, Sync, Barcode, Lever, Cue, Reward, ITI) and uses Firmata digital pin read/write.
Barcode timing notes:
Gap After Codeis the silent interval after one barcode word finishes.- Full barcode cycle time =
start pulse + start low + (bits * bit duration) + gap. - The app no longer depends on legacy custom Arduino sketches in this repo; use
StandardFirmata.
Install build tool:
pip install pyinstallerBuild a single-file EXE:
pyinstaller --onefile --noconsole --name CamApp main.pyThe output will be in dist/CamApp.exe. Copy it to the project root if desired:
copy dist\CamApp.exe .\Note: The compiled EXE still requires FFmpeg available on PATH at runtime.
- "FFmpeg not found": add FFmpeg to PATH and restart the terminal.
- "Failed to start Arduino TTLs": make sure no other app is holding the COM port, then reconnect.
- "No Basler camera found": verify Pylon is installed and the camera is detected by Pylon Viewer.
- "No USB camera found": verify the device is connected and not in use by another app.