#def print_raw(sample): # try: # #output.append(sample.channels_data) # print(sample.channels_data) # for i in range(1, MaxVal, StepInterval): # print(i) # except KeyboardInterrupt: # for i in range(1, MaxVal, StepInterval): # print('INTERRUPTED! Closing in: ', str(MaxVal-i)) # board.stop_stream() # #board.start_stream(print_raw) #print("Line 29") ### Write commands, while with keyboard interrupt ### board.write_command('b') while True: try: #output.append(board.parse_board_data().channels_data*SCALE_FACTOR_EEG) #output.append(board.parse_board_data().channels_data*SCALE_FACTOR_EEG) sample = board.parse_board_data().channels_data print(sample) sample_np = np.array(sample) print(sample_np) scaled_sample = sample_np * SCALE_FACTOR_EEG #print(type(scaled_sample)) output = np.vstack((output, scaled_sample)) except KeyboardInterrupt: board.stop_stream() print("Stream Stopped!")
else: sys.exit( 'Currently the Ganglion Python repo only works with Linux OS.') else: board = OpenBCIWiFi() valid_commands = '012345678!@#$%^&*qwertyuiQWERTYUI[]pdbsvnN;-=xXDzZASFGHJKLajbs?c<>' while True: command = input('--> ') if str(command).lower() in ['start', 'stream']: print('Starting Board Stream') stream_thread = threading.Thread(target=board.start_stream, args=(callback, ), daemon=True) stream_thread.start() elif str(command).lower() in ['stop']: board.stop_stream() elif str(command).lower() in ['exit']: sys.exit() elif all(c in valid_commands for c in command): try: board.write_command(command) except: raise else: print('Not a valid command')
from pyOpenBCI import OpenBCICyton from pylsl import StreamInfo, StreamOutlet import numpy as np SCALE_FACTOR_EEG = (4500000) / 24 / (2**23 - 1) #uV/count SCALE_FACTOR_AUX = 0.002 / (2**4) print("Creating LSL stream for EEG. \nName: OpenBCIEEG\nID: OpenBCItestEEG\n") info_eeg = StreamInfo('OpenBCIEEG', 'EEG', 8, 250, 'float32', 'OpenBCItestEEG') print("Creating LSL stream for AUX. \nName: OpenBCIAUX\nID: OpenBCItestEEG\n") info_aux = StreamInfo('OpenBCIAUX', 'AUX', 3, 250, 'float32', 'OpenBCItestAUX') outlet_eeg = StreamOutlet(info_eeg) outlet_aux = StreamOutlet(info_aux) def lsl_streamers(sample): outlet_eeg.push_sample(np.array(sample.channels_data) * SCALE_FACTOR_EEG) outlet_aux.push_sample(np.array(sample.aux_data) * SCALE_FACTOR_AUX) #print(np.array(sample.aux_data)*SCALE_FACTOR_AUX) board = OpenBCICyton(port='/dev/cu.usbserial-DM00D7TW') board.write_command('/2') # change the cyton AUX board mode to Analog mode. board.start_stream(lsl_streamers)