#openbci-sdk
An NPM module for OpenBCI
##Working with the Module
Initializing the board:
var OpenBCIBoard = require('openbci-sdk');
var ourBoard = new OpenBCIBoard.OpenBCIBoard();
You MUST wait for the 'ready' event to be emitted before streaming/talking with the board. The ready happens asynchronously so installing the 'sample' listener and writing before the ready event might result in... nothing at all.
var ourBoard = new require('openbci-sdk').OpenBCIBoard();
ourBoard.boardConnect(portName).then(function(boardSerial) {
ourBoard.on('ready',function() {
/** Start streaming, reading registers, what ever your heart desires */
});
}).catch(function(err) {
/** Handle connection errors */
});
The power of this module is in using the sample emitter, to be provided with samples to do with as you wish.
To actually get a sample you need to
- Start streaming
- Install the 'sample' event emitter
var ourBoard = new require('openbci-sdk').OpenBCIBoard();
ourBoard.boardConnect(portName).then(function(boardSerial) {
ourBoard.on('ready',function() {
ourBoard.streamStart();
ourBoard.on('sample',function(sample) {
/** Work with sample */
});
});
}).catch(function(err) {
/** Handle connection errors */
});
A sample is an object that has the following properties:
- startByte (number)
- sampleNumber (number)
- channelData (channel data indexed starting at 1 [1,2,3,4,5,6,7,8])
- auxData (aux data indexed starting at 0 [0,1,2])
- stopByte
You must have the OpenBCI board connected to the PC before trying to automatically find it.
If a port is not automatically found, then a list of ports will be returned, this would be a good place to present a drop down picker list to the user, so they may manually select the serial port name.
var ourBoard = new require('openbci-sdk').OpenBCIBoard();
ourBoard.autoFindOpenBCIBoard(function(portName,ports) {
if(portName) {
/**
* Connect to the board with portName
* i.e. ourBoard.boardConnect(portName).....
*/
} else {
/** Display list of ports */
console.log('Port not found... check ports for other ports');
}
});
- Plug usb module into serial port
- Turn OpenBCI device on
- Type
npm start
into the terminal in the project directory
npm test