Coder Social home page Coder Social logo

neuropy's Introduction

NeuroPy

NeuroPy library written in python to connect, interact and get data from NeuroSky's MindWave EEG headset.

This library is based on the mindwave mindset communication protocol published by Neurosky and is tested with Neurosky Mindwave EEG headset.

Installation

  1. Download the source distribution (zip file) from dist directory or from PyPi
  2. Unzip and navigate to the folder containing setup.py and other files
  3. Run the following command: python setup.py install

Usage

  1. Importing the module: from NeuroPy import NeuroPy
  2. Initializing: neuropy = NeuroPy()
  3. After initializing, if required the callbacks can be set
  4. Then call neuropy.start() method, it will start fetching data from mindwave.
  5. To stop call neuropy.stop()

Obtaining Data from Device

  • Obtaining value: attention = neuropy.attention #to get value of attention_

    Other Variable attention, meditation, rawValue, delta, theta, lowAlpha, highAlpha, lowBeta, highBeta, lowGamma, midGamma, poorSignal and blinkStrength

  • Setting callback: A call back can be associated with all the above variables so that a function is called when the variable is updated. Syntax:

    setCallBack("[variable]",callback_function)
    

    for eg. to set a callback for attention data the syntax will be

    setCallBack("attention",callback_function)
    

    Other Variables: attention, meditation, rawValue, delta, theta, lowAlpha, highAlpha, lowBeta, highBeta, lowGamma, midGamma, poorSignal and blinkStrength

Sample Program 1 (Access via callback)

from NeuroPy import NeuroPy
from time import sleep

neuropy = NeuroPy() 

def attention_callback(attention_value):
    """this function will be called everytime NeuroPy has a new value for attention"""
    print ("Value of attention is: ", attention_value)
    return None

neuropy.setCallBack("attention", attention_callback)
neuropy.start()

try:
    while True:
        sleep(0.2)
finally:
    neuropy.stop()

Sample Program 2 (Access via object)

from NeuroPy import NeuroPy
from time import sleep

neuropy = NeuroPy() 
neuropy.start()

while True:
    if neuropy.meditation > 70: # Access data through object
        neuropy.stop() 
    sleep(0.2) # Don't eat the CPU cycles

Python Compatibility

Note

I only have MindWave mobile, and therefore this library is supposed to work on it. I do not promise if it will work on other models. Another library which was suggested to me after I wrote this library can be found HERE. I have not tested that library, and cannot give any guarantees. More about the difference between the models of MindWave can be found HERE.

More Information

lihashgnis.blogspot.in - A blog post

neuropy's People

Contributors

christophebossens avatar lihas avatar nekromant avatar soachishti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

neuropy's Issues

Cannot connect to NeuroSky headset

Hi, when I ran the code:

from NeuroPy import NeuroPy
from time import sleep
neuropy = NeuroPy()

def attention_callback(attention_value):
    """this function will be called everytime NeuroPy has a new value for attention"""
    print ("Value of attention is: ", attention_value)
    return None

