/
readEMGData.ino
executable file
·53 lines (45 loc) · 1.38 KB
/
readEMGData.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <MyoBridge.h>
#include <SoftwareSerial.h>
//SoftwareSerial connection to MyoBridge
SoftwareSerial bridgeSerial(2,3);
//initialize MyoBridge object with software serial connection
MyoBridge bridge(bridgeSerial);
//declare a function to handle EMG data
void handleEMGData(int8_t data[8]) {
//the EMG data is 8bit signed integers. Just print them out:
Serial.print(data[0]);
Serial.print(" ");
Serial.print(data[1]);
Serial.print(" ");
Serial.print(data[2]);
Serial.print(" ");
Serial.print(data[3]);
Serial.print(" ");
Serial.print(data[4]);
Serial.print(" ");
Serial.print(data[5]);
Serial.print(" ");
Serial.print(data[6]);
Serial.print(" ");
Serial.print(data[7]);
Serial.println(" ");
}
void setup() {
//initialize both serial connections
Serial.begin(115200);
bridgeSerial.begin(115200);
//wait until MyoBridge has found Myo and is connected. Make sure Myo is not connected to anything else and not in standby!
Serial.println("Searching for Myo...");
bridge.begin();
Serial.println("connected!");
//set the function that handles EMG data
bridge.setEMGDataCallBack(handleEMGData);
//tell the Myo we want the filtered EMG data
bridge.setEMGMode(EMG_MODE_SEND);
//disable sleep mode, so we get continous data even when not synced
bridge.disableSleep();
}
void loop() {
//update the connection to MyoBridge
bridge.update();
}