Skip to content

EEG data stream, Windows, MacOS, TouchDesigner. Third-party developers can utilize the tools in this repository to implement real-time access to the EEG data from the BrainLink brainwave device within TouchDesigner.

Notifications You must be signed in to change notification settings

Macrotellect/BrainLinkParser-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BrainLink Pro is supported.

Pro_girl

BrainLink Lite is supported.

Lite20240909-110821 data_stream

BrainLinkParser-Python(EEG data stream, Windows, MacOS, TouchDesigner)

Python Version

  • Python 3.11. You need to have a brainwave detection device(BrainLink Lite or BrainLink Pro) to use the following code.
  • Buy from our website: https://o.macrotellect.com/index.html#v1
  • BrainLink Pro 259 USA$

SDK

  • Windows: BrainLinkParser.pyd
  • Macos: BrainLinkParser.so

Import

  • from BrainLinkParser import BrainLinkParser

Interface Parameters and Return Values

  • BrainLinkParser(eeg_callback(BrainLinkData)=None, eeg_extend_callback(BrainLinkExtendData)=None, gyro_callback(int, int, int)=None, rr_callback(int, int, int)=None, raw_callback(int)=None) Constructor

    Parameters Description
    eeg_callback EEG Data Callback Function, parameter is an object of BrainLinkData, default is None.
    eeg_extend_callback EEG Extended Data Callback Function, parameter is an object of BrainLinkExtendData, with a default value of None.
    gyro_callback Gyroscope Data Callback Function, parameters are integer values for x, y, z, with a default value of None.
    rr_callback Heartbeat RR Data Callback Function, parameters are integer values for rr1, rr2, rr3, with a default value of None.
    raw_callback Raw Data Callback Function, parameter is an integer type for 'raw', with a default value of None.
  • parse(byteData) Parse Data

    Parameters Description
    byteData Parameter is of type 'bytes'

BrainLinkData Explanation

  • signal

  • attention

  • meditation

  • delta

  • theta

  • lowAlpha

  • highAlpha

  • lowBeta

  • highBeta

  • lowGamma

  • highGamma

BrainLinkExtendData Explanation

  • ap

  • battery

  • version

  • gnaw

  • temperature

  • heart

Sample code provided for development reference

from cushy_serial import CushySerial
from BrainLinkParser import BrainLinkParser

def onRaw(raw):
    # print("raw = " + str(raw))
    return

def onEEG(data):
    print("attention = " + str(data.attention) +
          " meditation = " + str(data.meditation) +
          " delta = " + str(data.delta) +
          " theta = " + str(data.theta) +
          " lowAlpha = " + str(data.lowAlpha) +
          " highAlpha = " + str(data.highAlpha) +
          " lowBeta = " + str(data.lowBeta) +
          " highBeta = " + str(data.highBeta) +
          " lowGamma = " + str(data.lowGamma) +
          " highGamma = " + str(data.highGamma))
    return

def onExtendEEG(data):
    print("ap = " + str(data.ap) +
          " battery = " + str(data.battery) +
          " version = " + str(data.version) +
          " gnaw = " + str(data.gnaw) +
          " temperature = " + str(data.temperature) +
          " heart = " + str(data.heart))
    return

def onGyro(x, y, z):
    print("x = " + str(x) + " y = " + str(y) + " z = " + str(z))
    return

def onRR(rr1, rr2, rr3):
    print("rr1 = " + str(rr1) + " rr2 = " + str(rr2) + " rr3 = " + str(rr3))
    return

parser = BrainLinkParser(onEEG, onExtendEEG, onGyro, onRR, onRaw)

serial = CushySerial('/dev/cu.BrainLink_Pro', 115200)

@serial.on_message()
def handle_serial_message(msg: bytes):
    parser.parse(msg)
    # print(f"[serial] rec msg: {msg}")

Use in TouchDesigner

  • Macos:Place the BrainLinkParser.so file into the directory /Applications/TouchDesigner.app/Contents/MacOS/Lib, so that the module can be used directly within TouchDesigner
  • Windows system: Place the BrainLinkParser.pyd file into the directory C:\Program Files\Derivative\TouchDesigner\bin\Lib to use it in TouchDesigner

TD

FAQ

1.Don't know which COM port to choose for connection in Windows system?

video tutorial in this url https://youtu.be/ENkKVI4Av3k

After the computer's Bluetooth searches for the BrainLink Bluetooth device, pair it. The Bluetooth interface of the computer may display two BrainLink Pro device names. When pairing, please select the one with the headphone pattern in front of the device name.The computer will generate two virtual Bluetooth COM ports. When opening TouchDesigner, you don't know which COM port to choose for connection?

The correct answer is to select the output COM port for connection. So, how can you distinguish which COM port is for input and which is for output? You can go to the computer's Bluetooth settings interface, select more Bluetooth options, and then click on the COM port to see which one is the output port.

After the computer's Bluetooth locates the BrainLink Bluetooth device, proceed with the pairing. The computer will create two virtual Bluetooth COM ports. When you open TouchDesigner, you might be unsure which COM port to select for the connection.

The correct approach is to choose the output COM port for the connection. How can you identify which COM port is for input and which is for output? Navigate to your computer's Bluetooth settings, select additional Bluetooth options, and then click on the COM ports to see which one is designated as the output port.

About

EEG data stream, Windows, MacOS, TouchDesigner. Third-party developers can utilize the tools in this repository to implement real-time access to the EEG data from the BrainLink brainwave device within TouchDesigner.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published