Raspberry pi GPIO

Raspberry pi GPIO for Presentation

Mindaffect BCI is not limited to a screen based presentation. For example, physical lights and tactile vibrators can be used as means of stimulus. But first we need to connect our software to the desired hardware device (e.g. a lamp, LED, tactile vibrator). The software/hardware interfacing is done using GPIO. GPIO is a standard interface used to connect microcontrollers to other electronic devices. It can be used with sensors, diodes, displays, and System-on-Chip modules. For demonstration purposes we use a raspberry pi(Rpi) board. Any Rpi board with wireless connectivity is compatible with our software. In the rest of this section we discuss how to implement your physical presentation system of choice using Rpi’s GPIO.

You will need

Design concept

The BCI stimulus is represented by binary codes. To transfer that into a physical flickering pattern the LED/lamp/tactile vibrator will be ON when the code value is 1 and will be toggled to OFF when the code is value is 0. For example: Code 1011010 is represented by ON-OFF-ON for twice as long-OFF-ON-OFF. A raspberry pi zero W is used for demonstration purposes. Below you can see a schematic diagram of how the electronic hardware looks like for a 2 button presentation module Where one LED plays the binary pattern from code A and the other one plays the pattern from code B. It is up to you to decide how many LEDs you would like to use.

_images/gpiopizero.PNG

Software setup

The board needs to be programmed with the MindAffect GPIO software build on top of gpizero library. To do so, follow the steps below.

  1. Follow this guide to install the Raspbian OS and enable SSH on your Rpi.
  2. Now, connect to the raspberry pi via SSH and run the following command in the terminal
    sudo apt-get install git default-jre default-jdk python3 build-essential cli-common xterm ant gradle
  3. Clone the pymindAffectBCI repository by using the following command
    git clone https://github.com/mindaffect/pymindaffectBCI
  4. Install the necessary bits to your local python path:
    1. change to the directory where you cloned the repository.
    2. Add this module to the python path, and install dependencies
      python3 -m pip install -e .
  5. If you would like to configure the Rpi such that the MindAffect GPIO software automatically starts on boot, do the following:
    1. Open the autostart script by running the following command
      1. Sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
      2. Add the following line to the autostart file
        python3 -m mindaffectBCI.examples.presentation.rpigpio
      3. Press ctrl+x, then press Y and then Enter to save changes.
      4. The changes will take effect after a reboot.
  6. Make sure you are connected to the same WiFi network that is used by the machine running the MindAffectBCI software.
  7. The rpigpio python script uses GPIO pins 2,3,4 by default. You can customize it to your liking.
  8. Allright, the software is set up. Next, the hardware needs to be assembled.

Directions for setting up a minimum presentation hardware

  1. Connect the + pins of the LEDs to the GPIO pins
    1. By default pins 2,3,4 are used in the rpgpio.py script. You don’t have to use all the pins, but you need to inform the software about How many pins are going to be used by the LEDs
  2. Connect the - pins of the LEDS to the GND GPIO pin

  3. solder the micro USB cable to the power circuit pins
    • red wire –> 5v pin
    • black wire –> GND pin
  4. Connect the power circuit to the Rpi board.

    _images/LEDpresassembly.PNG
    Caution:If you are not familiar with safety cautions related to LiPo batteries use other safe batteries (such as AA battery packs) or learn how to safely use a LiPO battery. The power circuit & the battery can blow up if you plug in the battery the wrong way. Use at your own risk or choose a safe battery instead.
  5. As soon as the battery is connected to the power circuit the Rpi board will boot

  6. To shutdown the system, you can connect to the Rpi board via SSH and run the following command:
    1. Sudo shutdown -h now
    2. Then you can safely unplug the battery after the RPi’s green lights turn off
  7. Place all the assembled parts in the enclosure and insulator the electronics using hot glue.

    _images/LEDassembly.PNG

The final LED button looks like this:

_images/ledenclosure2.png _images/lednclosure1.png

To run the full demo

  1. On your host computer, go to the directory of pymindaffectBCI/mindaffectBCI . Open the online_bci.json file and set the presentation argument to None
    • “presentation”:”None”
  2. Now plug in the battery to the power circuit of the LED button and close the enclosure.

  3. Make sure your host computer and the LED button are connected to the same network

  4. The LED button should connect to the host computer and the presentation starts automatically and runs using the default arguments (see the code snippet below). You can set the following arguments in the rpigpio.py script:
    • Number of calibration and prediction trials

    • Number of LEDs

    • The LED to GPIO pin mapping

    • Speed of stimulus in Hz

      _images/ledpresconfig.PNG

Here’s how a one button LED presentation looks like (the LED button stays ON for a while when it is selected by the user’s brain response)

_images/LED_DEMO.gif

And a two button system looks like

_images/2_buttons.gif

RPI GPIO for control

You can control a physical device using MindAffect’s output module and a board with GPIO. For demonstration purposes we use GPIO pins of a raspberry pi board to control other physical devices.