Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Alex Glow
Published © CC BY

Mesh Your Brain

Build your own Internet of Brains with this wireless EEG hack!

Full instructions provided6,016
Mesh Your Brain

Story

Read more

Code

bootstrap.c

C/C++
bootstrap.c
// Eric's notes:
// You can get the signal strength, attention, and meditation values directly by 
// calling the scoutscript:  `print brain.signal`, `print brain.attention`, or 
// `print brain.meditation`.
// This was made by mashing up the Brain library (https://github.com/kitschpatrol/Brain)
// with the Pinoccio bootstrap (http://pinocc.io/solo).
// First, download and install the "brain" library. Then, paste this code into the Arduino IDE,
// save it as a sketch, and upload it to your Scout.

#include <SPI.h>
#include <Wire.h>
#include <Scout.h>
#include <GS.h>
#include <bitlash.h>
#include <lwm.h>
#include <js0n.h>
#include <Brain.h>
#include "version.h"

// hook up the Neurosky to Serial 1 (RX1/TX1)
Brain brain(Serial1);

void setup() {
  Scout.setup();

  // Add custom setup code here

  Serial1.begin(9600);
  addBitlashFunction("brain.signal", (bitlash_function)signal);
  addBitlashFunction("brain.attention", (bitlash_function)attention);
  addBitlashFunction("brain.meditation", (bitlash_function)meditation);
}

void loop() {
  Scout.loop();

  // Add custom loop code here

  char buf[32];

  // Expect packets about once per second.
   if (brain.update()) {
    Serial.println(brain.readErrors());
    Serial.println(brain.readCSV());

    // signal
    snprintf(buf, sizeof(buf), "on.brain.signal(%d)", brain.readSignalQuality());

    if (findscript(buf)) {
      doCommand(buf);
    }

    // attention
    snprintf(buf, sizeof(buf), "on.brain.attention(%d)", brain.readAttention());

    if (findscript(buf)) {
      doCommand(buf);
    }

    // meditation
    snprintf(buf, sizeof(buf), "on.brain.meditation(%d)", brain.readMeditation());

    if (findscript(buf)) {
      doCommand(buf);
    }
  }
}

numvar signal() {
  return brain.readSignalQuality();
}

numvar attention() {
  return brain.readAttention();
}

numvar meditation() {
  return brain.readMeditation();
}

Credits

Alex Glow
149 projects • 1594 followers
The Hackster team's resident Hardware Nerd. I love robots, music, EEG, wearables, and languages. FIRST Robotics kid.

Comments