Installing the Software for Arduino

Once you have completed the Arduino preamp circuit, download the Arduino and processing software appropriate for your laptop. Set them up and test them according to the tutorials for your model and platform. Then connect the Arduino using the USB cable, and using the Arduino software copy, paste, and upload this program:

// THE ARDUINO CODE FOR EEG

#define ANALOG_IN 0

void setup() {

Serial.begin(19200);

analogReference(INTERNAL);

}

void loop() {

int val = analogRead(ANALOG_IN);

Serial.print( 0xff, BYTE);

Serial.print( (val >> 8) & 0xff, BYTE);

Serial.print( val & 0xff, BYTE);

}

Then disconnect the Arduino and in processing-- not in the Arduino software-- copy and paste the program below. Note

that both these programs are adapted from one by Sofian Audry

http://accrochages.drone.ws/sites/accrochages.drone.ws/files/Oscilloscope.pde , and like it are therefore in the public domain, subject to GNU General Public License restrictions. Also note that this one expects the Arduino signal to be at port 0, where it seems to usually sit for Macs. For a PC, you will have to find the number of the correct COM port using println(Serial.list()); see http://itp.nyu.edu/physcomp/Labs/SerialOut .

// SET FOR 5 SECONDS EEG, 180 Hz. A LONGER DISPLAY MAY RUN SLOW,

// DEPENDING ON THE SPEED OF YOUR CPU.

import processing.serial.*;

Serial port; // Create object from Serial class

int val; // Data received from the serial port

int cnt;

int hht;

int wm1;

int[] values;

void setup()

{

size(900, 400); //currently set to 5 sec

// Open the port that the board is connected to and use the same speed (19200 bps)

port = new Serial(this, Serial.list()[0], 19200);

values = new int[width];

hht = 750; // Sets display DC offset; must adjust if gain is changed#

wm1= width-1;

cnt = 1;

frameRate(180); //read/draw 180 samples/sec

for (int s=0;s<width;s++) { //set initial values to midrange

values[s] = 550;

}

}

void draw()

{

background(0);

while (port.available() >= 3) { //read the latest value

if (port.read() == 0xff) {

val = (port.read() << 8) | (port.read());

}

}

values[cnt] = val; //put it in the array#

cnt++; //increment the count

stroke(60);

for (int d = 0; d < width-1; d = d + 180) { //**draw lines for seconds

line(d,0,d,400);

}

stroke(255,255,0);

line(cnt,100,cnt,300); //draw the leading edge line

stroke(255,0,0);

for (int x=2; x<wm1; x++) {

line (x-1, hht-values[x-1], x, hht-values[x]); //increment the data line

}

if (cnt > wm1) { //back to beginning

cnt = 1;

}

}

When all the software is ready, disconnect the Arduino, connect the EEG leads as described in "Recording the EEG", reconnect the Arduino, and run the Processing program. If the signal noise/amplitude is poor, or you have a slow CPU, the display may run slow, because processing is not designed to collect and display samples at precisely timed intervals. If everything is working, you should see activity like that illustrated on the accompanying pages.