-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTestMyoWareSamplingRate.ino
More file actions
78 lines (59 loc) · 2.39 KB
/
TestMyoWareSamplingRate.ino
File metadata and controls
78 lines (59 loc) · 2.39 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
Test MyoWare Sample Rate Example Code
Advancer Technologies, LLC
Brian Kaminski
2/24/2024
This example calculates the sampling rate of a microcontroller reading muscle
activity from a MyoWare Muscle Sensor.
The MyoWare Muscle Sensor is an analog sensor therefore the sampling rate
will be entirely determined by the hardware specifications of the Arduino and the
performance of the code used.
For the most accurate sampling rate, insert your code inside the loop indicated
below. This will more closely mirror your intended use case to see how additional
commands/calls would impact the sampling rate.
Hardware:
MyoWare 2.0 Muscle Sensor
Arduino-compatible Microcontroller
This example code is in the public domain.
*/
#include <MyoWare.h>
const long samples = 1000000; // number of samples
// MyoWare class object
MyoWare myoware;
void setup()
{
Serial.begin(115200);
while(!Serial);
Serial.println("Sampling Test");
Serial.println("------------------------------");
myoware.setENVPin(A3); // Arduino pin connected to ENV
pinMode(myoware.getStatusLEDPin(), OUTPUT); // initialize the built-in LED pin to indicate
// when a central is connected
digitalWrite(myoware.getStatusLEDPin(), LOW);
}
void loop()
{
// initialize variables
int testValue = 0;
digitalWrite(myoware.getStatusLEDPin(), HIGH);
Serial.println("Start Time:\t" + String(micros()) + " microsec");
// perform numerous read actions
// modify this to read all the output pins on the MyoWare Muscle Sensor that
// you are planning to use in your setup.
unsigned long startMicros = micros(); // variable for starting time in microseconds
for (long i = 0; i < samples; i++)
{
// INSERT YOUR CODE HERE
testValue = myoware.readSensorOutput(MyoWare::ENVELOPE);
}
const unsigned long endMicros = micros();
Serial.println("Finish Time:\t" + String(endMicros) + " microsec");
digitalWrite(myoware.getStatusLEDPin(), LOW);
// calculate the microseconds per sample (elapsed_time / number_of_samples)
// then convert to seconds
const double secondsPerSample = (endMicros - startMicros) / samples;
// write out the sampling rate in Hz
Serial.println("Sampling Rate:\t" + String((1.0 / secondsPerSample) * 1000000) + " Hz");
Serial.println("------------------------------");
delay(1000);
}