Quick Start Guide

This guide will get you up and running with microsync in minutes. It covers the basic setup and common usage patterns.

Basic Setup

  1. Install the Python driver:

    pip install pyserial
    # Copy the python/ directory to your project
    
  2. Connect your Arduino Due:

    from microsync import SyncDevice
    
    # Connect to device (replace COM4 with your port)
    sd = SyncDevice("COM4")
    print(f"Connected! Firmware version: {sd.version}")
    

Basic Event Scheduling

Simple Pulse Generation:

# Generate a 1ms pulse on pin A0
sd.pos_pulse("A0", 1000)
sd.go()

Repeating Events:

# Generate 10 pulses, 1ms each, every 50ms
sd.pos_pulse("A0", 1000, N=10, interval=50000)
sd.go()

Multiple Events:

# Schedule multiple events
sd.pos_pulse("A0", 1000, ts=0)      # At t=0
sd.pos_pulse("A1", 1000, ts=5000)   # At t=5ms
sd.pos_pulse("A2", 1000, ts=10000)  # At t=10ms
sd.go()

Using Context Manager for Precise Timing:

# Batch commands for precise timing
with sd as dev:
    dev.pos_pulse("A0", 1000, ts=0)
    dev.pos_pulse("A1", 1000, ts=5000)
    dev.pos_pulse("A2", 1000, ts=10000)
# All commands sent together

Laser Control

Basic Laser Shutter Control:

# Open all laser shutters
sd.open_shutters()

# Close specific shutters (Cy2 and Cy5)
sd.close_shutters(1 | 4)

# Select which lasers are enabled
sd.selected_lasers = 0b0110  # Enable Cy3 and Cy5

Laser Interlock:

# Check interlock status
print(f"Interlock enabled: {sd.interlock_enabled}")

# Disable interlock (for testing only)
sd.interlock_enabled = False

Acquisition Modes

Continuous Imaging:

# Configure timing
sd.shutter_delay_us = 1300
sd.cam_readout_us = 14000

# Start continuous acquisition
sd.start_continuous_acq(exp_time=200000, N_frames=15)
sd.go()

Stroboscopic Imaging:

# Start stroboscopic acquisition
sd.start_stroboscopic_acq(exp_time=200000, N_frames=15)
sd.go()

ALEX (Multi-spectral) Imaging:

# Select lasers for ALEX
sd.selected_lasers = 0b1111  # All lasers

# Start ALEX acquisition
sd.start_ALEX_acq(exp_time=50000, N_bursts=9)
sd.go()

System Control

Start/Stop Control:

# Start processing events
sd.go()

# Stop processing (events remain in queue)
sd.stop()

# Resume processing
sd.go()

Event Management:

# Clear all scheduled events
sd.clear()

# Check how many events are scheduled
print(f"Events in queue: {sd.N_events}")

# Get list of scheduled events
events = sd.get_events("us")
for event in events:
    print(f"{event.func} at {event.ts} {event.unit}")

System Status:

# Get detailed status
print(sd.get_status())

# Check if system is running
print(f"System running: {sd.running}")

# Get current system time
print(f"System time: {sd.sys_time_s:.3f} seconds")

Configuration

Timing Parameters:

# Set default pulse duration
sd.pulse_duration_us = 800

# Set camera readout time
sd.cam_readout_us = 14000

# Set shutter delay
sd.shutter_delay_us = 1300

Logging:

# Enable communication logging
sd = SyncDevice("COM4", log_file="sync.log")

# Or print to terminal
sd = SyncDevice("COM4", log_file="print")

Common Patterns

Timelapse Acquisition:

# Stroboscopic with timelapse
sd.start_stroboscopic_acq(
    exp_time=200000,
    N_frames=5,
    frame_period=1500000  # 1.5s between frames
)
sd.go()

Multi-channel Control:

# Control multiple pins simultaneously
with sd as dev:
    dev.pos_pulse("A0", 1000, ts=0)      # Laser 1
    dev.pos_pulse("A1", 1000, ts=1000)   # Laser 2
    dev.pos_pulse("A2", 1000, ts=2000)   # Laser 3
    dev.pos_pulse("A12", 100, ts=500)    # Camera trigger

Error Handling:

try:
    sd = SyncDevice("COM4")
    sd.pos_pulse("A0", 1000)
    sd.go()
except Exception as e:
    print(f"Error: {e}")
    # Handle error appropriately

Next Steps

Now that you have the basics:

  1. Explore the API: See Python API Reference for complete documentation

  2. Try examples: Check the Jupyter notebook for more complex scenarios

  3. Learn about hardware: Review the README for connection details

  4. Understand firmware: See the source code for technical details

Need help? Open an issue on GitHub or check the README.