Skip to main content

Galvo interface

Galvo interface Rev. B

Drives the two driver boards of a galvo mirror pair. A XIAO ESP32-S3 generates the scan pattern and writes it to a 12-bit dual DAC. Op-amps turn the DAC voltage into the differential ±10 V signal that common galvo drivers expect. In sync with the scan, the board puts out pixel, line and frame triggers for a detector or a FLIM card. It also supplies the galvo drivers with ±12 V.

How to use it in a setup is covered in the galvo add-on. This page is the board reference.

Current revisionRev. B, 2026-09-25. Rev. A (2025-05) is electrically the same, with other reference designators and two extra holes.
ControllerSeeed XIAO ESP32-S3
DACMCP4822, 2 × 12 bit, SPI
OutputsX and Y, differential, ±10 V. Three 50 Ω trigger outputs. One 50 Ω laser blanking output.
Supply12 V from the bus. On board: 3.3 V, 5 V for the DAC and an inverting converter for −12 V. ±12 V are passed on, switched, to the galvo drivers.
FirmwareUC2_canopen_slave_galvo, in the web flasher as "Galvo satellite"
CAN node40
SourcesKiCad project · schematic PDF

The board wired to a galvo pair

Signal path​

XIAO ──SPI──> MCP4822 ──> op-amps (gain, offset, inverter) ──> X+ / X−, Y+ / Y−
├── pixel, line, frame ──> 50 Ω buffers ──> SMA
├── laser ──> 50 Ω buffer ──> U.FL
└── CAN ──> SN65HVD230 ──> bus

Both DAC channels are written first and then latched together with LDAC, so X and Y change at the same instant.

Connectors​

Top view with silkscreen

Reference designators are those of Rev. B. On Rev. A they have an extra zero (J101 is J1001 there, and so on).

RefTypePin 1 → nUse
J101JST XH 4GND, +12 V, CAN_H, CAN_Lbus. 12 V and GND alone are enough to run the board from USB.
J1053-pinGND, L−, L+signal to galvo driver "L"
J1063-pinGND, R−, R+signal to galvo driver "R"
J107, J1083-pin, 2.54 mm−12 V, GND, +12 Vsupply for the two galvo drivers
J1043-pin, 3.96 mm+12 V, GND, −12 Vsame supply on the larger plug some drivers use. Note the reversed order.
J109SMApixel trigger
J110SMAline trigger
J111SMAframe trigger
J1201U.FLlaser blanking
SW101push buttonD0 to GNDfree for firmware use

Check the pin order against the print on your galvo drivers before plugging in the supply. Swapping +12 V and −12 V destroys them.

XIAO pinout​

XIAO pinESP32-S3 GPIOFunction
D01push button (enable the pull-up)
D12pixel trigger
D23line trigger
D34frame trigger
D45CAN TX
D56DAC LDAC
D643laser blanking
D744CAN RX
D87DAC SCK
D98DAC CS
D109DAC SDI

Solder jumpers​

FunctionRev. ARev. B
120 Ω CAN termination. Close only at a physical end of the bus.JP2001JP201
CAN activity LEDJP2002JP202

Firmware​

EnvUC2_canopen_slave_galvo
Pin mapmain/config/UC2_canopen_slave_galvo/PinConfig.h
Scanner codemain/src/scanner/GalvoController.cpp
BusCANopen, 500 kbit/s, node 40
USBserial JSON over USB-CDC

Flash it as described in Flashing the firmware. If the XIAO does not accept the upload, hold BOOT while plugging it in.

Coordinates are DAC counts, 0 to 4095, with 2048 in the middle:

{"task":"/galvo_act","galvo":{"x":2048,"y":2048}}
{"task":"/galvo_act","stop":true}

Raster scans and point lists are described in the serial command reference and in the add-on's scan parameters and trigger outputs.

Bring-up​

  1. Connect 12 V. Without CAN the board still runs, controlled over USB.
  2. Connect each galvo driver with its 3-pin supply and its signal cable.
  3. Flash the firmware and start a slow scan.
  4. Look at the pixel trigger on an oscilloscope to confirm the timing.
  5. Tune the trim pots on the galvo drivers for minimal overshoot.

A 512 × 512 scan

A 512 × 512 scan, recorded with a FLIM LABS detector and pulsed laser.


Boards: shop.openuc2.com. Questions: openuc2.discourse.group.

Stand-alone scanner firmware (openUC2-LaserScanner)​

Before the scanner became part of uc2-esp32 there was a small dedicated firmware. It has no CAN support, but it is short and a good starting point for experiments with the render loop. Source: openUC2/openUC2-LaserScanner.

warning

Sometimes the XIAO cannot be flashed immediately, for this you have to press boot and reset while firmware is flashed - or erase the firmware first using this tool: https://espressif.github.io/esptool-js/

