C Driver

ivanELECivanELEC United Kindgom
Hello, I want to use the C driver for the OpenBCI with the Cyton board: https://github.com/OpenBCI/OpenBCI_C to interface my Ultracortex with a C application.

I was wondering what compilation environments people are using for this driver. I am using CodeBlocks as an IDE on a Windows 10 with the GNU GCC Compiler from MingW and when I try to compile with the source and header file in my project, I get errors for many of the header files referenced in the openbci_c.h file including termios.h and sys/signal.h. I am assuming this is due to not using the right compiler (not having the relevant files). 

Can someone point me to the right development setup I should be using for this driver?

Many Thanks!

Comments

  • Hi ivanELEC,

      I'm working in an ubuntu 18.04 VM on a Windows 10 host using the Bled112 dongle to the ganglion so your mileage may vary significantly using a Cyton, especially if you're using a wifi shield. The virtual network adapter passthrough for that might be weird. But as far as compiler and IDE I was able to get everything to run fine using GCC 7.3.0 with Sublime Text 3.

      Here's the output of 'dpkg --list | grep compiler' from the guest OS:

    ii  g++                                        4:7.3.0-3ubuntu2                    amd64        GNU C++ compiler
    ii  g++-7                                      7.3.0-16ubuntu3                     amd64        GNU C++ compiler
    ii  gcc                                        4:7.3.0-3ubuntu2                    amd64        GNU C compiler
    ii  gcc-7                                      7.3.0-16ubuntu3                     amd64        GNU C compiler
    ii  libllvm6.0:amd64                           1:6.0-1ubuntu2                      amd64        Modular compiler and toolchain technologies, runtime library
    ii  libxkbcommon0:amd64                        0.8.0-1                             amd64        library interface to the XKB compiler - shared library

      Random troubleshooting note, in my experience for development it's usually easier to work with OS's that have package managers built into them than it is to develop on Windows. Windows works great as a VM host in these instances if you've got enough RAM to support it. But if that one thing you installed a binary for on Windows eight months ago to get the hex color of an area on your screen that one specific time just happens to have some dependency installed that's incompatible with what you're trying to do now it can be a bit of a nightmare to troubleshoot and fix the issue. 

      Again that's just my two cents and is a little bit outside the scope of your question but using an OS with a package manager would be one of many possible "right" development setups for this driver. And it might cause less headaches for you in the future! :)
  • wjcroftwjcroft Mount Shasta, CA
    Wonky, is your Ganglion C interface via BLED112, working? Do you have a Github? Florian @fwende may be interested in porting to Java / Android. His thread:

  • WonkybadonkWonkybadonk Idaho
    edited September 2018
    Hi William,

      Sorry for the delayed response! I've just been using a fork of the OpenBCI_C driver repo that's on OpenBCI_C. Mr. Keller merged one of my pull requests making some minor changes to find_port() (github user: zthurman) I'm awaiting the merge of the second pull request making some more slight modifications to find_port(). I've successfully started data streams for this driver on Ubuntu 18.04 using the BLED112. It just syncs up with either /dev/ttyS0 or /dev/ttyACM0 and starts giving me all the datas so far. Haven't seen the sigsegv referenced in some of the more recent commits and todo. 

      I'm not sure about the specifics of the referenced thread as far as android is concerned but based on the last comment it looks like a c to java would be more or less straightforward minus the initial jvm config. I'm more than happy to help the team with getting a java implementation going!
  • wjcroftwjcroft Mount Shasta, CA
    OK, I'm not sure I understand, since you mentioned Ganglion and BLED112 in your previous post. So I thought you were working on a C driver using BLED112 to talk to Ganglion. Your repo,


    Is the fork from OpenBCI's, and only talks to Cyton, using the Cyton dongle (serial port). Your last post says, "I've successfully started data streams for this driver on Ubuntu 18.04 using the BLED112." But your OpenBCI_C driver as it currently stands, ONLY talks to Cyton, not Ganglion. And only uses the Cyton dongle, not BLED112. Was your comment referring to using Ganglion with OpenBCI_GUI and the BLED112? Yes AJ set that up recently, but it is not C based.

    Sorry for my confusion. Maybe you will add a comment. The BLED112 does present a serial port to the OS, but it is a general interface for BLE devices (not Cyton, but does work with Ganglion using OpenBCI_GUI and Hub.)

    Regards,

    William

  • WonkybadonkWonkybadonk Idaho
    edited September 2018
    I think I'm as confused as you then. I've purchased a Ganglion, a CSR dongle and BLED112 dongle. When I launch the OpenBCI_C test.c with the BLED112 hooked up and run as sudo I receive the following after I fiddled with find_port() a bit:

    Using port /dev/ttyACM0
    Starting stream...
    SAMPLE NUMBER 0.774984
    Channel Number 1 : 4.59163e-41
    Channel Number 2 : 3.44777e+26
    Channel Number 3 : 4.57454e-41
    Channel Number 4 : 5.60519e-45
    Channel Number 5 : 0
    Channel Number 6 : 9.86301e+10
    Channel Number 7 : 3.07067e-41
    Channel Number 8 : 7.00649e-45
    Acc Channel 0 : -nan
    Acc Channel 1 : 98652905472.000000
    Acc Channel 2 : 0.000000
    Starting stream...
    SAMPLE NUMBER 0.774984
    Channel Number 1 : 0
    Channel Number 2 : 3.44777e+26
    Channel Number 3 : 4.57454e-41
    Channel Number 4 : 7.00649e-45
    Channel Number 5 : 0
    Channel Number 6 : 9.86301e+10
    Channel Number 7 : 3.07067e-41
    Channel Number 8 : 5.60519e-45
    Acc Channel 0 : -nan
    Acc Channel 1 : 98652905472.000000
    Acc Channel 2 : 0.000000
    Starting stream...
    SAMPLE NUMBER 0.774984
    Channel Number 1 : 4.59163e-41
    Channel Number 2 : 3.44777e+26
    Channel Number 3 : 4.57454e-41
    Channel Number 4 : 5.60519e-45
    Channel Number 5 : 0
    Channel Number 6 : 9.86301e+10
    Channel Number 7 : 3.07067e-41
    Channel Number 8 : 7.00649e-45
    Acc Channel 0 : -nan
    Acc Channel 1 : 98652905472.000000
    Acc Channel 2 : 0.000000
    Starting stream...
    SAMPLE NUMBER 0.774984
    Channel Number 1 : 0
    Channel Number 2 : 3.44777e+26
    Channel Number 3 : 4.57454e-41
    Channel Number 4 : 7.00649e-45
    Channel Number 5 : 0
    Channel Number 6 : 9.86301e+10
    Channel Number 7 : 3.07067e-41
    Channel Number 8 : 5.60519e-45
    Acc Channel 0 : -nan
    Acc Channel 1 : 98652905472.000000
    Acc Channel 2 : 0.000000
    Starting stream...
    SAMPLE NUMBER 0.774984
    Channel Number 1 : 4.59163e-41
    Channel Number 2 : 3.44777e+26
    Channel Number 3 : 4.57454e-41
    Channel Number 4 : 5.60519e-45
    Channel Number 5 : 0
    Channel Number 6 : 9.86301e+10
    Channel Number 7 : 3.07067e-41
    Channel Number 8 : 7.00649e-45
    Acc Channel 0 : -nan
    Acc Channel 1 : 98652905472.000000
    Acc Channel 2 : 0.000000

    I assumed that this was a successful stream with the Ganglion as I was getting errors prior to this and Silicon Labs the distributor of the BLED112 said to expect connections on /dev/ttyACM0 when using it on Linux. Is this not a successful stream?
  • wjcroftwjcroft Mount Shasta, CA
    No, it cannot be a successful stream, the C code is just printing data, assuming it came from a Cyton dongle. Your printout is complete gibberish. OpenBCI_C ONLY receives data from a Cyton, using a Cyton dongle.

    If you want to write a C interface for Ganglion, take a look at the OpenBCI Hub code, in the sections where it is talking to the BLED112.

    Sorry for my confusion.
  • WonkybadonkWonkybadonk Idaho
    edited September 2018
    You're good the confusion was on my end. The comment at the beginning of openbci_c.c just said 'This program provides serial port communication with the OpenBCI Board.' I assumed Ganglion was included in that using BLED112 and after the Code 412 errors that I had been receiving using the hub and gui back in July and August and issues with the nodejs and python implementations earlier this week I just wanted to see if I could get the device to talk at all. 

    Again I apologize for causing confusion, I just thought I finally had data and was happy XD I'll dig into the hub app and see if I can port the BLED112 Ganglion interface to c.
  • wjcroftwjcroft Mount Shasta, CA
    OpenBCI_Python requires a native Linux to speak with Ganglion, because of OS / BLE limitations. Windows Python will not work and Ubuntu VM under Windows, likely also will not do what you expect.

    The latest OpenBCI_GUI and Hub should be able to stream from your Ganglion, using either Windows or Linux. I suggest BLED112 dongle because it is simplest. The CSR dongle can work on Windows with the Zadig stuff; but more work to setup than BLED112. The Hub and GUI in July likely did not have working BLED112 support.

    Regards,

    William

  • WonkybadonkWonkybadonk Idaho
    edited September 2018
    I think I was actually able to get the OpenBCI_Python to talk to the Ganglion in the Ubuntu guest through the CSR dongle using BLE as of a few minutes ago. So I'm not sure that native Linux is required as long as you pass the dongle through to the guest in VMware Workstation 14.

    The only things that gave me trouble were that bluepy-helper.c needed to be manually 'maked' in the venv site packages for bluepy, I needed the yapsy dependencies dpkt and pycrypto that weren't listed in requirements.txt and after that I had to update bluepy from 1.0.5 specified in the requirements.txt up to 1.2.0 as the comment on line 152 of ganglion.py said. After this was all taken care of I was able to run user.py in the guest and I got the following as output and the light on the Ganglion went from blinking to solid blue:

    ------------user.py-------------
    WARNING: no plugin selected, you will only be able to communicate with the board. You should select at least one plugin with '--add [plugin_name]'. Use '--list' to show available plugins or '--info [plugin_name]' to get more information.
    Board type: OpenBCI Ganglion
    Port:  EB:6B:9A:B6:86:CE

    ------------SETTINGS-------------
    Notch filtering:True
    user.py: Logging Disabled.

    -------INSTANTIATING BOARD-------
    Looking for Ganglion board
    Init BLE connection with MAC: EB:6B:9A:B6:86:CE
    NB: if it fails, try with root privileges.
    Get mainservice...
    Got:Service <uuid=fe84 handleStart=23 handleEnd=30>
    Get characteristics...
    receive, properties: READ NOTIFY , supports read: True
    write, properties: WRITE NO RESPONSE WRITE , supports read: False
    disconnect, properties: WRITE NO RESPONSE WRITE , supports read: False
    Turn on notifications
    Connection established
    No daisy:
    4 EEG channels and 3 AUX channels at 200.0 Hz.

    ------------PLUGINS--------------
    Found plugins:


    --------------INFO---------------
    User serial interface enabled...
    View command map at http://docs.openbci.com.
    Type /start to run (/startimp for impedance 
    checking, if supported) -- and /stop
    before issuing new commands afterwards.
    Type /exit to exit. 
    Board outputs are automatically printed as: 
    %  <tab>  message
    $$$ signals end of message

    -------------BEGIN---------------
    % b'stop running\n'
    $$$
    % b'OpenBCI Ganglion v2'
    % b'.0.1\nGanglion-f122\n'
    % b'LIS2DH ID: 0x33\nMCP'
    % b'3912 CONFIG_1: 0x0F'
    % b'0000\n\n'
    $$$
    % b"send 'b' to start d"
    % b"ata stream\nsend 's'"
    % b' to stop data strea'
    % b'm\nuse 1,2,3,4 to tu'
    % b'rn OFF channels\nuse'
    % b' !,@,#,$ to turn ON'
    % b" channels\nsend '?' "
    % b'to print all regist'
    % b"ers\nsend 'v' to ini"
    % b'tialize board\n'
    $$$

    Is this a valid connect to the Ganglion using OpenBCI_Python or am I still not connected to my board?
  • wjcroftwjcroft Mount Shasta, CA
    I assume you have been able to get OpenBCI_GUI to stream data from your Ganglion?

    The best way to see if your Python connection is working, is to record some data with it / graph it. And then compare that data stream to what you see with the GUI. This is assuming you connect one or more channels to the scalp as shown in the tutorial. 

    If you have other Python questions or Ganglion issues, I suggest opening another thread. Since this thread is supposedly about C language interfacing to OpenBCI.

    Regards,

    William

Sign In or Register to comment.