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.
- Why does the attached simplyFunCalibration block serial
- 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);
}
}
- Does anyone have a tried and tested script for this that uses the mouse library to click.
- 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)