Pulse Necklace 15Nov2009: Difference between revisions

From Noisebridge
Jump to navigation Jump to search
(New page: =Hack Notes, pulse choker, Nov 15th, 2009= ==TENS Pad Electrodes== ==Op-Amp Experiment== ==Oscillascope Code== We got amazing code for a virtual Arduino oscilloscope from [http:/...)
 
No edit summary
Line 11: Line 11:




==Oscillascope Code==
==Oscilloscope Code==


We got amazing code for a virtual Arduino oscilloscope from [http://accrochages.drone.ws/en/node/90 Poorman's oscilloscope] and juse changed the serial port name to correspond to either Eric's or mine cable:  
We got great code for a virtual Arduino oscilloscope from [http://accrochages.drone.ws/en/node/90 Poorman's oscilloscope] and just changed the serial port name to correspond to either Eric's or mine cable. Below is the Arduino code:  


<pre>
<pre>
// Pulse Choker
// Chung-Hay and Eric
// Oct 1st, 2009


// Control 5 different lines of LEDs based on EKG
// The Arduino code.
// Center top line is 5V shared across all LEDs
// EKG input pin = pin 2


int OuterTwosLeft = 13; // Left, right w/r/t to viewer, not wearer
#define ANALOG_IN 2
int MiddleLeft = 12;
int CenterGrd = 11;
int MiddleRight = 10;
int OuterTwosRight = 9;
int val = 0;
int minval = 10000;
int maxval = 0;
float avg = 160;  // common value, better than initing to zero
float stdev = 40;
int i;


void setup() {
void setup() {
  pinMode(OuterTwosLeft, OUTPUT); 
   Serial.begin(9600);  
  pinMode(OuterTwosRight, OUTPUT);
  pinMode(MiddleLeft, OUTPUT);
  pinMode(MiddleRight, OUTPUT);
  pinMode(CenterGrd, OUTPUT);
  digitalWrite(OuterTwosLeft, 1);
  digitalWrite(OuterTwosRight, 1);
  digitalWrite(MiddleLeft, 1);
  digitalWrite(MiddleRight, 1);
  digitalWrite(CenterGrd, 1); 
 
   Serial.begin(57600);         //  setup serial
}
}


void loop() {
  int val = analogRead(ANALOG_IN);
  Serial.print( 0xff, BYTE);
  Serial.print( (val >> 8) & 0xff, BYTE);
  Serial.print( val & 0xff, BYTE);
}
</pre>


void loop() {
And here is the Processing code doing all the computation:
/*   digitalWrite(OuterTwosLeft, 1);
 
  delay(500);
<pre>
  digitalWrite(OuterTwosRight, 1);
/*
  delay(500);
* Oscilloscope
  digitalWrite(MiddleLeft, 1);  
* Gives a visual rendering of analog pin 0 in realtime.
  delay(500);   
*
  digitalWrite(MiddleRight, 1);
* This project is part of Accrochages
  delay(500);
* See http://accrochages.drone.ws
  digitalWrite(CenterGrd, 1);
*
  delay(500);
* (c) 2008 Sofian Audry (info@sofianaudry.com)
 
*
  digitalWrite(OuterTwosLeft, 0);
* This program is free software: you can redistribute it and/or modify
  delay(500);
* it under the terms of the GNU General Public License as published by
  digitalWrite(OuterTwosRight, 0);
* the Free Software Foundation, either version 3 of the License, or
  delay(500);
* (at your option) any later version.
  digitalWrite(MiddleLeft, 0);  
*
  delay(500);
* This program is distributed in the hope that it will be useful,
  digitalWrite(MiddleRight, 0); 
* but WITHOUT ANY WARRANTY; without even the implied warranty of
  delay(500);
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  digitalWrite(CenterGrd, 0);
* GNU General Public License for more details.
  delay(500);
*
*/
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
import processing.serial.*;
 
Serial port// Create object from Serial class
int val;      // Data received from the serial port
int[] values;
// Change this to the portname your Arduino board:
// Have USB cable connected. Open Arduino app.
// Go to tools -> Serial Port -> Find /dev/tty.usbserial-<blah> option
//String portname = "/dev/tty.usbserial-A9007Llr"; // Chung-Hay's
String portname = "/dev/cu.usbserial-A8007U5u"; //Eric's
 
void setup()  
{
  size(640, 480);
  // Open the port that the board is connected to and use the same speed (9600 bps)
  //port = new Serial(this, Serial.list()[0], 9600);
  port = new Serial(this, portname, 9600);
  values = new int[width];
  smooth();
}
 
int getY(int val) {
  return (int)(val / 1023.0f * height) - 1;
}


   val = 0;
void draw()
  for (i=0; i < 8; i++)
{
  {
   while (port.available() >= 3) {
    val += analogRead(2);   // read the input pin
    if (port.read() == 0xff) {
      val = (port.read() << 8) | (port.read());
    }
   }
   }
   val = val/8;
   for (int i=0; i<width-1; i++)
  if (val > maxval)
     values[i] = values[i+1];
    maxval = val;
   values[width-1] = val;
  if (val < minval)
   background(0);
     minval = val;
   stroke(255);
   avg = avg*99.0/100.0 + (float)val/100.0;
   for (int x=1; x<width; x++) {
   stdev = sqrt ((stdev*99.0/100.0)*(stdev*99.0/100.0) + ((float)val-avg)*((float)val-avg)/100);
     line(width-x,   height-1-getY(values[x-1]),  
   Serial.print(val);
        width-1-x, height-1-getY(values[x]));
   Serial.print("  ");
  Serial.print(minval);
  Serial.print("  ");
  Serial.print(maxval);            // debug value
  Serial.print("     ");
  Serial.print(avg);
   Serial.print("  ");
  Serial.println(stdev);
 
  if (val < (avg-stdev))
  {
  // Serial.println(val);            // debug value
    digitalWrite(OuterTwosLeft, 0);  // 0 = lit  // this LED not working, unless you push down at wire connection area
    digitalWrite(OuterTwosRight, 0);
    digitalWrite(CenterGrd, 0);  // this LED not working
    digitalWrite(MiddleLeft, 0);
    digitalWrite(MiddleRight, 0); // this LED not working 
   }
   }
  else
  {
    digitalWrite(OuterTwosLeft, 1);  // 1 = off
    digitalWrite(OuterTwosRight, 1);
    digitalWrite(CenterGrd, 1);
    digitalWrite(MiddleLeft, 1);
    digitalWrite(MiddleRight, 1);
  }
  //Serial.println("test");
}
}


</pre>
</pre>

Revision as of 16:44, 15 November 2009

Hack Notes, pulse choker, Nov 15th, 2009

TENS Pad Electrodes

Op-Amp Experiment

Oscilloscope Code

We got great code for a virtual Arduino oscilloscope from Poorman's oscilloscope and just changed the serial port name to correspond to either Eric's or mine cable. Below is the Arduino code:


// The Arduino code.

#define ANALOG_IN 2

void setup() {
  Serial.begin(9600); 
}

void loop() {
  int val = analogRead(ANALOG_IN);
  Serial.print( 0xff, BYTE);
  Serial.print( (val >> 8) & 0xff, BYTE);
  Serial.print( val & 0xff, BYTE);
}

And here is the Processing code doing all the computation:

/*
 * Oscilloscope
 * Gives a visual rendering of analog pin 0 in realtime.
 * 
 * This project is part of Accrochages
 * See http://accrochages.drone.ws
 * 
 * (c) 2008 Sofian Audry (info@sofianaudry.com)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */ 
import processing.serial.*;

Serial port;  // Create object from Serial class
int val;      // Data received from the serial port
int[] values;
// Change this to the portname your Arduino board: 
// Have USB cable connected. Open Arduino app. 
// Go to tools -> Serial Port -> Find /dev/tty.usbserial-<blah> option
//String portname = "/dev/tty.usbserial-A9007Llr"; // Chung-Hay's
String portname = "/dev/cu.usbserial-A8007U5u"; //Eric's

void setup() 
{
  size(640, 480);
  // Open the port that the board is connected to and use the same speed (9600 bps)
  //port = new Serial(this, Serial.list()[0], 9600);
  port = new Serial(this, portname, 9600);
  values = new int[width];
  smooth();
}

int getY(int val) {
  return (int)(val / 1023.0f * height) - 1;
}

void draw()
{
  while (port.available() >= 3) {
    if (port.read() == 0xff) {
      val = (port.read() << 8) | (port.read());
    }
  }
  for (int i=0; i<width-1; i++)
    values[i] = values[i+1];
  values[width-1] = val;
  background(0);
  stroke(255);
  for (int x=1; x<width; x++) {
    line(width-x,   height-1-getY(values[x-1]), 
         width-1-x, height-1-getY(values[x]));
  }
}