This repository was archived by the owner on Feb 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMyoelectric-EMG-Sensors.ino
52 lines (43 loc) · 2.25 KB
/
Myoelectric-EMG-Sensors.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
#include "Arduino.h"
/* ========================================== OPTIONS ========================================== */
#define SENSOR_OUTPUT 1 // 0: No output, 1: Output
#include "emg.h"
#include "ml.h"
/* ========================================== SETUP ========================================== */
void setup() {
Serial.begin(115200); // Initialize serial communication
setupEMG(); // Initialize EMG sensor
setupML(); // Initialize ML model
}
/* ========================================== LOOP ========================================== */
void loop() {
setEmgSensor(emgDataProcessedCallback); // Set EMG sensor, while providing callback
}
/* ========================================== FUNCTIONS ========================================== */
// Callback function for when the emg data is processed
void emgDataProcessedCallback(float vReal1[], float majorPeak1, float majorPeakParabola1,
float vReal2[], float majorPeak2, float majorPeakParabola2,
float vReal3[], float majorPeak3, float majorPeakParabola3) {
if (SENSOR_OUTPUT) { // If sensor output is enabled print the data
Serial.println("NewData"); // This is significant as the Serial-to-ML program will look for this to know when to start reading data into the csv
PrintVector(vReal1);
PrintVector(vReal2);
PrintVector(vReal3);
Serial.println(majorPeak1);
Serial.println(majorPeak2); // Note that Serial-to-ML expects the delineator between datapoints to be a new line
Serial.println(majorPeak3);
Serial.println(majorPeakParabola1);
Serial.println(majorPeakParabola2);
Serial.println(majorPeakParabola3);
Serial.println("EndData"); // This is significant as the Serial-to-ML program will look for this to know when to end reading data into the csv
}
// Run the ML model
runML(vReal1, majorPeak1, majorPeakParabola1, vReal2, majorPeak2, majorPeakParabola2, vReal3, majorPeak3, majorPeakParabola3);
}
// Print the vector
void PrintVector(float *vData) {
int vDataLength = sizeof(vData) / sizeof(vData[0]);
for (uint16_t i = 0; i < vDataLength; i++) {
Serial.println(vData[i]);
}
}