Olimex Support Forum

DUINO => SHIELDS => Topic started by: svan on November 14, 2013, 03:11:14 AM

Title: MEGA-ADK_SHIELD-EKG_Nexus4
Post by: svan on November 14, 2013, 03:11:14 AM
The following video demonstrates using an Arduino MEGA-ADK (for Android) with an Olimex SHIELD-EKG to display an electrocardiogram on a Nexus 4 cellphone (Google/LG):

http://youtu.be/h7nysCmyWiU (http://youtu.be/h7nysCmyWiU)
Title: Re: MEGA-ADK_SHIELD-EKG_Nexus4
Post by: LubOlimex on November 14, 2013, 02:53:43 PM
Nice svan,

I have the same phone. However, why are you showing only a demo signal, not an actual reading? I'm also curious where have you connected the micro USB? Can't clearly see an output port on the MEGA-ADK.

Thanks for sharing your project.

Best regards,
Lub/OLIMEX
Title: Re: MEGA-ADK_SHIELD-EKG_Nexus4
Post by: svan on November 14, 2013, 04:37:38 PM
> why are you showing only a demo signal, not an actual reading

That's not a demo signal.  It is my own electrocardiogram in real-time.

> where have you connected the micro USB

The micro USB to the Nexus 4 phone plugs into the center port of the the MEGA-ADK; it looks like a regular USB port.  The MEGA-ADK has three ports.  One USB goes to the computer (I used a Mac) for uploading Arduino code and power, one USB goes to the cellphone, and the third is for a 9V battery.

[img]MEGA-ADK/img]
Title: Re: MEGA-ADK_SHIELD-EKG_Nexus4
Post by: metin on April 30, 2015, 03:18:54 PM
Hello swan.. When I received my sample project your project.
I am sending the signals bluetooth.But
I can not edit a kind of signals.My final project.
Can you share the Arduino code.Thanks..
Title: Re: MEGA-ADK_SHIELD-EKG_Nexus4
Post by: svan on April 30, 2015, 06:55:04 PM
The Arduino code for this project was taken from "Beginning Android ADK with Arduino" by Mario Bohmer, page 119.  I modified it slightly:

#include <Max3421e.h>
#include <Usb.h>
#include <AndroidAccessory.h>

#define COMMAND_ANALOG 0x3
#define TARGET_PIN 0x0
#define INPUT_PIN A5

AndroidAccessory acc("Manufacturer",
           "ECG_Android",
           "Description",
           "Version",
           "URI",
           "Serial");

byte sntmsg[6];
int analogPinReading;

void setup() {
  Serial.begin(19200);
  acc.powerOn();
  sntmsg[0] = COMMAND_ANALOG;
  sntmsg[1] = TARGET_PIN;
}

void loop() {
  if (acc.isConnected()) { 
  //  analogPinReading = analogRead(INPUT_PIN) >> 2 ;
    analogPinReading = analogRead(INPUT_PIN) >> 1 ;
    sntmsg[2] = (byte) (analogPinReading >> 24);
    sntmsg[3] = (byte) (analogPinReading >> 16);
    sntmsg[4] = (byte) (analogPinReading >> 8);
    sntmsg[5] = (byte) analogPinReading;
    acc.write(sntmsg, 6);
   // delay(100);
  }
}

