Go Down

Topic: Two EMG, one Arduino (Read 124 times) previous topic - next topic

Spartan1344

Hello, within this project I'm trying out I have found myself trying to use two EMGs and one Arduino to analyze and compare muscle voltages. The goal is to measure muscle atrophy through this comparison and output the results to led lights. I believe I understand how I will average out the EMGs, but the problem I'm having is getting two separate reading for the EMG at the moment (Serial monitor only displays one?). I am new to Arduino but have been suggested to use "class" statements as to complete this from peers.


The main components are the readings of "Reading L" & "ReadingR".

Code in full below just in case:

int R13 = 13;
int R12 = 12;
int Y11 = 11;
int Y10 = 10;
int G9 = 9;
int G8 = 8;

const int ReadingL = A0;
const int ReadingR = A1;

const int numReadings = 500;
int readings[numReadings]; // the readings from the analog input
int readIndex = 0; // the index of the current readings
int total = 0;  // running total shiiii
int average = 0;  // the index of the current reading

long Good;
long Bad;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(500000);
  pinMode(R13, OUTPUT);
  pinMode(R12, OUTPUT);
  pinMode(Y11, OUTPUT);
  pinMode(Y10, OUTPUT);
  pinMode(G9, OUTPUT);
  pinMode(G8, OUTPUT);

  for (int thisReading = 0; thisReading < numReadings; thisReading++)
  {
    readings[thisReading] = 0;
}
}
void loop() {
  // put your main code here, to run repeatedly:
  Good = analogRead(ReadingL);
  Bad = analogRead(ReadingR);
  Serial.println(Good);
  Serial.println(Bad);
  //?   Serial.Println(InputR);

   // hypothetically

  total = total - readings[readIndex]; // subtract the last reading:
  readings[readIndex] = analogRead(ReadingL); // read from the sensor:
  total = total + readings[readIndex]; // add the reading to the total:
  readIndex = readIndex + 1; // advance to the next position in the array:
  if (readIndex >= numReadings) // if we're at the end of the array...
{ readIndex = 0; //wrap to beginning
  }

  //calculate average
  average = total / numReadings;
  // send it to the computer as ASCII digits
  Serial.println(average);
  delay(1);        // delay in between reads for stability

  // hypothetially! Got to average the two readings
  // Light up the lights

 
  // WYA = AvgBad/AvgGood
  // if WYA <= 0.16667
  digitalWrite(R13, HIGH);
  //  else if WYA <= 0.333
  digitalWrite(R12, HIGH);
  // else if WYA <= 0.5
  digitalWrite(Y11, HIGH);
  // else if WYA <= 0.6667
  digitalWrite(Y10, HIGH);
  // else if WYA <= 0.833
  digitalWrite(G9, HIGH);
  // else if WYA <= 1
  digitalWrite(G8, HIGH);
 



}

pylon

Code: [Select]
const int numReadings = 500;
int readings[numReadings]; // the readings from the analog input


This uses half of the available memory of your UNO. Were you aware of that?

Quote
but the problem I'm having is getting two separate reading for the EMG at the moment (Serial monitor only displays one?).
What output do you get? I would expect to see 3 lines with values for every run of loop().

Go Up