Package: pyOpenBCI
OpenBCI PythonProvide a stable Python driver for all OpenBCI BiosensorsUsing this repo provides a building block for developing with Python. The goal for the Python library is toprovide a stable Python driver for all OpenBCI Biosensors, that:Allows Python users to install one module and use any board they chooseProvides examples of using Python to port data to other apps like lab streaming layerPerforms the heavy lifting when extracting and transforming raw binary byte streamsProvides a base for the beginner users to use Python to process their OpenBCI dataTo DoAdd Ganglion Aux DataRequirementsPython 2.7 or 3.4+Currently the Cyton works on Windows, Linux, and MacOS.Ganglion works on Linux only (Linux VM with enabled Bluetooth works as well).The WiFi shield is known to have reliability issues across different computer configurations. Using it effectively requires advanced technical skills and programming knowledge. Note that the code avaiable here has not been tested accross all platforms.InstallationFirst, make sure you have the necessary dependencies.pipinstallnumpypyserialbitstringxmltodictrequestsLinux users may needbluepyalso.Then you can use pip to install the OpenBCI module.pipinstall-ihttps://test.pypi.org/simple/pyOpenBCIOnce installed, try running the examples provided to make sure you can connect to your OpenBCI board.Important notesCurrently the Ganglion board can only be used with a Linux OS. The WiFi shield is known to have reliability issues across different computer configurations. Using it effectively requires advanced technical skills and programming knowledge. Note that the code avaiable here has not been tested accross all platforms.Getting StartedFirst you need to initialize your board with one of the following commands:For Cyton board:# For Windows replace '*' with the port numberboard=OpenBCICyton(port='COM*')# For MacOS and Linux replace '*' with the port numberboard=OpenBCICyton(port='/dev/ttyUSB*')To find the COM port you are connected to you can use the OpenBCI GUI. Otherwise you can leave the port number as None, and the function find_port() will run and connect to the first Cyton Dongle it finds.For Cyton + Daisy:# For Windows replace '*' with the port numberboard=OpenBCICyton(port='COM*',daisy=True)# For MacOS and Linux replace '*' with the port numberboard=OpenBCICyton(port='/dev/ttyUSB*',daisy=True)To find the COM port you are connected to you can use the OpenBCI GUI. Otherwise you can leave the port number as None, and the function find_port() will run and connect to the first Cyton Dongle it finds.For Ganglion:# For Linux replace '*' with the mac address.board=OpenBCIGanglion(mac='*')If you need to find the Ganglion mac address you can use an app likenRF connectto find the ganglion. Otherwise you can leave the mac address as None, and the function find_mac() will run (NOTE: You will need to run the script with sudo for this function to work).For Wifi Shield:board=OpenBCIWifi(shield_name='OpenBCI-2254',sample_rate=200)Sending commandsOnce you initialize the board you can use the commands on the OpenBCI SDKs (Ganglion,Cyton,Wifi Shield) to send commands to the board using python (make sure your commands are strings).# Write commands to the boardboard.write_command(command)Here is a table of the most common ones:Ganglion SDKCyton SDKCyton & Daisy SDK (Additional Commands)Wifi Shield SDK (Additional Commands)Turn Channels OFF1 2 3 41 2 3 4 5 6 7 8q w e r t y u iTurn Channels ON! @ # $ % ^ & *Q W E R T Y U IConnect to internal GND0Enable Synthetic Square Wave[[Disable Synthetic Square Wave]]Connect to DC SignalpSet Channels to DefaultdStart Streaming DatabbStop Streaming DatassSoft Resetvv;Enable AccelerometernDisable AccelerometerNInitializing StreamTo start your stream you can use the following command with a callback function. You can look at the examples folder for some pre-written callback functions.# Start streamboard.start_stream(callback)The output of the start_stream function is the OpenBCISample on the callback function. The OpenBCISample object has the following attributes:packet_id = The ID of the incomming packet.channels_data = The raw EEG data of each channel. 4 for the Ganglion, 8 for the Cyton, and 16 for the Cyton + Daisy.aux_data = Accelerometer data.Because the channels_data and aux_data is the raw data in counts read by the board, we need to multiply the data by a scale factor. There is a specific scale factor for each board:For the Cyton and Cyton + Daisy boards:Multiply uVolts_per_count to convert the channels_data to uVolts.uVolts_per_count=(4500000)/24/(2**23-1)#uV/countMultiply accel_G_per_count to convert the aux_data to G.accel_G_per_count=0.002/(2**4)#G/countFor the Ganglion BoardMultiply Volts_per_count to convert the channels_data to Volts.Volts_per_count=1.2*8388607.0*1.5*51.0#V/countMultiply accel_G_per_count to convert the aux_data to G.accel_G_per_count=0.032#G/countFor the Wifi ShieldThe Wifi Shield already outputs the data in Volts and the aux data in G.Example (Print Raw Data)To test this example, usepy Examples\print_raw_example.pyorpython Examples\print_raw_example.py.frompyOpenBCIimportOpenBCICytondefprint_raw(sample):print(sample.channels_data)board=OpenBCICyton(port='COM5',daisy=False)board.start_stream(print_raw)Example (Simple LSL Streamer)To run this example, usepy Examples\lsl_example.pyorpython Examples\lsl_example.py.frompyOpenBCIimportOpenBCICytonfrompylslimportStreamInfo,StreamOutletimportnumpyasnpSCALE_FACTOR_EEG=(4500000)/24/(2**23-1)#uV/countSCALE_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)deflsl_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)board=OpenBCICyton(port='COM5',daisy=False)board.start_stream(lsl_streamers)Who are we?The founder of the OpenBCI Python repository is Jermey Frey. The Python driver is one of the most popular repositories and has the most contributors!The contributors to these repos are people using Python mainly for their data acquisition and analytics.Get involvedIf you think you can help in any of the areas listed above (and we bet you can) or in any of the many areas that we haven't yet thought of (and here we'resureyou can) then please check out ourcontributors' guidelinesand ourroadmap.Please note that it's very important to us that we maintain a positive and supportive environment for everyone who wants to participate. When you join us we ask that you follow ourcode of conductin all interactions both on and offline.Contact usIf you want to report a problem or suggest an enhancement we'd love for you toopen an issueat this github repository because then we can get right on it. But you can also contact [AJ][link_aj_keller] by email (pushtheworldllc AT gmail DOT com) or ontwitter.Find out moreYou might be interested in:Purchase aCyton|Ganglion|WiFi ShieldfromOpenBCIGet taught how to use OpenBCI devices by [Push The World][link_ptw] BCI ConsultingAnd of course, you'll want to know our:Contributors' guidelinesRoadmapGlossaryOpenBCI boards are commonly referred to asbiosensors. A biosensor converts biological data into digital data.TheGanglionhas 4 channels, meaning the Ganglion can take four simultaneous voltage readings.TheCytonhas 8 channels andCyton with Daisyhas 16 channels.Generally speaking, the Cyton records at a high quality with less noise. Noise is anything that is not signal.Thank youThank you so much (Danke schÃ¶n! Merci beaucoup!) for visiting the project and we do hope that you'll join us on this amazing journey to make programming with OpenBCI fun and easy.License:MIT