CPR Trainer

By: Joe & Dan

    January 6th 2010
     
  We had decided to come up with a CPR training dummy that would show the user if they are doing the chest compressions the right way.  This could be done by using the Nunchuck from  a Wii gaming system and an arduino board.  The nunchuck is placed on the inside of the dummy and connected to the arduino through analog pins 5,4,3, and 2 as Inputs via an adapter found Here

The Library was found on the same website

The code that we are currently using is:

#include <Wire.h>
#include "nunchuck_funcs.h"

int an[] = {11,12,13,11,12,13,10,13,10,12,10,11,10,9,9,11,12,9,8,11,8,10,8,9,8,7,9,7,10,7,7,11,12,7,13,7};
int ca[] = {12,11,11,13,13,12,13,10,12,10,11,10,9,10,11,9,9,12,11,8,10,8,9,8,7,8,7,9,7,10,11,7,7,12,7,13};
int loop_cnt=0;
int t = 2500;

byte accx,accy,zbut,cbut;
int ledPin = 13;
int x=0;

void setup()
{
  for (int pin =7; pin<=13; pin++)
{
  pinMode(pin,INPUT); // Set as input
}
  
    Serial.begin(19200);
    nunchuck_setpowerpins();
    nunchuck_init(); // send the initilization handshake
   
    Serial.print("WiiChuckDemo ready\n");
}

void loop()
{
    if( loop_cnt > 100 ) { // every 100 msecs get new data
        loop_cnt = 0;

        nunchuck_get_data();

        accx  = nunchuck_accelx(); // ranges from approx 70 - 182
        accy  = nunchuck_accely(); // ranges from approx 65 - 173
        zbut = nunchuck_zbutton(); // show data everytime the Z button is pressed
        cbut = nunchuck_cbutton(); // show data everytime the C button is pressed
        x = nunchuck_accelx();        // sets variable x = nunchuck_accelx
        x= map(x,0,255,0,35);         // sets variable x = map(x,0,255,0,35)
       delayMicroseconds(t);          // sets delay to variable (t)
        pinMode (an[x], OUTPUT); // declares an[x] as an OUTPUT
        pinMode (ca[x], OUTPUT); // declares ca[x] as an OUTPUT
        digitalWrite(an[x], HIGH);    // set an[x] to HIGH
        digitalWrite(ca[x], LOW);     // set ca[x] to LOW
        delayMicroseconds(t);        // sets delay to variable (t)
        digitalWrite(an[x], LOW);    // sets an[x] to LOW
        digitalWrite(ca[x], LOW);    // sets an[x] to LOW
        delayMicroseconds(t);       // shows variable (t) for delay
        pinMode (an[x], INPUT);   // sets an[x] as an INPUT
        pinMode (ca[x], INPUT);   // sets ca[x] as an INPUT
        Serial.print("accx: "); Serial.print((byte)accx,DEC);
        Serial.print("\taccy: "); Serial.print((byte)accy,DEC);
        Serial.print("\tzbut: "); Serial.print((byte)zbut,DEC);
        Serial.print("\tcbut: "); Serial.println((byte)cbut,DEC);
    }
    loop_cnt++;
    delay(1);
}

Conversions for the serial monitor:
  +1g = 180
   -1g = 72
    0g = 128
    -2g = 0
    +2g = 255
This is a calculation of the amount of G's that are being experienced.
So when it's not moving, the normal force = the force of gravity which is 0g (not moving).
    y = 63.75x + 128


  

January 14, 2010

posted Jan 14, 2010, 9:49 AM by Unknown user   [ updated Jan 14, 2010, 8:51 AM ]

    The last day!  After changing two LEDs so it lights up in sequence from red, yellow, to green we need to calibrate the timing so it's right on queue with each compression.

January 13, 2010

posted Jan 13, 2010, 9:08 AM by Unknown user   [ updated Jan 13, 2010, 8:22 AM ]

 We modified our program so the serial monitor only registers when there is important data given so it isn't constantly displaying insignificant data.  Now it will only show when the nunchuck is being put to use.  Today we will modify the code to work better with our setup. 

The serial monitor will only show numbers above 190.

Here is the code we are currently using:

#include <Wire.h>
#include "nunchuck_funcs.h"

int an[] = {11,12,13,11,12,13,10,13,10,12,10,11,10,9,9,11,12,9,8,11,8,10,8,9,8,7,9,7,10,7,7,11,12,7,13,7};
int ca[] = {12,11,11,13,13,12,13,10,12,10,11,10,9,10,11,9,9,12,11,8,10,8,9,8,7,8,7,9,7,10,11,7,7,12,7,13};
int loop_cnt=0;
int t = 2500;

byte accx,accy,zbut,cbut;
int ledPin = 13;
int x=0;
int y = 0;
void setup()
{
  for (int pin =7; pin<=13; pin++)
{
  pinMode(pin,INPUT);
}
  
    Serial.begin(19200);
    nunchuck_setpowerpins();
    nunchuck_init(); // send the initilization handshake
   
    Serial.print("WiiChuckDemo ready\n");
}

void loop()
{
    if( loop_cnt > 100 ) { // every 100 msecs get new data
        loop_cnt = 0;

        nunchuck_get_data();

        accx  = nunchuck_accelx(); // ranges from approx 70 - 182
        accy  = nunchuck_accely(); // ranges from approx 65 - 173
        zbut = nunchuck_zbutton();
        cbut = nunchuck_cbutton();
        x = nunchuck_accelx();
        x= map(x,0,255,0,35);
       delayMicroseconds(t);
        pinMode (an[x], OUTPUT);
        pinMode (ca[x], OUTPUT);
        digitalWrite(an[x], HIGH);
        digitalWrite(ca[x], LOW);
        delayMicroseconds(t);
        digitalWrite(an[x], LOW);
        digitalWrite(ca[x], LOW);
        delayMicroseconds(t);
        pinMode (an[x], INPUT);
        pinMode (ca[x], INPUT);
        if (accx > 190)
        {   
        Serial.print("accx: "); Serial.print((byte)accx,DEC);
        Serial.print("time: "); Serial.println((long)millis(), DEC);
        }
    }
    loop_cnt++;
    delay(1);
}

January 7th 2010

posted Jan 7, 2010, 9:24 AM by Unknown user   [ updated Jan 8, 2010, 8:03 AM ]

    Today we need to do compressions to see how precise our data is with each compression.
This is important because for the meter that will be connected to work right when used properly so you can be as accurate as you are precise.

At first the serial monitor was showing the force of around 80 which converted to G's is around -1g, after turning the nunchuck right side up the serial monitor was able to show 180 which is the equivalent of about +1g.  This data shows that the direction which it is facing does matter and is significant. 

1-3 of 3