Myoware Muscle Sensor Mouse Input Issues

Hello,

Arduino rookie here; I am trying to make a reliable mouse using the Myoware muscle sensor.

Attached is all the scripts the scripts I have used / co-belled together.

simplyFunCalibration

/*Simply Fun Calibration Daniel Kendall calibration() by me; other code adapted from Muscle Mouse*/

#include <Mouse.h>
void setup();
void loop();

const int sensorPin = A0;
const int ledPin = 13;
const int calibrated = calibration();
boolean UpdateSensorState();
void SendSensors();

int Threshold = 300;
boolean bPrevSensorState=false;
boolean bCurrSensorState=false; 

void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(sensorPin, INPUT);
  Serial.begin(9600);

}

void loop()
{  
  consoleLog(); 
  UpdateState();
}
void consoleLog()
{
  int val = analogRead(sensorPin);
  delay(3000);
  Serial.print("SimplyFun Sensor Read: ");
  Serial.print(val);
  Serial.print("\n"); 

}

void UpdateState()
{     
  int val = analogRead(sensorPin);
  if(val >= calibrated)
  {
    Mouse.press(MOUSE_LEFT);  

  }
  else
  {
    Mouse.release(MOUSE_LEFT);  

  }

}

int calibration()

{
  int counter = 0;
  int val = analogRead(sensorPin);
  int total =0;

  while (counter < 11)
  { 
    delay(1000);
    Serial.print("SimplyFun Calibration Value: ");
    Serial.print(val);
    Serial.print("\n"); 
    total+=val;
    counter+=1;
  }
  int calibrated = total/10;
  Serial.print("Calibrated Value:");
  Serial.print(calibrated);
  Serial.print("\n");
  return calibrated;
}

I have tried Myoware muscle mouse and adapting that; the above script (simplyFunCalibration) wipes out serial access atm.

  1. Why does the attached simplyFunCalibration block serial
  2. The attached image shows placement for the one time the below code block instead of without calibration worked
/* Simply Fun Demo By Daniel Kendall
adapted from Myoware Mouse added mouse input*/

#include <Mouse.h>
void setup();
void loop();

boolean UpdateSensorState();
void SendSensors();

const int sensorPin = A0;
const int ledPin = 13;

int Threshold = 100;
boolean bPrevSensorState=false;
boolean bCurrSensorState=false; 

void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(sensorPin, INPUT);
  Mouse.begin();
  Serial.begin(9600);
  delay(100);
}

void loop()
{  
  consoleLog();
  UpdateState();
  doInput();  
}
void consoleLog()
{
  int val = analogRead(sensorPin);
  delay(1000);
  Serial.print("SimplyFun Sensor Read: ");
  Serial.print(val);
  Serial.print("\n"); 

}
void UpdateState()
{    
  int val = analogRead(sensorPin);
  if(val >= Threshold)
  {
    bPrevSensorState = bCurrSensorState;
    bCurrSensorState = true;
  }
  else
  {
    bPrevSensorState = bCurrSensorState;
    bCurrSensorState = false;
  }

}

void doInput()
{

  if(bCurrSensorState && !bPrevSensorState)
  {
    Mouse.press(MOUSE_LEFT);  
  }
  else if(!bCurrSensorState && bPrevSensorState)
  {
    delay(150);
    Mouse.release(MOUSE_LEFT);  
  }
}
  1. Does anyone have a tried and tested script for this that uses the mouse library to click.
  2. Any diagram showing ideal placement of sensor per muscle and direction of movement to trigger the strongest EMG response

I am using a Leonardo

simplyFunCalibration.ino (1.25 KB)

simplyFun.ino (1.11 KB)

CalibrationIfAmpas.ino (1.44 KB)

Please post your code.
Use code tags.

Done :slight_smile:

I looked at the photograph that you posted - it is blurred and out of focus.

I can't be bothered to download the .ino files that you posted, because I would have to download them, and then store them in a folder with the correct name, so that I could open them in the Arduino IDE. After viewing them I would then have to delete them, so as not to clutter up my hard drive.

There is a proper way of adding your sketch to a topic, you should use it.

AND WHEN YOU PUT "URGENT HELP NEEDED MYOWARE MOUSE", THAT IS LIKE SHOUTING, SO I AM LESS LIKELY TO WANT TO HELP YOU.

You may find that there are others with the same attitude.

What's the point of the while loop in function "calibration"?

To calculate the sum of 10 sensor readings. After the while loop this is then divided by 10 to give an average threshold. Then if the user then moves muscle exceed threshold and click

To calculate the sum of 10 sensor readings.

Or, as is actually the case, to sum the same reading ten times.
(And a "for" loop would have been more concise)

Doh ofcourse the sensorRead is outside and val won't change!

int calibration()

{
  int total =0;
  int counter;
for(counter=0;counter<11;counter++)  { 
    delay(1000);
      int val = analogRead(sensorPin);
    Serial.print("SimplyFun Calibration Value: ");
    Serial.print(val);
    Serial.print("\n"); 
    total+=val;
  }
  int calibrated = total/10;
  Serial.print("Calibrated Value:");
  Serial.print(calibrated);
  Serial.print("\n");
  return calibrated;
}