If you are interested in bluetooth, I have another project on You-Tube entitled "ECG_Bluetooth" which demonstrates this: youtu.be/Exx215-yEFs (http://youtu.be/Exx215-yEFs).  The source code for that project is at github.com/vsquared/ecg (http://github.com/vsquared/ecg); the Arduino sketch is in a file called "ECG_BlueSerial.txt".

P.S. If you see an emoji with sunglasses in the code, the missing text is 'eight)'.
Title: Re: MEGA-ADK_SHIELD-EKG_Nexus4
Post by: metin on May 01, 2015, 03:52:59 PM
but I used Hc06 Bluetooth Module and passive electrodes.
How do I adapt the passive electrodes in Arduino??
Because graphics so irregular and bad.And txtrecive Value on Android came out on top 80.
my Arduino Code;your project code your ECG_BlueSerial.txt.
And Can I show your name as a reference in the report.
Thanks...
Title: Re: MEGA-ADK_SHIELD-EKG_Nexus4
Post by: svan on May 01, 2015, 05:47:51 PM
> How do I adapt the passive electrodes in Arduino??

As far as I know, there is nothing that you can do with the Arduino code to reduce the noise.  The Olimex shield is inherently noisy.  In my experience, the noise was reduced by using Bluetooth.  Using an ecg cable with adhesive snap-on electrodes also helps somewhat.

> Can I show your name as a reference in the report

This is an open-source project, so you are free to use it and use me as a reference.  Thank you for your interest in the project.
Title: Re: MEGA-ADK_SHIELD-EKG_Nexus4
Post by: metin on May 03, 2015, 02:08:40 PM
Arduino sketch is in a file called "ECG_BlueSerial.txt" at  at github.com/vsquared/ecg;
I used ecg cable with adhesive snap-on electrodes and later passive electrodes.
But In both signals ireegular and values very slow
I would be very happy if you help me.Thanks very much
Title: Re: MEGA-ADK_SHIELD-EKG_Nexus4
Post by: svan on May 03, 2015, 06:03:05 PM
1) Is your ecg trace slower than what is seen in the video "ECG_Bluetooth"?
2) Your project uses a different bluetooth module than the one that I used;  that may or may not be important.  I used an Adafruit E-Z Link, while you used HC06.
3) Are you using the same baud rate for both the HC06 and the Arduino?  The video used 9600 for both.
4) If the data is coming in slowly, you could try increasing the baud rate to 19200 or higher for both.  I have not tried this, so I don't know if it will help or not.
5) I don't understand "values very slow".  Does that mean that the signal amplitude is a short spike?  If so, you could try turning up the gain on the Olimex shield.  In the Arduino code, shifting the sensor value >> 1 instead of 2 should also change the signal height.
6) If it's possible, posting an image of the smartphone output would be helpful.
7) This discussion should probably be moved to a new thread since it does not pertain to the MEGA-ADK project.
Title: Re: MEGA-ADK_SHIELD-EKG_Nexus4
Post by: metin on May 03, 2015, 06:43:21 PM
primarily in English is not good.sory..
HC06 and Arduino same bound rate.9600
signal amplitude short spike.very short.

my arduino code:
#include <SoftwareSerial.h>
SoftwareSerial myBluetooth(10, 11);
const int analogInPin = A5;
char outStr[5];
unsigned long LoopTimer = 0;

int sensorValue = 0;        // value read from the pot

const int LoopTime5000 = 5000;

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

