Streaming Examples

Complete, ready-to-run examples demonstrating ADC and DAC streaming capabilities using the Red Pitaya streaming client library.

All example source code is maintained on GitHub for easy access and continuous updates.


Prerequisites

Before running these examples:

  • Red Pitaya board with OS version 2.07 or newer

  • Streaming application running on Red Pitaya (see Streaming Quick Start). Either in the web interface or as command-line server.

  • Streaming command line client downloaded to your computer

  • Computer and Red Pitaya connected to the same network (LAN recommended)

  • Python 3.12 (or higher) or C++20 compiler installed on your computer

  • Unblocked network access for the streaming client application in your computer’s firewall/antivirus software.

Note

Firewall/Antivirus Configuration: If you experience issues with board detection or connection, ensure that Python/C++ is allowed network access in your firewall and antivirus software. Some security programs may block Python’s network communication, preventing the client from discovering Red Pitaya boards on the network.

For installation instructions, see Streaming Client Setup.


Quick Start

New to streaming? Start here:

The quick start guide shows a minimal working example to get you streaming data in under 5 minutes.


ADC Streaming Examples

Continuous data acquisition from Red Pitaya fast analog inputs to your computer.

Note

The code snippets below highlight key features. For complete, runnable examples with full error handling and documentation, follow the implementation links in each section.

Basic ADC Data Acquisition

Stream data from ADC channels with automatic memory management and real-time processing.

ADC Dual Channel Streaming

Stream to numpy arrays with automatic buffer management.

  • Configurable sample rate (via decimation)

  • Memory-efficient numpy array storage

  • Real-time data loss monitoring

Complexity: ⭐⭐

https://github.com/RedPitaya/RedPitaya-Examples/blob/main/python-api/Streaming/adc_1_stream.py

Key Features:

import streaming

# Configure streaming parameters
decimation = 256                    # Sample rate = 125 MS/s / decimation
capture_duration = 1                # seconds
ch1_state = 'ON'                    # Enable channel 1
ch2_state = 'ON'                    # Enable channel 2

# Create client and callback
client = streaming.ADCStreamClient()
callback = streaming.ADCCallback()  # Handles incoming data

# Start streaming
client.startStreaming()
client.wait()

Complete implementation: adc_1_stream.py


Multi-Board Synchronized ADC

Stream data from multiple Red Pitaya boards (4+ channels) with hardware-synchronized acquisition.

Features:

  • Master/slave synchronization for phase-coherent capture

  • Per-board data tracking and statistics

  • Configurable board IPs

  • Independent channel control per board

Complexity: Python ⭐⭐⭐ | C++ ⭐⭐⭐⭐


Implementation: adc_2_stream.py →

import streaming

# Define board IPs (master + slaves)
hosts = ['192.168.0.114', '192.168.0.108']

# Connect to all boards
client = streaming.ADCStreamClient()
client.connect(hosts)

# Configure master board
master = hosts[0]
client.sendConfig(master, 'adc_decimation', '64')
client.sendConfig(master, 'channel_state_1', 'ON')
client.sendConfig(master, 'channel_state_2', 'ON')

# Clone configuration to slaves
for slave in hosts[1:]:
    client.cloneConfig(master, slave)

# Start synchronized streaming
client.startStreaming()

DAC Streaming Examples

Continuous waveform generation on Red Pitaya fast analog outputs from your computer.

Note

The code snippets below highlight key features. For complete, runnable examples with full error handling and documentation, follow the implementation links in each section.

Single Channel WAV Output

Generate and stream signals from WAV audio files to DAC output.

DAC Waveform Streaming

Stream custom waveforms from WAV files to DAC outputs.

  • Configurable DAC rate (up to 125 MS/s)

  • Repeat mode (finite or infinite)

  • 16-bit sample format support

Complexity: ⭐⭐

https://github.com/RedPitaya/RedPitaya-Examples/blob/main/python-api/Streaming/dac_1_stream.py

Key Features:

import streaming
import numpy as np
from scipy.io.wavfile import write

# Generate waveform and save as WAV
t = np.linspace(0., 1., 1024)
data = 32767 * np.sin(2. * np.pi * frequency * t)
write('waveform.wav', sample_rate, data.astype(np.int16))

# Configure and stream
client = streaming.DACStreamClient()
client.sendConfig('dac_rate', '125000000')  # 125 MS/s
client.setRepeat(2)  # Repeat 2 times
client.startStreaming('./waveform.wav')

Complete implementation: dac_1_stream.py →


Stereo DAC Output

Stream stereo signals to both DAC channels with perfect synchronization.

Features:

  • Stereo WAV file generation

  • Independent waveforms per channel

  • Infinite loop playback

  • Synchronized output timing

Complexity: ⭐⭐⭐


Implementation: dac_2_stream.py →

import streaming
import numpy as np
from scipy.io.wavfile import write

# Create stereo waveform (2 channels)
stereo = np.vstack((channel1_data, channel2_data)).transpose()
write('stereo.wav', sample_rate, stereo)

# Stream with infinite repeat
client = streaming.DACStreamClient()
client.sendConfig('dac_rate', '262144')
client.setRepeatInf(True)
client.startStreaming('./stereo.wav')

Direct Memory Mode

Stream waveforms directly from memory buffers for zero-latency playback.

Features:

  • Zero file I/O overhead

  • Direct FPGA memory upload

  • Real-time waveform generation

  • Independent channel control

Complexity: ⭐⭐⭐


Implementation: dac_3_stream.py →

import streaming
import numpy as np

# Generate waveform in memory
waveform_data = (32767 * np.sin(2. * np.pi * t)).astype(np.int16).tolist()

# Load directly to FPGA memory
client = streaming.DACStreamClient()
client.setMemory16Bit(1, waveform_data)  # Channel 1
client.setMemory16Bit(2, waveform_data)  # Channel 2

# Start streaming from memory (no file needed)
client.startStreamingFromMemory()

API Reference

For detailed information about the streaming client classes, methods, and callback system:


Additional Resources