Hello,
I connected an Arduino nano 33 IoT to the Myo armband and tried to read EMG data from the Myo sensors. I am using the Arduino BLE library to read the EMG characteristics but I didn't succeed to read the real data.
First, I am not sure about the right functions to use. I have to notify the characteristics and then read them. Here is my code:
void armband::get_emg_data(BLEDevice peripheral){
BLEService EmgDataService = peripheral.service("d5060005-a904-deb9-4748-2c7f4a124842");
if (EmgDataService) {
// use the service
Serial.println("Peripheral has EMG service");
BLECharacteristic EmgData0Characteristic = peripheral.characteristic("d5060105-a904-deb9-4748-2c7f4a124842");
BLECharacteristic EmgData1Characteristic = peripheral.characteristic("d5060205-a904-deb9-4748-2c7f4a124842");
BLECharacteristic EmgData2Characteristic = peripheral.characteristic("d5060305-a904-deb9-4748-2c7f4a124842");
BLECharacteristic EmgData3Characteristic = peripheral.characteristic("d5060405-a904-deb9-4748-2c7f4a124842");
// subscribe to emg characteristic
Serial.println("Subscribing to EMG char");
if (!EmgData0Characteristic && !EmgData1Characteristic && !EmgData2Characteristic && !EmgData3Characteristic){
Serial.println("no EMG Char found");
peripheral.disconnect();
return;
}else if(!EmgData0Characteristic.subscribe() && !EmgData1Characteristic.subscribe() && !EmgData2Characteristic.subscribe() && !EmgData3Characteristic.subscribe()){
Serial.println("subscription failed!");
peripheral.disconnect();
return;
}else{
Serial.println("Subscribed!");
}
while(peripheral.connected()){
//while the peripheral is connected
// armband::emgdata0 = EmgData0Characteristic.value();
EmgData0Characteristic.readValue(emgdata0); //stores incoming data in the value byte.
EmgData0Characteristic.readValue(emgdata1); //stores incoming data in the value byte.
EmgData0Characteristic.readValue(emgdata2); //stores incoming data in the value byte.
EmgData0Characteristic.readValue(emgdata3); //stores incoming data in the value byte.
emg_callback(emgdata0);
emg_callback(emgdata1);
emg_callback(emgdata2);
emg_callback(emgdata3);
}
}else{
Serial.println("EMG service not found");
peripheral.disconnect();
}
}
void armband::print_emg_sample(int8_t *sample, size_t len)
{
for (int i = 0; i < len; i++)
{
Serial.print(sample[i]);
Serial.print("\t");
}
Serial.println();
}
void armband::emg_callback(uint8_t pData)
{
myohw_emg_data_t *emg_data = (myohw_emg_data_t *)pData;
print_emg_sample(emg_data->sample1, myohw_num_emg_sensors);
//Serial.println("");
}
I got this data when I read from only one characteristic
10:55:09.801 -> -4 127 0 32 1 6 0 0
10:55:10.051 -> -4 127 0 32 1 6 0 0
10:55:10.284 -> -4 127 0 32 1 6 0 0
10:55:10.518 -> -4 127 0 32 1 6 0 0
10:55:10.782 -> -4 127 0 32 1 6 0 0
10:55:11.015 -> -4 127 0 32 1 6 0 0
10:55:11.282 -> -4 127 0 32 1 6 0 0
10:55:11.514 -> -4 127 0 32 1 6 0 0