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.
Stream to numpy arrays with automatic buffer management.
Configurable sample rate (via decimation)
Memory-efficient numpy array storage
Real-time data loss monitoring
Complexity: ⭐⭐
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
High-performance acquisition with std::vector buffers.
Pre-allocated std::vector buffers
Real-time min/max/mean calculations
Efficient memory management
Frame loss detection
Complexity: ⭐⭐⭐
Key Features:
#include "adc_streaming.h"
#include "callbacks.h"
class Callback : public ADCCallback {
std::vector<int16_t> ch1_data; // Pre-allocated buffer
std::vector<int16_t> ch2_data;
void receivePack(ADCStreamClient* client, ADCPack& pack) override {
// Process incoming ADC data packets
}
};
// Create client and start streaming
ADCStreamClient client;
Callback callback;
client.setReceiveDataCallback(&callback);
client.startStreaming();
Complete implementation: stream_adc_1.cpp
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()
Implementation: stream_adc_2.cpp →
#include "adc_streaming.h"
// Define board IPs (master + slaves)
std::vector<std::string> hosts = {"192.168.0.114", "192.168.0.108"};
// Connect to all boards
ADCStreamClient client;
client.connect(hosts);
// Configure master board
std::string 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 (size_t i = 1; i < hosts.size(); i++) {
client.cloneConfig(master, hosts[i]);
}
// 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.
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: ⭐⭐
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 →
High-performance waveform generation with WAV files.
Pre-generated WAV file support
Efficient sample buffering
Configurable playback modes
Complexity: ⭐⭐⭐
Key Features:
#include "dac_streaming.h"
// Generate sine wave and write WAV
std::vector<int16_t> samples = generateSineWave(1000.0, 4096, 1.0);
writeWAV("waveform.wav", 4096, samples);
// Configure and stream
DACStreamClient client;
client.sendConfig("dac_rate", "125000000"); // 125 MS/s
client.setRepeat(2); // Repeat 2 times
client.startStreaming("./waveform.wav");
Complete implementation: stream_dac_1.cpp →
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')
Implementation: stream_dac_2.cpp →
#include "dac_streaming.h"
// Generate stereo sine waves
std::vector<int8_t> left = generate8bitSine(1000.0, 262144, 1.0);
std::vector<int8_t> right = generate8bitSine(1000.0, 262144, 1.0);
// Write stereo WAV and stream
writeStereoWAV("stereo.wav", 262144, left, right);
DACStreamClient client;
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()
Implementation: stream_dac_3.cpp →
#include "dac_streaming.h"
// Generate waveform in memory
std::vector<int16_t> waveform = generateSineWave(1000.0, 32768, 1.0);
// Load directly to FPGA memory
DACStreamClient client;
client.setMemory16Bit(1, waveform); // Channel 1
client.setMemory16Bit(2, waveform); // 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
Performance Optimization - Disable web interface for maximum performance