Examples
Knight Board
Section titled “Knight Board”import timefrom brainflow.board_shim import BoardShim, BrainFlowInputParams, BoardIds
# ── 1. Configure ──────────────────────────────────────────────────────────────params = BrainFlowInputParams()params.serial_port = "COM3" # adjust for your OSparams.other_info = '{"gain": 12}' # must match gain used in chon_ commands
board = BoardShim(BoardIds.NEUROPAWN_KNIGHT_BOARD, params)board_id = board.get_board_id()
eeg_channels = BoardShim.get_eeg_channels(board_id)sampling_rate = BoardShim.get_sampling_rate(board_id) # 125
# ── 2. Open session & start stream ───────────────────────────────────────────board.prepare_session()board.start_stream(450000)time.sleep(2) # wait for the board to stabilise
# ── 3. Enable channels ────────────────────────────────────────────────────────# Channels are OFF by default. Both the Knight Board and Knight Board IMU# require chon_ commands after start_stream() — without them you will see# no signal data.for ch in range(1, 9): time.sleep(0.5) board.config_board(f"chon_{ch}_12") time.sleep(1) board.config_board(f"rldadd_{ch}") time.sleep(0.5)
# ── 4. Read data ──────────────────────────────────────────────────────────────try: while True: time.sleep(1) data = board.get_current_board_data(sampling_rate * 1) eeg_data = data[eeg_channels, :] # shape: (8, num_samples), µV print(f"Received {eeg_data.shape[1]} samples")
# ── 5. Clean up ───────────────────────────────────────────────────────────────finally: board.stop_stream() board.release_session()Knight Board IMU
Section titled “Knight Board IMU”The IMU variant uses NEUROPAWN_KNIGHT_BOARD_IMU. Channel activation is
identical to the standard board — chon_ and rldadd_ commands are still
required after start_stream(). IMU data is available on top of the standard
EEG channels.
import timefrom brainflow.board_shim import BoardShim, BrainFlowInputParams, BoardIds
ACCEL_CHANNELS = [11, 12, 13] # x, y, zGYRO_CHANNELS = [14, 15, 16] # x, y, zMAG_CHANNELS = [17, 18, 19] # x, y, z
params = BrainFlowInputParams()params.serial_port = "COM3"params.other_info = '{"gain": 12}'
board = BoardShim(BoardIds.NEUROPAWN_KNIGHT_BOARD_IMU, params)board_id = board.get_board_id()
eeg_channels = BoardShim.get_eeg_channels(board_id)sampling_rate = BoardShim.get_sampling_rate(board_id)
board.prepare_session()board.start_stream(450000)time.sleep(2)
for ch in range(1, 9): time.sleep(0.5) board.config_board(f"chon_{ch}_12") time.sleep(1) board.config_board(f"rldadd_{ch}") time.sleep(0.5)
try: while True: time.sleep(1) data = board.get_current_board_data(sampling_rate * 1)
eeg_data = data[eeg_channels, :] # (8, n) µV accel_data = data[ACCEL_CHANNELS, :] # (3, n) gyro_data = data[GYRO_CHANNELS, :] # (3, n) mag_data = data[MAG_CHANNELS, :] # (3, n)
print(f"EEG samples : {eeg_data.shape[1]}") print(f"Accel X mean: {accel_data[0].mean():.4f}")
finally: board.stop_stream() board.release_session()