diff --git a/README.md b/README.md index aa7d92b..47c08ea 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,53 @@ Python Library for OpenBCI ============== +This repository's purpose is to allow for programmers to interface with OpenBCI technology directly, both to acquire data and to write programs that can use that data on a live setting, using Python. -![alt tag](https://raw.github.com/theRealWardo/Python_OpenBCI/master/architecture.png) +If this is not what you are looking for, you can visit http://openbci.com/downloads and browse other OpenBCI software that will fit your needs. -- **open_bci.py** manages the connection between the OpenBCI board and Python -- **udp_server.py** exposes the data over UDP -- **socket_server.js** a Node.js server that retransmits the data over a Web Socket -- **htdocs/index.html** a hack to display data using D3.js - -Running the Server +## Dependency List -------------- -- Plugin the board -- `python udp_server.py --json` (add the `--filter_data` command to enable the band-stop filter on the board) -- Optionally use `python udp_client.py --json` to verify data is coming through -- Run `npm install` to make sure you have the dependencies -- Run `node socket_server.js` -- Visit [http://127.0.0.1:8880](http://127.0.0.1:8880) to see your brain waves -- Optionally use `python socket_client.py` to view the Web Socket data coming back into Python (requires socketio-client) +OpenBCI 8 and 32 bit board with 8 or 16 channels. +* Python 2.7 or later (https://www.python.org/download/releases/2.7/) +* Numpy 1.7 or later (http://www.numpy.org/) + +Use of specific features and scripts may require additional packages. -Running the Python server/client without the --json flag will cause the OpenBCISample object to be used as the data transmission mechanism. This is for people that want to do some processing in Python. +## Setup and Installation +------------- +Refer to http://docs.openbci.com/tutorials/01-GettingStarted -Dependency List +## Repository Hierarchy -------------- +### open_bci.py + +This file contains the class definition that instantiates an OpenBCI Board object and various helpful commands to interact with the board, including initializing communication with it. + +### test.py + +A simple piece of example code that should print values. + +### Utilities + +The `utilities` folder contains numerous tools with which to collect and sort data from the OpenBCI board. + +* `classifier` + + A good starting point. It includes openbci_collector.py (a class that tracks data and stores it in a CSV file) and pyeeg.py (a Python module to extract EEG features) + +* `pybrain_examples` + + Code that can be used in conjunction with PyBrain - the Python Machine Learning Library + +* `udp` + + This folder contains scripts needed to run a UDP server that streams OpenBCI data and a sample client for the server. + +## Additional Information +------------------- -Python UDP demos require: -- pyserial +To learn more about the Cognitive Technology Group, check out the Facebook page! +https://www.facebook.com/groups/CogTechBerkeley/ -Node sample requires: -- socket.io +This readme was adapted from that of https://github.com/OpenBCI/OpenBCI_Python -Python Web Socket requires: -- socketio-client diff --git a/open_bci.py b/open_bci.py index 4f00afa..88e687d 100644 --- a/open_bci.py +++ b/open_bci.py @@ -214,47 +214,52 @@ def read(n): toogle_position - An boolean indicating what position the channel should be set to. ***NEEDS TO BE TESTED*** - ***TODO: Change cascading ifs to mapping functions - + """ def set_channel(self, channel, toggle_position): #Commands to set toggle to on position if toggle_position == 1: - if channel is 1: - self.ser.write('q') - if channel is 2: - self.ser.write('w') - if channel is 3: - self.ser.write('e') - if channel is 4: - self.ser.write('r') - if channel is 5: - self.ser.write('t') - if channel is 6: - self.ser.write('y') - if channel is 7: - self.ser.write('u') - if channel is 8: - self.ser.write('i') - #Commands to set toggle to off position - elif toggle_position == 0: - if channel is 1: - self.ser.write('1') - if channel is 2: - self.ser.write('2') - if channel is 3: - self.ser.write('3') - if channel is 4: - self.ser.write('4') - if channel is 5: - self.ser.write('5') - if channel is 6: - self.ser.write('6') - if channel is 7: - self.ser.write('7') - if channel is 8: - self.ser.write('8') + self.ser.write(on_keys[channel]) + # if channel is 1: + # self.ser.write('q') + # if channel is 2: + # self.ser.write('w') + # if channel is 3: + # self.ser.write('e') + # if channel is 4: + # self.ser.write('r') + # if channel is 5: + # self.ser.write('t') + # if channel is 6: + # self.ser.write('y') + # if channel is 7: + # self.ser.write('u') + # if channel is 8: + # self.ser.write('i') + #Commands to set toggle to off position + elif toggle_position == 0: + self.ser.write(off_keys[channel]) + # if channel is 1: + # self.ser.write('1') + # if channel is 2: + # self.ser.write('2') + # if channel is 3: + # self.ser.write('3') + # if channel is 4: + # self.ser.write('4') + # if channel is 5: + # self.ser.write('5') + # if channel is 6: + # self.ser.write('6') + # if channel is 7: + # self.ser.write('7') + # if channel is 8: + # self.ser.write('8') + +# map the channel numbers to the desired output string +on_keys = {1: 'q', 2: 'w', 3: 'e', 4: 'r', 5: 't', 6: 'y', 7: 'u', 8: 'i'} +off_keys = {1: '1', 2: '2', 3: '3', 4: '4', 5: '5', 6: '6', 7: '7', 8: '8'} class OpenBCISample(object): """Object encapulsating a single sample from the OpenBCI board.""" diff --git a/test.py b/test.py new file mode 100644 index 0000000..5643bcb --- /dev/null +++ b/test.py @@ -0,0 +1,21 @@ +#import sys; sys.path.append('..') +# help python find open_bci.py relative to scripts folder + +import open_bci as bci +import os + +def printData(sample): + #os.system('clear') + print "----------------" + print("%f" %(sample.id)) + print sample.channel_data + print sample.aux_data + print "----------------" + + + +if __name__ == '__main__': + port = '/dev/ttyUSB0' + baud = 115200 + board = bci.OpenBCIBoard(port=port) + board.start(printData) \ No newline at end of file