neuropy.setCallBack(\"attention\", attention_callback)
neuropy.start()

try:
    while True:
        sleep(0.2)
finally:
    neuropy.stop()

I'm getting this error:

[Errno 2] could not open port /dev/rfcomm0: [Errno 2] No such file or directory: '/dev/rfcomm0'

Does anyone know why? I'm using a Mac and my NeuroSky headset is connected via bluetooth.

Index OutofBound

I am constantly receiving this error running the sample program

Unhandled exception in thread started by <bound method NeuroPy.__packetParser of <NeuroPy.NeuroPy.NeuroPy object at 0x10f3471d0>>
Traceback (most recent call last):
File "/Users/apple/Desktop/NeuroPy-0.1/NeuroPy/NeuroPy.py", line 106, in __packetParser
i=i+1; self.attention=int(payload[i],16)
IndexError: list index out of range

Is there any fix to this?

Exception in thread Thread-1:

I am getting the following error after running the script
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 505, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/pi/NeuroPy/NeuroPy/NeuroPy.py", line 146, in __packetParser
p1 = self.__srl.read(1).encode("hex") # read first 2 packets

Blink strenght in neurosky mindwave

Hi I am using neurosky mindwave module and connected it to arduino using bluetooth module.I am getting the attention and meditation value but the blink state in showing 0.

Please help in identifying the problem.

Neurosky mindawave Mobile 2 connection

We are trying to connect the headset but in your code there is no line in which you call the connect function. So. how can we connect your code with headset on windows10 without dongle

Clarify this is only for MindWave Mobile

Hello,

I tried using this and only realized after trying to google "rfcomm" since that's your device name that this is for bluetooth devices.

The current NeuroSky products are MindWave, MindSet and MindWave Mobile. The latter ones have Bluetooth, the first one does not.

You might want to point out at the beginning of the readme that this is for MindWave Mobile, since it's easily confused with the MindWave.

Info from http://support.neurosky.com/kb/general-21/what-is-the-difference-between-the-mindset-mindwave-mindwave-mobile-and-xwave

You could point to https://github.com/BarkleyUS/mindwave-python for people who use the original MindWave.

Cheers

I get this error after 10 seconds max

Unhandled exception in thread started by <bound method NeuroPy.__packetParser of <NeuroPy.NeuroPy.NeuroPy object at 0x1022b7a10>>
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/NeuroPy/NeuroPy.py", line 84, in __packetParser
p2=srl.read(1).encode("hex")
File "/Library/Python/2.7/site-packages/serial/serialposix.py", line 481, in read
raise SerialException('read failed: %s' % (e,))
serial.serialutil.SerialException: read failed: (9, 'Bad file descriptor')

Problem in running the Program

Traceback (most recent call last):
File "trialNy.py", line 4, in
neuropy = NeuroPy()
TypeError: 'module' object is not callable

Updates needed?

It seems this library is not updated to work with Python3. Could I fork it and make some updates? I am working on a group project that uses MindWave Mobile and I'm interested in contributing to this library as a result.

Multiple connection

Hi i'm trying to connect multiple headset. Here i attached my code:

issue

How can i connect multiple device at the same time(for example "COM3" and "COM5" simultaneously). Also It stops when i update rawLabel. raw updates continuously but att not. its working fine with console but with pyqt it stops.

Sincerly.

from PyQt4.QtGui import *
from PyQt4.QtCore import *
from NeuroPy import NeuroPy

portlar=[]
app = QApplication([])
window = QWidget()
window.setWindowTitle('Neurosky Connect')
attLabel = QLabel('Attention')
rawLabel = QLabel('Raw Data')
connectButton = QPushButton('Connect')
disconnectButton = QPushButton('Disconnect')
def disconnect():
connection1.stop() # NOT WORKING
def connect():
connection1=NeuroPy("COM3",9600)
connection1.setCallBack("attention",attWR)
connection1.setCallBack("rawValue",rawWR)
connection1.start()
def attWR(att):
attLabel.setText("Attention :"+ str(att))
print "Attention :",att
return None
def rawWR(raw):
rawLabel.setText("Raw Data :"+ str(raw))
print "Raw :",raw
return None

window.connect(connectButton, SIGNAL('pressed()'), connect )
window.connect(disconnectButton, SIGNAL('pressed()'), disconnect)
dizayn1 = QVBoxLayout()
dizayn1.addWidget(rawLabel)
dizayn1.addWidget(attLabel)
dizayn1.addWidget(connectButton)
dizayn1.addWidget(disconnectButton)
window.setLayout(dizayn1)
window.show()
app.exec_()

Linux

Hi,
I change my OS from windows to linux-Ubuntu. But there is no rfcomm for bluetooth. How can I fix/attach/etc?
Sincerly.

stop() function not working

on calling the stop() method, the thread which fetches data from mindWave should stop and mindWave should be disconnected but it is not happening and the thread continues to run.

checked on Ubuntu, not sure if the bug affects other platforms, however there is no reason to believe otherwise as the python code has no platform specific part.

getting raw data only

I'm getting only raw data while calling back attention data, does anyone know how to solve it?
this my code :
from NeuroPy.NeuroPy import NeuroPy
from time import sleep
abc = NeuroPy("COM3", 16550)
def attention_callback(attention_value):
"""this function will be called everytime NeuroPy has a new value for attention"""
print ("Value of attention is: ", attention_value)
return None

abc.setCallBack("attention", attention_callback)
abc.start()

I get:

self.rawValue = 1917
self.rawValue = 779
self.rawValue = -1625
self.rawValue = -744
self.rawValue = 1589
self.rawValue = 1028
self.rawValue = -1491
self.rawValue = -1111
Mindwave has already started!
self.rawValue = 1335
self.rawValue = 1809
self.rawValue = -426

Capture

I cannot obtain Blink Strength using ThinkGear communication protocol .

I read on Neurosky page that : """This data value is currently unavailable via the ThinkGear Serial Stream APIs. It is not directly available as output from any current ThinkGear hardware. For TGCD, see the TG_DATA_BLINK_STRENGTH data type for use with the TG_GetValueStatus() and TG_GetValue() functions."""

My Question is there any way to get blink strength from Bluetooth serial stream ? in other words : by using your module ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.