fbpx

HITIBrain


Video tutorials

WELCOME TO our TUTORIALS

  • See how to control your Arduino with your Emotiv EEG headset.

For these tutorials, we used an Arduino Uno connected to the following devices (schematic) :

  • pin 3 : Switch
  • pin 5 : LED 1
  • pin 6 : LED 2
  • pin 8 : Servo
  • pin 13 : Built-in LED

INSTALLATION

1. INSTALLing HITIBrain

See how to install HITIBrain. The required Arduino libraries are automatically installed and updated by the software itself at each start.


To use HITIBrain, you will first need to install the Arduino IDE and the Emotiv Launcher.

CONNECTING THE DEVICES

2. Connecting your Arduino TO HITIBRAIN

(Same tutorial as HITIPanel)


See how to connect your Arduino to HITIBrain, by uploading a Reference sketch to your board.


Sketch

#include <HITIComm.h>

// sketch ID
// (used to identify the sketch running on your Arduino)
const char code_name[]    PROGMEM = "My sketch";
const char code_version[] PROGMEM = "1.0.0";

// button click counter
unsigned long clickCounter = 0;


void setup()
{
    // initialize HITIComm library
    HC_begin();

    // set sketch ID
    HC_codeName(code_name);
    HC_codeVersion(code_version);

    // set pin 3 as Digital Input (with internal pull-up)
    pinMode(3, INPUT_PULLUP);

    // set pin 5 and 6 as PWM Outputs
    HC_outputType(5, PWM);
    HC_outputType(6, PWM);
    pinMode(5, OUTPUT);
    pinMode(6, OUTPUT);

    // set pin 8 as Servo Output (initial position is 12.8°)
    HC_attachServo(8, 12800);

    // set pin 13 as Digital Output
    pinMode(LED_BUILTIN, OUTPUT);
}


void loop()
{
    // communicate with HITIPanel or HITIBrain
    HC_communicate();


    // read photoresistor on Analog Input 0, and convert value in %
    float rawSensorValue = analogRead(0);
    float sensorValueInPercent = HCS_map(rawSensorValue, 0, 1023, 0, 100);


    // use Analog Data 0 as a Metric in HITIPanel
    // => to display the sensor value in %
    HC_analogDataWrite(0, sensorValueInPercent);


    // use Analog Data 1 as a Setpoint in HITIPanel
    // => to set a threshold value for the sensor
    // => and to constrain this value between 0 and 100
    float threshold = HC_analogDataRead_setpoint(1, 0, 100);


    // use Digital Data 0 as an Indicator in HITIPanel
    // => which turns on if the sensor value exceeds the threshold value
    bool indicatorValue = (sensorValueInPercent > threshold);
    HC_digitalDataWrite(0, indicatorValue);


    // use Digital Data 1 as a Switch in HITIPanel
    // => to toggle the servo between 2 positions
    if (HC_digitalDataRead(1))
        // if Switch is activated, move Servo to position 169.3°
        HC_servoWrite(8, 169300);
    else
        // if Switch is deactivated, move Servo back to position 12.8°
        HC_servoWrite(8, 12800);


    // use Digital Data 2 as a Button in HITIPanel
    // => to increment a counter
    if (HC_digitalDataRead_click(2))
        // when Button is clicked, increment counter
        clickCounter++;

    // use Analog Data 2 as a Metric in HITIPanel
    // => to display the counter value
    HC_analogDataWrite(2, clickCounter);
}

3. Connecting your Emotiv headset

See how to connect your Emotiv EEG headset to HITIBrain.

CONTROLLING I/O WITH YOUR MIND

4. Using the Arduino I/O control panels

(Same tutorial as HITIPanel)


See how to control and monitor your Arduino inputs and outputs from the I/O Control Panels.

5. Controlling Arduino outputs with your mind

See how to use the Linker Panel to send commands from your Emotiv EEG headset to your Arduino outputs. Use your mind to turn on and off a LED, to control a LED intensity, and to move a servo.

CONTROLLING ANYTHING WITH YOUR MIND

6. Using the arduino data control panels

(Same tutorial as HITIPanel)


See how to create a user interface for your Arduino BCI project by using the Data Control Panels (Indicators, Virtual Switches, Virtual Buttons, Gauges, Sliders, Spinners).

7. Performing More advanced device control with your mind

See how to perform more advanced control of your Arduino with your mind by linking Emotiv commands to Virtual Switches and Rising Edges. Use your mind to blink a LED, to move a servo during 2s...

Sketch

#include <HITIComm.h>

// sketch ID
const char code_name[]    PROGMEM = "Actions With Duration";
const char code_version[] PROGMEM = "1.0.0";


// HITI Timers
HC_Timer myTimer1;
HC_Timer myTimer2;
HC_Timer myTimer3;


bool LED1_state = false;
bool LED2_state = false;
unsigned long servo_position = 0;
bool doPunctualAction = false;


void setup()
{
    // initialize library
    HC_begin();

    // set sketch ID
    HC_codeName(code_name);
    HC_codeVersion(code_version);

    // set pin 5 as DO Output (LED 1)
    pinMode(5, OUTPUT);

    // set pin 6 as DO Output (LED 2)
    pinMode(6, OUTPUT);

    // set pin 8 as Servo Output (initial position is 12.8°)
    HC_attachServo(8, 12800);
}


void loop()
{
    // communicate with HITIBrain
    HC_communicate();
    

    // --------------------------------------------------------------- 
    // Continuous Action : 
    // => triggered by Virtual Switch on Digital Data 0 
    //    (action runs as long as the Virtual Switch is activated)
    if(HC_digitalDataRead(0))
    {
        // blink LED 1 (invert LED state every 1s)
        if(myTimer1.delay(1000))
            LED1_state = !LED1_state;
    }
    else 
        // turn off LED 1
        LED1_state = false;

    digitalWrite(5, LED1_state);


    // -------------------------------------------------------------
    // Time-Limited Action : 
    // => triggered by Virtual Button on Digital Data 1
    //    (action is triggered when the Button is clicked)
    // => triggered by Rising Edge on Digital Data 2
    //    (action is triggered on a rising edge of the Digital Data boolean value)
    if(HC_digitalDataRead_click(1) || HC_digitalDataRead_risingEdge(2))
    {
        doPunctualAction = true;

        myTimer2.reset();
        myTimer3.reset();
    }

    if(doPunctualAction)
    {
        // blink LED 2 (invert LED state every 0.25s)
        if(myTimer2.delay(250))
            LED2_state = !LED2_state;

        // move servo to position 169.3°
        servo_position = 169300;

        // this action lasts 2s
        if(myTimer3.delay(2000))
            doPunctualAction = false;
    }
    else 
    {
        // turn off LED 2
        LED2_state = false;

        // move servo back to its initial position 12.8°
        servo_position = 12800;
    }
    digitalWrite(6, LED2_state);
    HC_servoWrite(8, servo_position);
}