Converting EMG signals with Arduino and saving to MicroSD Card

Hi,

I am about to begin a project and thought I would get the insight of some more experienced Arduino users (I have only been using Arduino for a month so any help is appreciated).

Basically I am conducting an experiment to test muscles spasms in a patient's cheek. They will wear a bandage with electrodes on it. The EMG signals from the bandage will be amplified and sent to the Arduino's A to D converters. Every signal must be time stamped and a signal must be taken maybe twice to ten times a second (I have not decided yet). Then I will load the signal's value and the respective timestamp into an array which will then be saved on a micro SD card. The data will then be sent to MATLAB for analysis etc etc.

Seems simple when I write it out like that, but being a noob on Arduino there are simple things that I just don't even know how to do. how do I convert the EEG signals to arduino? Do the A/D pins do this automatically? I know there is a millis() function that I will use to track time, and assign it to a EEG value.

If anyone has done anything like this and has some sample code, it would be much appreciated. ANY insight whatsoever would help. How would you go about coding/solving this project? Thank you to all.

Seems simple when I write it out like that,

No it dose not. What do you mean by a signal? Do you want to record a single static value from a sensor that returns a constantly changing changing value, or do you want to return a sequence of numbers that represent the samples returned in the period of time since you last recorded it?

You need to know what you want to do in a lot more detail before we can give advice as to how you can possibly do anything.

My apologies Grumpy Mike, I was not clear enough. So lets say every two milliseconds I retrieve the voltage data, which is just a static number at that instant. I will save that to an array, along with the time stamp that goes with it. Two milliseconds go by, I retrieve the voltage data, save it to the same array along with the timestamp for that point, repeat repeat repeat over the course of a day. What more details would you like?

Do you already have a circuit that will amplify the minute signals from the electrodes to a level that can be detected by the Arduino?

ppatricklydonn: how do I convert the EEG signals to arduino? Do the A/D pins do this automatically?

They could do this, but its not automatic. Perhaps you could start by simulating the EEG input with a potentiometer: https://www.arduino.cc/en/Tutorial/ReadAnalogVoltage

This could be a first baby step, eventually replacing the pots by the circuit JohnLincoln was referencing. Adding an SD card also has tutorials. Chip away at it one feature at a time.

Maybe someone more familiar with the SD library on arduino could comment on the speed of writing samples every 2ms. I'm guessing that the SD write is buffered and only physically writes to the card once the buffer is full. For example every 9 samples are quick but the 10th fills the buffer and then it physically writes to the SD card, which may blow up your 2ms sample rate for the next sample.

Yes, JohnLincoln, my partner says he will be able to deal with the circuitry side of things if I can deal with the programming side.

Thank you bDeters for the insight. I was also wondering about the speed at which I could run this program and how fast it could be written onto an SD. Does anyone have experience with SD cards that could clarify? HOwever I did have a typo, I did not mean 2ms rather I meant every 200ms, so 5 readings per second. Thank you for all the help Arduino Community

I did not mean 2ms rather I meant every 200ms, so 5 readings per second.

So what speed is your signal changing at? A sample rate of 200mS seems way too slow to me. Their is a thing called the Nyquist_rate which basically says you can't see any signal unless you sample at least twice in any one period of the signal.

If you have a known sample rate then their is no need for a time stamp on each sample because you know it is xx mS from the last one. Unless the time stamp includes the real clock time then you do not even need one at the start.

As an SD card can record data at an audio rate so this very slow data rate is within the capabilities of an SD card.

I think you have a lot more reading to do.

Thank you for the reference for the Nyquist_rate. I wouldnt have to put it with a time stamp, but it seems that it would be easy and useful with the tools Arduino provides with you.

You are right I do need to do some more reading, that is one of the reasons I posted in the forum. Do you have any recommendations on what I should read, any links? Thank you Grumpy Mike for sticking with me.

but it seems that it would be easy and useful with the tools Arduino provides with you.

Well the only tool in the basic Arduino is the millis timer, and that is the number of milliseconds since the Arduino last reset. If you want the true time you would have to use a real time clock ( RTL ). Like this one https://www.adafruit.com/product/264

Do you have any recommendations on what I should read,

Read about sampling audio signals, what you are trying to do is very much the same only you have a slower frequency signal.

Grumpy Mike, you are correct on everything you have said. 200ms is way too slow, I was getting confused between projects. The rate of 2ms, which I initially said, is correct, pr atleast reasonable (I might want to change it to 1 ms or 0.5ms if the Arduino can handle that). I will be getting voltage readings from the electrode every 2ms.

Now a question I have is: what is the most efficient way of intializing this and looping it. The way i was generally thinking was this: Using the millis() function create a loop where every 2 millisecons it retrieves the voltage data, then writes it to the SD card.

What would be the best way to do this? write every individual point as it is retrieved in real time to the SD card or should I collect many points on the arduino's memory and then move those points over to the SD card in groups of 100 or 200 or something.

I have much more reading to do and will continue doing that, but any insight is appreciated.

Using the millis() function create a loop where every 2 millisecons it retrieves the voltage data, then writes it to the SD card.

Sounds like a plan.

should I collect many points on the arduino's memory and then move those points over to the SD card in groups of 100 or 200 or something.

Yse I think that would be better.