1. First connect MyoWare EMG sensor to Arduino:
MyoWare "+" to +ve on Arduino
MyoWare "-" to GND on Arduino
MyoWare "SIG" to analogue pin on Arduino
2. Code for printing what we get using the Arduino IDE serial monitor:
int analogValue = 0; // variable to hold the analog value void setup() { // open the serial port at 9600 bps: Serial.begin(9600); } void loop() { // read the analog input on pin 0: analogValue = analogRead(0); // print it out in many formats: Serial.println(analogValue); // print as an ASCII-encoded decimal Serial.println(analogValue, DEC); // print as an ASCII-encoded decimal Serial.println(analogValue, HEX); // print as an ASCII-encoded hexadecimal Serial.println(analogValue, OCT); // print as an ASCII-encoded octal Serial.println(analogValue, BIN); // print as an ASCII-encoded binary delay(10) }
Code from https://www.arduino.cc/en/Serial/Println
serial.begin is to set data rate in baud https://www.arduino.cc/en/Serial/Begin
analogRead(0) analogue read from A0 pin on Arduino - put this in analogValue
Then go ahead and print the analogValue to the serial monitor
Next just print it to serial monitor
Then we can use the serial plotter too! e.g. http://www.instructables.com/id/Ultimate-Guide-to-Adruino-Serial-Plotter/
Ah ok, so we should get data corresponding to open vs. closed fist from that.
Ok, so we want to get a threshold value for closed fist. If it's above that we have closed fist, if it's below we don't have it.
Set const int closed_fist_threshold = whatever that value is
So then it's just if(analogRead(0) > closed_fist_threshold: we have closed fist!
or else if (analogRead(0) < closed_fist_threshold: we don't have closed fist!
** this is all C++
----
It all seems very easy, but this threshold value will be the same for everyone? I think we will have to test this! I don't think it will be!
const int closed_fist_threshold = ??? ///// threshold for closed fist. Anything
//above is closed fist. Below is not closed fist
void setup()
{
//start serial monitor, set data rate 9600 Baud
Serial.begin(9600);
void loop()
{
//print EMG data to serial monitor for debug
Serial.println(analogRead(0));
//if EMG data greater than threshold, we have a fist
if(analogRead(0) > closed_fist_threshold) {
//do something
}
//if EMG data lower than threshold, we don't have a fist made
else if (analogRead(0) < closed_fist_threshold) {
//do something
}
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.