EPOC-to-Arduino “Goodbye, World”

Related articles: FBLR Mind-Controlled Robot | Processing + EPOC via OSC

This Processing sketch demonstrates a simple interface between the Emotiv EPOC and Arduino via Processing and OSC. When the operator wearing the EPOC thinks “disappear,” the LED connected to the Arduino turns off; when the operator ceases thinking “disappear,” the LED turns back on. The sketch requires the arduino and oscP5 libraries for Processing, and the Mind Your OSCs application for EPOC.

(There exists one OSC library for Arduino, that I know of, that has been reportedly updated for build 0021, but I have not used it. I typically use Processing in conjunction with Arduino, for developing graphical interfaces such as the one shown here.)

Here is the Processing code:

/**
 * EPOC-to-Arduino "Goodbye, World"
 * by Joshua Madara, hyperRitual.com
 * 
 * This sketch demonstrates a simple interface between
 * Emotiv EPOC and Arduino via Processing and OSC. When the
 * operator wearing the EPOC thinks "disappear," 
 * the LED connected to the Arduino turns off;
 * when the operator ceases thinking "disappear,"
 * the LED turns back on.
 * 
 * The sketch requires the arduino and oscP5 libraries
 * for Processing, and the Mind Your OSCs application for EPOC.
 */

// import libraries needed for Arduino and OSC
import processing.serial.*;
import cc.arduino.*;
import oscP5.*;

Arduino arduino; // declare object
OscP5 oscP5; // declare object

float disappear = 0; // holds the value incoming from EPOC
int LED = 13; // LED connected to Arduino pin 13

void setup() {
  println(Arduino.list()); // look for available Arduino boards
  // start Arduino communication at 57,600 baud
  arduino = new Arduino(this, Arduino.list()[1], 57600);
  
  // set LED as output pin
  arduino.pinMode(LED, arduino.OUTPUT);
  
  // start oscP5, listening for incoming messages on port 7400
  // make sure this matches the port in Mind Your OSCs
  oscP5 = new OscP5(this, 7400);
  
  /* plug automatically forwards OSC messages having
  address pattern /COG/DISAPPEAR to getDisappear()
  which updates the disappear variable with the value
  of the OSC message */
  oscP5.plug(this,"getDisappear","/COG/DISAPPEAR");
}

void draw() {
  /* the following block evaluates disappear and if it is 
  greater than or equal to .5, turns LED off, otherwise it 
  turns/keeps LED on */
  if(disappear >= 0.5) {
    arduino.digitalWrite(LED, arduino.LOW);
  } else {
    arduino.digitalWrite(LED, arduino.HIGH);
  }
}

/* the following function updates disappear with the value
of any incoming OSC messages for /COG/DISAPPEAR/, plugged
in setup() */
void getDisappear (float theValue) {
  disappear = theValue;
  println("OSC message received; new disappear value: "+disappear);
}

Arduino LED setup

FBLR Mind-Controlled Robot

Related articles: Processing + EPOC via OSC | EPOC-to-Arduino “Goodbye, World” | Arduino + fischertechnik | BYTR Virtual Servitor

FBLR (“Fibbler”) is a robot that moves forward and backward, and turns left and right, in response to its operator’s thoughts. The signal flow is brain → Emotiv EPOCMind Your OSCsProcessingArduinofischertechnik robot. I wrote a Processing sketch (zipped with data files) that converts the EPOC signals via OSC messages, to Arduino signals that move the robot. The sketch uses the arduino, controlP5, and oscP5 libraries. The Arduino uses Firmata (standard with the Arduino software) and a motor shield from Rugged Circuits (see this article for more info).

FBLR Processing Interface

There are four knobs for adjusting the actuator thresholds. The EPOC’s Cognitiv values are compared to said thresholds to determine whether to enable the robot’s motors and which directions to turn them in:

Cognitiv Action Motor 1 Direction Motor 2 Direction
PUSH 0 0
PULL 1 1
LEFT 1 0
RIGHT 0 1

Setting a knob to 0 (all the way to the left) will enable its associated motors regardless of the Cognitiv value. Four bars display the levels of the incoming Cognitiv values; if a value is greater than or equal to its threshold, the bar displays green, otherwise it displays red.

