HUMANNODENeuroNode EEG GuideProduct page →

4 · Record with Python (BrainFlow)

Goal: stream EEG into your own script, save it, and measure alpha power. BrainFlow has the same API in Python, C++, Java, C#, Julia, MATLAB, R and Rust.

Close OpenBCI GUI first. Only one program can use the amplifier at a time.

Step 1: Install

python3 -m pip install brainflow numpy

Step 2: Try it without hardware

BrainFlow has a synthetic board that produces fake EEG, which is perfect for writing your code first:

import time
from brainflow.board_shim import BoardShim, BrainFlowInputParams, BoardIds

board_id = BoardIds.SYNTHETIC_BOARD.value
board = BoardShim(board_id, BrainFlowInputParams())
board.prepare_session()
board.start_stream()
time.sleep(5)
data = board.get_board_data()          # rows = channels, columns = samples
board.stop_stream()
board.release_session()

eeg = BoardShim.get_eeg_channels(board_id)
fs = BoardShim.get_sampling_rate(board_id)
print(f"{data.shape[1]} samples at {fs} Hz on EEG rows {eeg}")

Step 3: Connect your kit

Change only the board ID and the connection parameters. Use the board type from your quick-start card:

params = BrainFlowInputParams()
params.ip_address = "192.168.4.1"      # Wi-Fi: the amplifier's IP
# params.serial_port = "COM3"          # USB dongle / Bluetooth serial: the port
board_id = BoardIds.CYTON_WIFI_BOARD.value   # ← the board type for your kit and connection
board = BoardShim(board_id, params)

BrainFlow lists every board in BoardIds. Print them with print(list(BoardIds)).

Step 4: Save to a file

from brainflow.data_filter import DataFilter

DataFilter.write_file(data, "session1.csv", "w")      # tab-separated, one row per channel
restored = DataFilter.read_file("session1.csv")

Step 5: Measure alpha (eyes closed vs open)

import time
from brainflow.board_shim import BoardShim, BrainFlowInputParams, BoardIds
from brainflow.data_filter import DataFilter

board_id = BoardIds.SYNTHETIC_BOARD.value     # change to your kit
board = BoardShim(board_id, BrainFlowInputParams())
eeg = BoardShim.get_eeg_channels(board_id)
fs = BoardShim.get_sampling_rate(board_id)
board.prepare_session()
board.start_stream()

def alpha_share(label, seconds=10):
    input(f"Press Enter, then keep your eyes {label} for {seconds} s…")
    board.get_board_data()                    # clear the buffer
    time.sleep(seconds)
    data = board.get_board_data()
    bands, _ = DataFilter.get_avg_band_powers(data, eeg, fs, True)   # delta, theta, alpha, beta, gamma
    print(f"eyes {label}: alpha = {bands[2]:.0%} of total power")
    return bands[2]

opened, closed = alpha_share("OPEN"), alpha_share("CLOSED")
board.stop_stream()
board.release_session()
print("Alpha goes up with eyes closed ✔" if closed > opened else "No alpha increase. Check O1/O2 contact.")

With electrodes on O1/O2, alpha should clearly rise with your eyes closed. That gives you a working, measurable brain signal in about 20 lines of code.

Step 6: Mark events

To relate EEG to what happened on screen, add a marker into the stream at each event:

board.insert_marker(1)     # e.g. 1 = stimulus shown, 2 = response

Markers appear in their own row of data (BoardShim.get_marker_channel(board_id)).

✅ Done. Next: Stream to other apps (LSL) →

Questions? Email contact@humannode.dev. Developer Platform customers get 3 months of direct technical support.