void loop()
{
  if (micros() >= LoopTimer+LoopTime5000)
  {
   LoopTimer += LoopTime5000;
   sensorValue = analogRead(analogInPin);           
   sensorValue = sensorValue >> 2*;
   sprintf(outStr,"%03d",sensorValue);
   myBluetooth.print("*");
   myBluetooth.write(outStr);
  }
}
Title: Re: MEGA-ADK_SHIELD-EKG_Nexus4
Post by: metin on May 03, 2015, 07:13:36 PM
And my Arduino power comes from the laptop
image of the smartphone output
(http://imgur.com/UCVrLRF)
http://imgur.com/UCVrLRF (http://imgur.com/UCVrLRF)
Title: Re: MEGA-ADK_SHIELD-EKG_Nexus4
Post by: svan on May 03, 2015, 09:46:37 PM
Thank you for posting the image.  I'm not certain that there is an ecg in the trace.  Do you have the jumper on the Olimex board set to A5?  Pins 11,12 should be jumpered together.

>SoftwareSerial myBluetooth(10, 11);

I'm not familiar with SoftwareSerial; what are the two parameters, 10 and 11?

> sensorValue = sensorValue >> 2*;

Why is there an asterisk(*) after the two?

What software are you using on the smartphone?

If you are unable to get it to work, and you send me an e-mail address, I will try to work with you off-list to get it running.
Title: Re: MEGA-ADK_SHIELD-EKG_Nexus4
Post by: metin on May 03, 2015, 10:28:27 PM
pin 10 get bluetooth value, pin 11 is send bluetooth value..

This is feature of bluetooth library.. very thanks for your advice and attenion..

(*) is my mistake in writing to forum..

i using your project at this adress github.com/vsquared/ecg..

i am importing this code on eclipe..

my device is samsung tablet, android 4.4.4
Title: Re: MEGA-ADK_SHIELD-EKG_Nexus4
Post by: svan on May 04, 2015, 02:19:31 AM
1) It appears to me that the ecg signal from the Olimex shield is not being sent.
2) Would it be possible to post an image of the Olimex shield so that I can see how the jumpers are set?
3) How is the HC06 attached to the Arduino?  Is it attached to a shield or are you using a breadboard with wiring?  If it is attached to a shield, is there a 'micro', 'USB' switch; if there is a switch, how is it set?
Title: Re: MEGA-ADK_SHIELD-EKG_Nexus4
Post by: metin on May 04, 2015, 11:19:01 PM
I upload image
http://imgur.com/BS99XAT,zVEi0xb,gTixOES,5QqImK1#0 (http://imgur.com/BS99XAT,zVEi0xb,gTixOES,5QqImK1#0)
http://imgur.com/BS99XAT,zVEi0xb,gTixOES,5QqImK1#1 (http://imgur.com/BS99XAT,zVEi0xb,gTixOES,5QqImK1#1)
http://imgur.com/BS99XAT,zVEi0xb,gTixOES,5QqImK1#2 (http://imgur.com/BS99XAT,zVEi0xb,gTixOES,5QqImK1#2)
http://imgur.com/BS99XAT,zVEi0xb,gTixOES,5QqImK1#3 (http://imgur.com/BS99XAT,zVEi0xb,gTixOES,5QqImK1#3)
very thanks...
Title: Re: MEGA-ADK_SHIELD-EKG_Nexus4
Post by: svan on May 05, 2015, 12:05:34 AM
The images are very helpful; thank you for posting.  AIN SEL should be set to A5 and you have it set to A0.  The jumper needs to go all the way to the other end.  The pins are in pairs and on the shield are labelled 1,3,5,7,9,11.  11 and 12 need to be jumpered together (currently 1,2 are jumpered).  Your ecg should appear after you set the jumpers correctly.  Attached image shows correct position (if it loads).

[img]BS99XAT.jpg/img]
Title: Re: MEGA-ADK_SHIELD-EKG_Nexus4
Post by: metin on May 05, 2015, 12:33:26 AM
but no picture appears...  :'(
Title: Re: MEGA-ADK_SHIELD-EKG_Nexus4
Post by: svan on May 05, 2015, 02:01:00 AM
> but no picture appears...

Not sure how to upload an image to this website.  Please try looking at your Olimex shield and following the instructions.
Title: Re: MEGA-ADK_SHIELD-EKG_Nexus4
Post by: metin on May 05, 2015, 10:24:51 PM
thank you very much swan!!
I am grateful to you.
Greetings from Turkey  :)
Title: Re: MEGA-ADK_SHIELD-EKG_Nexus4
Post by: svan on May 06, 2015, 12:03:43 AM
> thank you very much

You're welcome.  I presume that you got it working.  I'm curious what kind of signal quality that you have using bluetooth.  Would it be possible to post an image of your ecg going across the tablet?
Title: Re: MEGA-ADK_SHIELD-EKG_Nexus4
Post by: metin on May 08, 2015, 10:01:30 AM
Hello swan.
Sometimes I get the ECG signal is very nice but often comes EMG signals.
Passive Electrodes in the body exactly where to tie up?
Electrodes ->olimex Shield EKG-EMG-PA
Thanks..
Title: Re: MEGA-ADK_SHIELD-EKG_Nexus4
Post by: svan on May 08, 2015, 05:38:45 PM
>Passive Electrodes in the body exactly where to tie up?

Einthoven's Triangle is typically right wrist, left wrist, and left ankle.  Sometimes I put two electrodes on the left wrist and one on the right wrist and that also seems to work.  If you are using an ecg cable with adhesive electrodes, I use placement just below each clavicle (collar bone) and left lower rib cage.

After some experimentation to find optimal placement, I marked each electrode, eg, "R" for right wrist, "L" for left wrist, and "A" for left ankle.  Nothing bad happens if you scramble them, but this helps you to be consistent with lead placement once you find something that works.

For safety reasons, it is recommended that the Arduino be powered by a 9v battery and not the USB connector.  This is to protect the patient from stray currents coming from the electrical grid.