The slider can be used to change the delay from 0 to 200 milliseconds. The shorter the delay, the more frequently OSC messages are evaluated, but the robot may also “stutter” for trying to retrieve messages faster than they are delivered. There are a variety of ways to handle this; I chose one that was simple and effective but not the most elegant. I found that 100ms makes for smooth operation most of the time. Note also that push, pull, left, and right are evaluated in that order by the draw() loop, so if, e.g., push and left both exceed their threshold values, only moveForward() will fire.

Here is an EmoScript for EmoComposer, to test the interaction without needing the headset. See the Emotiv EPOC SDK guide for more about that.

Occult Applications

Mankind’s oldest fantasy is to move something with the power of thought. // Tan Le, co-founder of Emotiv

Any use of the EPOC seems to be magical in a folk sense, but I am interested in new-media interactions that respond to explicitly magical intentions or commands (e.g. sigil concentration), ecstatic or gnostic states of consciousness, state entity projections, etc. I expect the EPOC to feature in some of the robomancy projects I will be developing in the near future.

FBLR mind-Controlled Robot

Arduino + fischertechnik

Related articles: Portable Arduino Lab | FBLR Mind-Controlled Robot

Arduino + fischertechnik 1

This week I blew the dust off my old fischertechnik Experimenta Computing kit to see about controlling it with Arduino. If I can control the kit with Arduino, I can get it to respond to the EPOC via OSC with Processing. More about that later.

The kit was made to interface with a PC via parallel port. It includes I/O for four motors/lamps/etc. (M1 – M4), eight binary switches (E1 – E8), and two analog inputs for pots, photo-resistors, etc. (EX, EY). The models on the base plate are powered through a distributing box that connects to the interface via a 20-pin IDC ribbon cable. Here is a pinout that I sorted out with a multimeter:
fischertechnik IDC Pinout

Obviously, Arduino has enough I/O to handle the kit’s variety — almost. The kit’s motors are powered by 6–9vdc, so I am using a Rugged Circuits motor driver shield and 9v battery to power two of them. The shield will not power four motors, but M3 and M4 can be connected to two of Arduino’s other PWM pins in order to power other components. Here is a sketch for a switch to turn the motor on when pressed:

#define M1 3 // motor output
#define M1_DIR 12 // direction output, not used in loop
#define E1 5 // binary input (push switch)

int toggle = 0;

void setup() {
  // configure all outputs off for now
  pinMode(M1, OUTPUT); digitalWrite(M1, LOW);
  pinMode(M1_DIR, OUTPUT); digitalWrite(M1_DIR, LOW);
  // configure input
  pinMode(E1, INPUT);
  
  analogWrite(M1, 0); // motor off for now
}

void loop() {
  if(digitalRead(E1) == HIGH) {
    toggle = 1;
  }
  while(toggle == 1) {
    analogWrite(M1, 255);
    if(digitalRead(E1) == LOW) {
    toggle = 0;
    }
  }
  analogWrite(M1, 0);
}

Since the motor shield has stackable headers, I am thinking about creating a shield for the remaining I/O, using a Technological Arts IDC ribbon cable to breadboard adapter and an Adafruit proto shield kit.

Cf. scratchfisch.org, a Scratch driver for fischertechnik kits.

Portable Arduino Lab

I have hot-glued my Arduino Duemilanove to the battery compartment lid of my Maxitronix 500-in-One electronics lab, making for a portable Arduino lab that includes:

  • 8 LEDs
  • Photo-transistor
  • CdS cell
  • Antenna coil
  • Tuning capacitor
  • DPDT swtich
  • 665-hole breadboard
  • 8 SPST switches
  • 8-digit LCD display
  • 7-segment LED display
  • 4-bit embedded microcomputer w/ keyboard
  • Speaker
  • Transformer
  • 50kΩ and 100kΩ potentiometers
  • Compartments and trays for loose components

The Arduino aligns with the spring terminals of the 7-segment display, such that the case closes perfectly.

Arduino Lab 1

Arduino Lab 2

Conductive Sigils

