Synthesized Streaming Board to GUI

bushmanlbushmanl Utah, USA
edited April 2022 in OpenBCI_GUI

The Ganglion board is being shipped to me now. In the meantime, I am trying to get some proof of concept code written.
Goal is to stream synthesized board data to the OpenBCI GUI.
Installed brainflow 3.0.1 as that is what the OpenBCI GUI Github says it is using.
GUI version is 5.0.9 (2021/11/06 00:16:07)
In the GUI, set STREAMING (form external) IP to 239.255.255.255 and port to 6677,
started the session and then started data stream.

The code below is almost verbatim from the BrainFlow's examples.
The image is being written after importing to mne, but I don't see any data in the OpenBCI gui.

import time
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from brainflow.board_shim import BoardShim, BrainFlowInputParams, BoardIds

import mne
from mne.channels import read_layout

def import_to_mne():
    BoardShim.enable_dev_board_logger()
    # use synthetic board for demo
    params = BrainFlowInputParams()
    board = BoardShim(BoardIds.SYNTHETIC_BOARD.value, params)
    board.prepare_session()
    # board.start_stream()
    board.start_stream(450000, 'streaming_board://239.255.255.255:6677')
    time.sleep(60)
    data = board.get_board_data()
    board.stop_stream()
    board.release_session()

    eeg_channels = BoardShim.get_eeg_channels(BoardIds.SYNTHETIC_BOARD.value)
    eeg_data = data[eeg_channels, :]
    eeg_data = eeg_data / 1000000  # BrainFlow returns uV, convert to V for MNE

    # Creating MNE objects from brainflow data arrays
    ch_types = ['eeg'] * len(eeg_channels)
    ch_names = BoardShim.get_eeg_names(BoardIds.SYNTHETIC_BOARD.value)
    sfreq = BoardShim.get_sampling_rate(BoardIds.SYNTHETIC_BOARD.value)
    info = mne.create_info(ch_names=ch_names, sfreq=sfreq, ch_types=ch_types)
    raw = mne.io.RawArray(eeg_data, info)
    # its time to plot something!
    raw.plot_psd(average=True)
    plt.savefig('psd2.png')

def main():
    import_to_mne()

if __name__ == '__main__':
    main()

Comments

  • bushmanlbushmanl Utah, USA

    Running on Windows.

  • wjcroftwjcroft Mount Shasta, CA

    Hi Bushman,

    So you say your modified code is based on,

    https://brainflow.readthedocs.io/en/stable/Examples.html#python-mne-integration

    Yet that example is just doing the following: creating 10 seconds of synthetic data, then sending it to MNE for processing / plotting. No involvement of the GUI.

    Your code above seems to be referencing IP address 239.255.255.255. Where did you get this address? This type of address looks to me like an IP broadcast address. Which is generally not what you want to use. Does the GUI allow incoming streaming from external sources? I know the Networking Widget allows GUI to stream OUT via various protocols. Mentioning Richard @retiutut.

    A good place for asking Brainflow related questions, is on their Slack. Sign up via:

    https://brainflow.org/

    Regards, William

  • bushmanlbushmanl Utah, USA

    Thanks William,

    Correct, the code is plotting the data. But as well, it should be streaming the data simultaneously to the IP address/port. OpenBCI GUI 5.0.9 has input prompts indicating that it is able to stream in data from another external process. Likewise, I have a teammate that later was able to get it working on her Mac with the same code. For some reason I haven't been able to get it working for me on my Windows machine.

    The streaming_board capabilities are mentioned here for the OpenBCI GUI:
    https://docs.openbci.com/Software/OpenBCISoftware/GUIDocs/#brainflow-streaming-board-feature
    Which points to the brainflow docs:
    https://brainflow.readthedocs.io/en/stable/SupportedBoards.html?highlight=streaming_board#streaming-board
    Today, I followed those steps to stream out data from python and then stream it in with another python process successfully.
    The above GUIDocs also show that the GUI is able to use a streaming board to stream data out from the GUI. But I don't see those options available. Must be something coming in 5.1.0 as the screen capture shows 5.1.0-alpha.

    I downloaded Processing and the GUI (5.0.9) from github in in order to debug. But running the GUI code from Processing (at least the version I downloaded) is not working out of the box.

    Is there a possible build that has this working that I can be pointed to?
    The Networking widget with LSL seems to be my next best option.
    However, given the below statement from the GUIDocs, the streaming board option sounds perfect for creating a python application with MNE:
    "This method (streaming board) can be more reliable and quicker to implement than sending Time Series data out from the Networking Widget over UDP, LSL, or OSC!"

    Thanks and Regards
    Lamont

  • wjcroftwjcroft Mount Shasta, CA

    Richard @retiutut will know the answer.

  • wjcroftwjcroft Mount Shasta, CA

    Richard mentioned to me that he is working up a detailed response... So apologies for the delay.

  • retiututretiutut Louisiana, USA

    https://docs.openbci.com/Software/OpenBCISoftware/GUIDocs/#gui-to-external-process

    To access this feature now, you can use Processing 4 and the OpenBCI GUI development branch.

    When using streaming board in either direction, the BrainFlow versions need to be the same in case a channel was added or removed from the data format.

    5.1.0 has been a heavy lift and is almost done. We have also been working hard on software for Galea.

    Let me know if you have any more questions here on this thread.

    Take Care,
    RW

Sign In or Register to comment.