LayerKey filesFunction
Applicationsrc/main.cppInstantiates SPIRenderer, updates parameters in a while(1) loop, and calls start(); disables the watchdog and raises log level to warn for GPIO. (GitHub)
Render Enginesrc/SPIRenderer.{h,cpp}Converts image geometry into DAC samples, handles SPI transfers, and asserts pixel/line/frame triggers with single–cycle GPIO writes. Implements setParameters(), draw(), start(). (GitHub)
Board-select macrossame headerIS_XIAO, IS_XIAO_UC2GALVOBOARD choose the correct pin map at compile time. (GitHub)
Build systemplatformio.iniTwo build environments: esp32dev (generic) and UC2_3_Xiao (Seeed XIAO ESP32-S3). Both use ESP-IDF with Arduino component; UART at 921 kbit s⁻¹. (GitHub)

1 File structure​

openUC2-LaserScanner
├── src/ # C++ sources
│ ├── main.cpp # app_main() entry point
│ ├── SPIRenderer.cpp # raster engine
│ └── SPIRenderer.h
├── include/ # (optional) extra headers
├── lib/ # third-party libs, e.g. UC2-CAN
├── python/ # helper scripts (ILDA, LUT generation)
├── KICAD/ # electrical design
├── platformio.ini # build targets
└── sdkconfig.* # pre-tuned IDF configs

2 Build flow (PlatformIO)​

  1. Select UC2_3_Xiao in platformio.ini.
  2. pio run → ESP-IDF CMake → compile + link with Arduino component.
  3. pio run -t upload flashes over USB-CDC (921 kbit s⁻¹).
  4. Partition scheme custom_partition_esp32s3.csv reserves PSRAM cache and 1 MiB for OTA.

3 Runtime tasks​

TaskCore affinityDuty
mainTask (app_main)core 0parameter sweep, calls renderer, yields 10 ms to scheduler.
IDF idle0/1core 0/1housekeeping (watchdog disabled for main).
Additional tasks (optional)—CAN listener, WebSocket, or CLI can be added; use xTaskCreatePinnedToCore.

The code presently runs everything in the foreground; heavy processing (e.g. CAN command parsing) should be off-loaded to a FreeRTOS task to keep the raster loop deterministic.

4 SPIRenderer workflow​

constructor()
├─ configure GPIO for laser, LDAC, triggers
├─ initialise SPI3 @20 MHz (XIAO) or HSPI (generic)
└─ pre-compute nX, nY from (X_MIN…X_MAX)/STEP

start()
└─ draw()

draw()
for each frame
assert all triggers high ← frame start
for X = X_MIN…X_MAX
for Y = Y_MIN…Y_MAX
clear triggers
hold LDAC low
SPI out 16-bit word to DAC-A (X)
SPI out 16-bit word to DAC-B (Y)
release LDAC ← both axes latch simultaneously
set pixel trigger, delay tPixelDwelltime µs
issue line trigger each X-loop
clear all triggers ← frame end
  • Timing – esp_rom_delay_us() delivers sub-µs waits; replace with a hardware timer ISR for dwell times <5 µs.
  • Throughput – one SPI transaction per axis, LDAC latched once per pixel → 2 × 16 bits @ 20 MHz ≈ 1.6 µs transfer; 512×512 raster ≈ 0.42 s per frame exclusive of galvo settling.
  • Triggers – 50 Ω back-termination; rising edge marks start of integration for FLIM/PMT cards.

5 Customisation hooks​

Use caseModification
Different image sizecall setParameters() with new limits/step; renderer recomputes nX/nY without reallocating.
External controladd a CAN listener task that writes into a shared parameters struct guarded by a mutex; call renderer->start() from that task.
Scan patternsreplace the two nested for loops with a lookup table of (x,y) pairs (e.g. spiral, Lissajous).
Higher speeduse queued (spi_device_queue_trans) DMA transfers and toggle LDAC from SPI post-trans callback to overlap SPI and galvo settling.

6 Pin map (compile-time)​

SignalGPIO (UC2-Galvo)GPIO (bare XIAO)
MOSI97
SCK78
CS89
LDAC66
TRIG PIXEL22
TRIG LINE33
TRIG FRAME44
LASER blank4343

Defined in SPIRenderer.h; switch boards via -DIS_XIAO_UC2GALVOBOARD or -DIS_XIAO build flag. (GitHub)

7 Extending the firmware​

  • Finite-state machine – wrap the renderer in a state class (IDLE, SCANNING, PAUSED).
  • Streaming points – replace the nested loops by a ring buffer filled by CAN/UART for arbitrary point lists.
  • Persistent settings – store last used scan parameters to NVS (nvs_flash.h) and recall on boot.
  • Web OTA – enable esp_https_ota component and reserve second app partition (already present in custom_partition_esp32s3.csv).