Ganglion board now working with python on Linux
Hello,
If you survive these steps, please test it and give your feedback, here or, especially if you encounter bugs, on github.
The last few days I worked on the Python repo, and here it is, finally the Ganglion board can be used directly from python. There's a catch: because I have been using the "bluepy" library, it works only on Linux for now.
Still, if you have the right, OS now you can easily use it in you python programs, use the existing plugins to stream in LSL or OSC, etc. Of course the first thing I did was to stream signals to OpenViBE... and it works great, *at last* I can test this nice piece of hardware!
It is possible to switch-on the AUX channels and the impedance check -- in that sense this implementation might be now more advance than the Cyton one . I had to make some changes under the hood (e.g. enable automatic discovery for both ganglion and cyton from the "user.py" interface), in theory nothing should break if you have been using the python API before, my apologies if it is the case.
This implementation would not have been as smooth if it were not for the nice NodeJS code out there, thanks @pushtheworld
I hope that in the future one could switch from bluepy to another library which runs on Windows and Mac (if any of you knows one....).
As described in the README, you need a recent version of bluepy, which is included in the repo as a submodule. Hence you need to use "git clone --recursive https://github.com/OpenBCI/OpenBCI_Python.git" to get it all. After that run "make" inside the "bluepy/bluepy" folder. Yes, it's a bit hacky at the moment... and it's not over.
During my tests I encountered sever packet drops (15% of data were missing), I had to tune the parameters of my bluetooth dongle. To do type:
sudo echo 9 > /sys/kernel/debug/bluetooth/hci0/conn_min_interval
sudo echo 10 > /sys/kernel/debug/bluetooth/hci0/conn_max_interval
If you survive these steps, please test it and give your feedback, here or, especially if you encounter bugs, on github.
I only tested on my laptop running Ubuntu 16.04, so I'd be eager to know how it goes with other installations.
Enjoy
Comments
For example, when capturing some test data with my 4-channel Ganglion, the CSV has this content (I read in the data with R, so the column names V1...V10 were automatically generated):
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
21.99545 0 -0.07473816 0.025622053 0.11645300 0.239228296 0 0 0 NA
21.99553 1 0.09672316 -0.034968062 0.05697363 -0.133187179 0 0 0 NA
21.99556 2 0.03414341 -0.056973632 0.07048028 -0.065451985 0 0 0 NA
21.99558 3 -0.16342427 0.028073557 0.12382434 0.307541304 0 0 0 NA
21.99560 4 0.04805397 -0.001075221 0.08577086 -0.001419292 0 0 0 NA
21.99563 5 0.08750430 -0.062981781 0.05940831 -0.166068377 0 0 0 NA
Given the strange number of columns, I'm not sure how to interpret this.
Based on what I'm seeing in csv_collect.py:
- V1 = time since start
- V2 = ID's / row numbers
Beyond that, I'm guessing:- V10 is just junk from imperfectly parsing the file.
Do you have any idea what V7 - V9 represent?Thanks in advance!
I did notice that it said AUX data, I just have no idea what that means. I'm editing the .py and .yapsy-plugin now to allow us to record external events based on key strokes
Is that something I should submit to you as a pull request, or is there some other GitHub repo by the plugin's author who I should submit it to?
I was trying to use the keyDown() function from pygame to handle the event column. I *think* have the code working, but when I go to test it with user.py it doesn't see the pygame module. This is strange. I have pygame in my library. hmmmm
dongle.
I wonder if it's using the wrong hci device (the built-in one).
Strange that it would work fine with Jeremy's user.py but not with LSL.
python openbci_lsl.py --stream
and it hung on the part where it's looking for the board.Thank you for the clarification, @jfrey . Much appreciated!
Sorry, one more question - when you run LSL as a plugin, what are you doing with the output? Are you sending it to OpenVibe or MATLAB or something, so that you can record data + events that way?
I managed to build the stable version of OpenVibe on my Ubuntu machine. In the acquisition server it's asking me for a port. You said that Ganglion doesn't have ports, right? Hmmm. Am I going about connecting user.py --add streamer_lsl and OpenVibe correctly?
I've sucessfully connected the Ganglion Board with OpenViBE through LSL using NodeJS Ganglion.
I've displayed the signals (in time and frequency domain) and saw that everything is working well. But when I went to "Signal Information" from OpenViBE's window, I found that the sample rate of the signal acquired from OpenViBE is 256Hz, but as we know, the Ganglion Board has 200Hz sample rate. I was wondering if it's some particularity of LSL, or if there's some problem in the OpenViBE cofiguration?
stream_data.py
a version of a TCP streaming server that somehow oversamples OpenBCI from 250 to 256Hz.I wonder if the underlying cause is not the same in that case and in your case?
I will stick with OpenVibe for now because I do want to do real-time signals processing, but I'd be more comfortable training my own algorithm in Python or R than having a GUI try to do it automatically for me. I guess that's why some people use MATLAB for LSL, but I'm not really a MATLAB guy (and if I were, it would have to be Octave, the free version of MATLAB). Maybe I can train my own ensemble model in Python or R and then somehow load it into OpenVibe with a little hacking of their code.
Actually everything is working well, just this point that bothers me