The next method for impregnation is the so-called charge with magic volts, using, for this purpose, the electromagnetic fluid. The volt is charged, after its creation, with an electromagnetic fluid. The qualities of the intelligence in question are concentrated into the centre of the volt by help of imagination, imperturbable confidence and sure power, and are so condensed by repeated action that the metal of the talisman absorbs the volt. When the process of charging by volts is repeated, the magician has to concentrate on the wish that the intelligence in question is connected to that particular volt and that it will bring about by it the desired causes in the Akasha-world, and with them the desired effects. // Franz Bardon, The Practice of Magical Evocation

Conductive sigils — i.e. sigils that pass an electric current — offer many possible uses in multimedia rituals, both mechanically as switches etc., and sympathetically to add or combine some magical quality to/with an electrical action. E.g., we could use a conductive rune as a switch to turn on an engine (like the Rune Priests of the Adeptus Mechanicus). Sigils can be drawn with conductive inks on just about any surface including skin. 3D sigils may be sculpted from wire or other conductive materials. Sigils of varying resistances could initiate various actions depending on which sigil is selected.

Here is an example of a conductive sigil, which I made using the same tech for making printed circuit boards:

Conductive Sigil

Conductive Sigil 2  Conductive Sigil 3  Conductive Sigil Wired

I first drew the sigil using Inkscape and GIMP, then laser-printed it (600dpi) to a transparency that I used to transfer the image to a photosensitive circuit board, which I then developed and etched (the circuit board, developer, and etch solution are available as a kit from Jameco). You can also just draw a sigil on a blank board, using a black Sharpie, and then etch that. The process may be as elaborate (consecrate the materials, employ them during appropriate hours, chant while etching, etc.) or simple as you care for.

Conductive Sigil Design

To “charge” the sigil (no pun intended), I used Processing to play an appropriate song, and Arduino to send a voltage through the sigil, proportional to the varying amplitude of the song. Here are code examples for each application:

/**
 * Charge Sigil (Processing)
 * Joshua Madara
 * oneirodynesystems.com
 * 
 * Parts of this code were taken from
 * Joshua Noble, _Programming Interactivity_, p.203
*/

import ddf.minim.*;
import processing.serial.*;

AudioPlayer mySong;
Minim minim;
Serial myPort;
int message = 0; // Holds the voltage value we'll send to Arduino

void setup(){
  size(600, 400);
  minim = new Minim(this);
  myPort = new Serial(this, Serial.list()[0], 9600);
  mySong = minim.loadFile("song_title.mp3");
}

void draw() {
  fill(0x000000, 30);
  rect(0, 0, width, height);
  stroke(255);
  noFill();
  // Load buffer for mySong into array mix
  float[] mix = mySong.mix.toArray();
  // Draw waveform across screen
  for(int i = 0; i < mySong.bufferSize() - 1; i++) {
    ellipse(i * 4, 200 + mix[i]*100, 5, 5);
  }
  // Play mySong
  mySong.play();
  // Map first value of array mix to
  // (rounded, integer) value between 0 and 255
  // that corresponds to 0 to 5 volts in Arduino
  // and set message to it
  message = int(round(map(mix[1], -1, 1, 0, 255)));
  // Send message to Arduino
  myPort.write(message);
  // println(message); // Uncomment to monitor message in Processing
}

// Stop and close minim
void stop() {
  mySong.close();
  minim.stop();
  super.stop();
}

/**
 * Charge Sigil (Arduino)
 * Joshua Madara
 * oneirodynesystems.com
*/

// Define variables for incoming message and output pin
int message = 0;
int outPin = 10;

void setup() {
  // Initiate serial connection
  Serial.begin(9600);
}

void loop() {
  if(Serial.available() > 0) {
    // Read message (0 to 255) from Processing, then...
    message = Serial.read();
    // ...set pin 10 to corresponding voltage (0 to 5 volts)
    analogWrite(outPin, message);
  }
}

To “evoke the spirit” of the sigil, I connect it in series with whatever ritual artifact(s) I am working with. E.g., a Scratch project might include the following script (assuming that the appropriate two wire pads on the sigil are connected to the Resistance-A input of the PicoBoard):

PCB Sigil Scratch Script

The “conditional stuff” could be any number of program blocks that manipulate graphics, play sounds, message other sprites to act, etc.

Here is a great video showing you how to etch using the same products as I did: