Editing Pulse Necklace 15Nov2009

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 13: Line 13:
To look at the output signal from AD 620, we resorted to a virtual oscilloscope - link and code are in the next section. Unfortunately, we saw only noise from the oscilloscope. We tried switching the gain-control resistor from 98 ohms (two 47 ohm resistors) to 1 kohm. That only lowered the amplitude. We were using red dot electrodes, so the ECG signal was entering the chip reliably. More work to be done on this front.
To look at the output signal from AD 620, we resorted to a virtual oscilloscope - link and code are in the next section. Unfortunately, we saw only noise from the oscilloscope. We tried switching the gain-control resistor from 98 ohms (two 47 ohm resistors) to 1 kohm. That only lowered the amplitude. We were using red dot electrodes, so the ECG signal was entering the chip reliably. More work to be done on this front.


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


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:  
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:  


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


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


#define ANALOG_IN 2
int OuterTwosLeft = 13; // Left, right w/r/t to viewer, not wearer
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() {
   Serial.begin(9600);  
  pinMode(OuterTwosLeft, OUTPUT); 
  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() {
void loop() {
   int val = analogRead(ANALOG_IN);
/*   digitalWrite(OuterTwosLeft, 1);
  Serial.print( 0xff, BYTE);
  delay(500);
  Serial.print( (val >> 8) & 0xff, BYTE);
  digitalWrite(OuterTwosRight, 1);
  Serial.print( val & 0xff, BYTE);
  delay(500);
}
  digitalWrite(MiddleLeft, 1);
  delay(500); 
  digitalWrite(MiddleRight, 1); 
  delay(500);
  digitalWrite(CenterGrd, 1);
  delay(500);
 
  digitalWrite(OuterTwosLeft, 0);
  delay(500);
  digitalWrite(OuterTwosRight, 0);
  delay(500);
  digitalWrite(MiddleLeft, 0);
  delay(500)
  digitalWrite(MiddleRight, 0);
  delay(500);
  digitalWrite(CenterGrd, 0);
  delay(500);
*/


</pre>
  val = 0;
 
  for (i=0; i < 8; i++)
And here is the Processing code doing all the computation:
  {
 
    val += analogRead(2);    // read the input pin
<pre>
  }
/*
  val = val/8;
* Oscilloscope
  if (val > maxval)
* Gives a visual rendering of analog pin 0 in realtime.
    maxval = val;
*
  if (val < minval)
* This project is part of Accrochages
    minval = val;
* See http://accrochages.drone.ws
  avg = avg*99.0/100.0 + (float)val/100.0;
*
  stdev = sqrt ((stdev*99.0/100.0)*(stdev*99.0/100.0) + ((float)val-avg)*((float)val-avg)/100);
* (c) 2008 Sofian Audry (info@sofianaudry.com)
  Serial.print(val);
*
  Serial.print(" ");
* This program is free software: you can redistribute it and/or modify
  Serial.print(minval);
* it under the terms of the GNU General Public License as published by
  Serial.print("  ");
* the Free Software Foundation, either version 3 of the License, or
   Serial.print(maxval);             // debug value
* (at your option) any later version.
   Serial.print("    ");
*
   Serial.print(avg);
* This program is distributed in the hope that it will be useful,
   Serial.print("  ");
* but WITHOUT ANY WARRANTY; without even the implied warranty of
   Serial.println(stdev);
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
* GNU General Public License for more details.
  if (val < (avg-stdev))
*  
  {
* You should have received a copy of the GNU General Public License
  // Serial.println(val);             // debug value
* along with this program. If not, see <http://www.gnu.org/licenses/>.
    digitalWrite(OuterTwosLeft, 0);   // 0 = lit  // this LED not working, unless you push down at wire connection area
*/  
     digitalWrite(OuterTwosRight, 0);
import processing.serial.*;
    digitalWrite(CenterGrd, 0);  // this LED not working
 
    digitalWrite(MiddleLeft, 0);
Serial port;  // Create object from Serial class
     digitalWrite(MiddleRight, 0);  // this LED not working 
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++)
   else
    values[i] = values[i+1];
  {
  values[width-1] = val;
    digitalWrite(OuterTwosLeft, 1); // 1 = off
  background(0);
    digitalWrite(OuterTwosRight, 1);
  stroke(255);
    digitalWrite(CenterGrd, 1);
  for (int x=1; x<width; x++) {
    digitalWrite(MiddleLeft, 1);
     line(width-x,   height-1-getY(values[x-1]),
     digitalWrite(MiddleRight, 1);  
        width-1-x, height-1-getY(values[x]));
   }
   }
  //Serial.println("test");
}
}


</pre>
</pre>


[[Category:Sensebridge]]
[[Category:Sensebridge]]
Please note that all contributions to Noisebridge are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Noisebridge:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel Editing help (opens in new window)