← All projects

Real-time GPU-accelerated coupled cardiac system: Integrating bidirectional interactions between living optogenetic monolayers and computational simulations

A dish of cultured mouse cardiac cells and a GPU simulation of cardiac tissue run side by side and respond to each other within milliseconds.

  • Published, PLOS Computational Biology 2026
  • Valibeigi, Kaboudian, Fenton, Bub

What it does

Reentrant arrhythmias start when an electrical wave keeps circling through heart tissue. They are hard to study because the experimenter has little control over the circuit.

Our system gives that control. A camera watches a monolayer of cultured mouse ventricular cells for contraction waves. A cardiac simulation, written with the Abubu.js WebGL library and running on a graphics card, works out where a wave should be. An Arduino then turns the result into a pattern on an 8 by 8 LED matrix, and the blue light depolarizes cells that express channelrhodopsin-2.

Earlier optical closed-loop setups mostly stimulated after a fixed delay following a detected wave. Here the model decides when and where to stimulate, so the tissue changes the stimulus and the stimulus changes the tissue. The whole rig is built from inexpensive parts and a 30 frames-per-second machine-vision camera.

Figure 1: a cellular automaton model of a heart with a reentrant wave, a monolayer grown around an obstacle, a fixed-delay loop, and the full coupled system
Fixed delay versus a coupled model. (A, B) A reentrant wave circling an obstacle in a 3D heart model and in a monolayer. (C) A closed loop with a fixed delay. (D) The full system: signals from the tissue update the model, and the model's predictions drive stimulation.

How the loop works

Four stages, repeated for every wave.

  1. DetectMotion detection on camera frames (each frame minus the one six frames earlier) shows contraction waves without voltage-sensitive dyes, so recordings can run for a long time. Two regions of interest give the wave's speed and an estimate of when it will reach a target region.
  2. SimulateA cellular automaton with a 256 by 256 grid runs in Abubu.js. Its excitability radius and threshold can be changed during an experiment, which gives planar waves and spirals.
  3. SynchronizeThe camera's TTL pulse counts frames on the Arduino, so the camera acts as the clock. The Arduino waits the computed delay itself and skips the variable latency of sockets and serial links.
  4. StimulateThe LED matrix lights the pattern the simulation asked for, below the tissue, at the moment the model predicts.
Figure 2: WebGL simulation, Node.js, microcontroller, LED matrix, cardiac tissue and camera connected in a loop
The loop. Node.js passes data between the simulation, the camera and the microcontroller over sockets, serial and TCP.

Timing and what the loop can do

Jitter
Standard deviation of the stimulation cycle period fell from 11.34 ms to 1.53 ms once the camera and microcontroller were synchronized.
Camera
A 30 fps camera is enough, because two regions of interest give sub-frame timing.
Proof of concept
Model-driven stimulation redirected waves in the monolayer away from their intrinsic direction. A fixed-delay protocol redirected them too, with more variable cycle periods.
Limits
Validated in monolayers only. The model assumes a constant wave speed.
Figure 6: optical layout with Basler camera, DMD projector, Olympus MVX10, Nikon Eclipse Ti-U, LEDs and photodiode
Optical setup. A camera images the monolayer from above through an Olympus MVX10; the LED matrix stimulates from below through a Nikon Eclipse Ti-U. A DMD projector creates artificial waves for validation, and a photodiode measures the light output.
Figure 3: simulated planar wave and spiral wave from the cellular automaton model
The simulation. (A) Planar waves. (B) A spiral wave. Color is cell voltage from 0 to 1; r and θ are the model's radius of excitability and threshold.

The model is swappable

The cellular automaton is fast and has two knobs, which makes it a good first model. The same framework can host differential-equation models such as Fenton-Karma or O'Hara-Virág-Varró-Rudy, and the paper points to tuning the model until it reproduces the tissue's own waves, which would give a digital cardiac twin.

Try the model

Both simulations below run live in your browser, on your graphics card. They use the same cellular-automaton rule, with the same two knobs: the radius of excitability and the threshold. Use the bar beside each canvas to change them, to switch colors, to speed up or pause.

2D tissue

Drag across the canvas to stimulate the tissue. Shift and drag, or choose "Place block" in the Draw menu, puts down a block that waves cannot cross. A wave that meets the end of a block can curl around it, which is how a spiral wave starts.

3D heart

Drag to rotate the heart. Double-click a spot on it to stimulate; holding Ctrl (or Cmd) and moving the mouse stimulates along the path. Shift and click places a block. On a phone, double-tap to stimulate and use the Draw menu to place blocks.

Code and installation

The repository is MIT licensed and written for people with limited coding experience. Exact versions, wiring and screenshots are in its README.

You need

  • Node.js and npm
  • A Basler camera and the Pylon SDK (6.0.1, development version)
  • Visual Studio, to compile the camera program
  • Arduino IDE, an Arduino Uno, an 8 by 8 DotStar LED matrix and the Adafruit DotStarMatrix library
  • Cardiac monolayers expressing channelrhodopsin-2 (protocol in the paper's supporting information)

Repository layout

  • ServerClient_CellularAutomaton_Simulation/ for the model-driven loop
  • ServerClient_FixedDelay/ for the fixed-delay loop
  • ServerClient_FKModel/ for the Fenton-Karma model
  • cpp_Camera-Code/ for camera acquisition and wave detection
  • Python_Data-Analysis/ for timing analysis

Set up the server

npm init            # set the entry point to server.js
npm install express
npm install socket.io
npm install serialport
npm install @serialport/parser-readline

Run it

  1. CameraIn Pylon Viewer set exposure to 30000 µs, 30 frames per second, and Line 3 as an output driven by Exposure Active. Close Pylon Viewer, then build the Grab program in Visual Studio (Release, x64).
  2. ArduinoWire the LED matrix as described in the README and upload ArduinoCode.ino.
  3. ServerStart it, then open the simulation in a browser:
    node server.js
    # then visit http://localhost:8081/
  4. Camera programRun Grab from its Release folder. Press s to save the last 500 frames and q to quit. Put camera_input.txt and threshold.txt next to Grab.exe; they hold the regions of interest, refractory frames (20 at 30 fps) and detection thresholds.

Cite this work

Valibeigi Y, Kaboudian A, Fenton F, Bub G (2026) Real-time GPU-accelerated coupled cardiac system: Integrating bidirectional interactions between living optogenetic monolayers and computational simulations. PLoS Comput Biol 22(8): e1014590. https://doi.org/10.1371/journal.pcbi.1014590

Figures are from the paper, published under a Creative Commons Attribution (CC BY) license.