Skip to content

Commit 18e3824

Browse files
committed
Release commit (v1.0.0)
1 parent d466021 commit 18e3824

11 files changed

Lines changed: 1161 additions & 5 deletions

File tree

ISSUE_TEMPLATE.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
### Subject of the issue
2+
Describe your issue here.
3+
4+
### Your workbench
5+
* What development board or microcontroller are you using?
6+
* What version of hardware or breakout board are you using?
7+
* How is the breakout board wired to your microcontroller?
8+
* How is everything being powered?
9+
* Are there any additional details that may help us help you?
10+
11+
### Steps to reproduce
12+
Tell us how to reproduce this issue. Please post stripped down example code demonstrating your issue.
13+
14+
### Expected behavior
15+
Tell us what should happen
16+
17+
### Actual behavior
18+
Tell us what happens instead

LICENSE renamed to LICENSE.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
MIT License
1+
Advancer Technologies License Information
2+
============================
3+
4+
**Advancer Technologies code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).**
5+
6+
The MIT License (MIT)
27

38
Copyright (c) 2024 Advancer Technologies
49

510
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
11+
of this software and associated documentation files (the Software), to deal
712
in the Software without restriction, including without limitation the rights
813
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
914
copies of the Software, and to permit persons to whom the Software is
@@ -12,7 +17,7 @@ furnished to do so, subject to the following conditions:
1217
The above copyright notice and this permission notice shall be included in all
1318
copies or substantial portions of the Software.
1419

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1621
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1722
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1823
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,35 @@
1-
# MyoWare-Arduino-Library
2-
Arduino library for the MyoWare Muscle Sensor and Ecosystem
1+
# MyoWare Arduino Library
2+
3+
This library provides a simple interface for interacting with the [MyoWare 2.0 Ecosystem](https://www.sparkfun.com/myoware) using Arduino.
4+
5+
### MyoWare Wireless Shield Examples
6+
- [MyoWareBLEPeripheral](examples/MyoWareBLEPeripheral): An example of how to setup a MyoWare 2.0 Wireless Shield as a BLE peripheral device using the ArduinoBLE and MyoWare Arduino libraries.
7+
- [MyoWareBLECentral](examples/MyoWareBLECentral): An example of how to setup a MyoWare 2.0 Wireless Shield as a BLE central device using the ArduinoBLE and MyoWare Arduino libraries.
8+
- [MyoWareBLEUART](examples/MyoWareBLEUART): An example of how to setup a MyoWare 2.0 Wireless Shield to send data to mobile apps such as [Adafruit Blufruit app](https://play.google.com/store/apps/details?id=com.adafruit.bluefruit.le.connect&hl=en_US&gl=US&pli=1) as a BLEUART device using the ESP32 BLE Arduino and MyoWare Arduino libraries.
9+
10+
### Other Examples
11+
- [ReadMyoWareVoltage](examples//ReadMyoWareVoltage): An example of how to read and convert data from a MyoWare 2.0 Muscle Sensor using the MyoWare Arduino Library.
12+
- [TestMyoWareSamplingRate](examples/TestMyoWareSamplingRate): An example of how a simple way to calculate your Arduino device's sampling rate. Note: The MyoWare 2.0 Muscle Sensor is an analog device so your sampling rate wholly depends on your Arduino device and code, not the sensor itself.
13+
14+
15+
## MyoWare 2.0 Ecosystem
16+
17+
The MyoWare 2.0 ecosystem consists of shields that easily interface with the [MyoWare 2.0 Muscle Sensor](https://www.sparkfun.com/products/21265), which is a low-cost, Arduino-compatible, all-in-one electromyography (EMG) sensor from [Advancer Technologies](https://myoware.com). The innovative connector system allows users to easily snap shields together with a compact low profile and connect to a microcontroller's analog input to measure raw, filtered, and rectified electrical activity of a target muscle. This eliminates the need to solder connections between boards.
18+
19+
### Documentation
20+
21+
- [Getting Started with the MyoWare 2.0 Muscle Sensor Ecosystem](https://learn.sparkfun.com/tutorials/getting-started-with-the-myoware-20-muscle-sensor-ecosystem/all)
22+
- [MyoWare 2.0 Quick Start Guide](https://myoware.com/wp-content/uploads/2022/03/MyoWare_v2_QuickStartGuide.pdf)
23+
- [MyoWare 2.0 Advanced Guide](https://myoware.com/wp-content/uploads/2022/03/MyoWare_v2_AdvancedGuide-Updated.pdf)
24+
25+
## Support
26+
27+
[MyoWare 2.0 Ecosystem](https://www.sparkfun.com/myoware) technical support is now handled via [r/MyoWare on Reddit](https://www.reddit.com/r/MyoWare/)! Technical Support moderators will be monitoring the Subreddit during weekdays. Additionally, you can get help through [SparkFun Electronics support and forums](https://forum.sparkfun.com/viewforum.php?f=143).
28+
29+
## License
30+
31+
This open source code is licensed under the MIT license (see [LICENSE](LICENSE.md)
32+
for details).
33+
34+
The MyoWare 2.0 Ecosystem is a collaboration between [Advancer Technologies](https://myoware.com) and [Sparkfun Electronics](https://www.sparkfun.com), please support future MyoWare development by purchasing products from
35+
[Sparkfun Electronics](https://www.sparkfun.com/myoware)!
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
/*
2+
MyoWare BLE Central Example Code
3+
Advancer Technologies, LLC
4+
Brian Kaminski
5+
8/01/2023
6+
7+
This example sets up a BLE Central device, Then, it connects
8+
to up to four MyoWare 2.0 Wireless Shields that are reading the ENV and RAW
9+
outputs of a MyoWare Muscle sensor. It then streams the selected output data
10+
(ENVELOPE or RAW) from all sensors on the Serial Terminal.
11+
12+
Note, in BLE, you have services, characteristics and values.
13+
Read more about it here:
14+
https://www.arduino.cc/reference/en/libraries/arduinoble/
15+
16+
Note, before it begins checking the data and printing it,
17+
It first sets up some BLE stuff:
18+
1. sets up as a central
19+
2. scans for and connects to any MyoWare 2.0 Wireless Shields for 10 seconds
20+
21+
In order for this example to work, you will need a MyoWare 2.0 Wireless Shield,
22+
and it will need to be programmed with the MyoWare BLEnPeripheral code,
23+
and advertizing with the unique and correlating characteristic UUID.
24+
25+
Note, both the service and the characteristic need unique UUIDs and each
26+
MyoWare 2.0 Wireless Shield needs a unique name (e.g. MyoWareSensor1, MyoWareSensor2)
27+
28+
This "BLE Central", will read each MyoWare 2.0 Wireless Sensor,
29+
aka the "BLE Peripheral", charactieristic, parse it for the ENV and RAW values,
30+
and print them to the serial terminal.
31+
32+
Hardware:
33+
BLE device (e.g. Artemis Redboard)
34+
USB from BLE device to Computer.
35+
36+
** For consistent BT connection follow these steps:
37+
** 1. Reset Peripheral
38+
** 2. Wait 5 seconds
39+
** 3. Reset Central
40+
** 4. Enjoy BT connection
41+
**
42+
** ArduinoBLE does not support RE-connecting two devices.
43+
** If you loose connection, you must follow this hardware reset sequence again.
44+
**
45+
** ArduinoBLE does not support connecting more than four peripheral devices.
46+
47+
This example code is in the public domain.
48+
*/
49+
50+
#include <ArduinoBLE.h>
51+
#include <MyoWare.h>
52+
#include <vector>
53+
54+
// debug parameters
55+
const bool debugLogging = false; // set to true for verbose logging to serial
56+
57+
std::vector<BLEDevice> vecMyoWareShields;
58+
59+
// MyoWare class object
60+
MyoWare myoware;
61+
62+
void setup()
63+
{
64+
Serial.begin(115200);
65+
while (!Serial);
66+
67+
pinMode(myoware.getStatusLEDPin(), OUTPUT); // initialize the built-in LED pin to indicate
68+
// when a central is connected
69+
70+
// begin initialization
71+
if (!BLE.begin())
72+
{
73+
Serial.println("Starting BLE failed!");
74+
75+
while (1);
76+
}
77+
78+
if (debugLogging)
79+
{
80+
Serial.println("MyoWare BLE Central");
81+
Serial.println("-------------------");
82+
}
83+
84+
// start scanning for MyoWare Wireless Shields
85+
if (debugLogging)
86+
{
87+
Serial.print("Scanning for MyoWare Wireless Shields: ");
88+
Serial.println(MyoWareBLE::uuidMyoWareService.c_str());
89+
}
90+
91+
BLE.scanForUuid(MyoWareBLE::uuidMyoWareService.c_str(), true);
92+
93+
// scan for Wireless Shields for 10sec
94+
const long startMillis = millis();
95+
while (millis() - startMillis < 10000)
96+
{
97+
myoware.blinkStatusLED();
98+
99+
BLEDevice peripheral = BLE.available();
100+
if (peripheral && std::find(vecMyoWareShields.begin(), vecMyoWareShields.end(), peripheral) == vecMyoWareShields.end())
101+
{
102+
if (debugLogging)
103+
{
104+
Serial.print("Connecting to ");
105+
PrintPeripheralInfo(peripheral);
106+
}
107+
108+
// connect to the peripheral
109+
BLE.stopScan();
110+
if (peripheral.connect())
111+
{
112+
if (!peripheral.discoverAttributes())
113+
{
114+
Serial.println("Discovering Attributes... Failed!");
115+
if (!peripheral.discoverAttributes())
116+
{
117+
Serial.println("Discovering Attributes... Failed!");
118+
Serial.print("Disconnecting... ");
119+
PrintPeripheralInfo(peripheral);
120+
peripheral.disconnect();
121+
Serial.println("Disconnected");
122+
continue;
123+
}
124+
}
125+
vecMyoWareShields.push_back(peripheral);
126+
}
127+
else
128+
{
129+
Serial.print("Failed to connect: ");
130+
PrintPeripheralInfo(peripheral);
131+
}
132+
BLE.scanForUuid(MyoWareBLE::uuidMyoWareService.c_str(), true);
133+
}
134+
}
135+
BLE.stopScan();
136+
137+
if (vecMyoWareShields.empty())
138+
{
139+
Serial.println("No MyoWare Wireless Shields found!");
140+
while (1);
141+
}
142+
143+
digitalWrite(myoware.getStatusLEDPin(), HIGH); // turn on the LED to indicate a
144+
// connection
145+
146+
for (auto shield : vecMyoWareShields)
147+
{
148+
auto ritr = vecMyoWareShields.rbegin();
149+
if (ritr != vecMyoWareShields.rend() && shield != (*ritr))
150+
{
151+
Serial.print(shield.localName());
152+
Serial.print("\t");
153+
}
154+
else
155+
{
156+
Serial.println(shield.localName());
157+
}
158+
}
159+
}
160+
161+
void loop()
162+
{
163+
for (auto shield : vecMyoWareShields)
164+
{
165+
if (!shield)
166+
{
167+
Serial.print("Invalid MyoWare Wireless Shields pointer! MAC Address: ");
168+
Serial.println(shield);
169+
auto itr = std::find(vecMyoWareShields.begin(), vecMyoWareShields.end(), shield);
170+
if (itr != vecMyoWareShields.end())
171+
vecMyoWareShields.erase(itr);
172+
continue;
173+
}
174+
175+
if (debugLogging)
176+
{
177+
Serial.print("Updating ");
178+
PrintPeripheralInfo(shield);
179+
}
180+
181+
if (!shield.connected())
182+
{
183+
// output zero if the Wireless shield gets disconnected
184+
// this ensures data capture can continue for the
185+
// other shields that are connected
186+
Serial.print("0.0");
187+
Serial.print("\t");
188+
continue;
189+
}
190+
191+
BLEService myoWareService = shield.service(MyoWareBLE::uuidMyoWareService.c_str());
192+
if (!myoWareService)
193+
{
194+
Serial.println("Failed finding MyoWare BLE Service!");
195+
shield.disconnect();
196+
continue;
197+
}
198+
199+
// get sensor data
200+
BLECharacteristic sensorCharacteristic = myoWareService.characteristic(MyoWareBLE::uuidMyoWareCharacteristic.c_str());
201+
202+
const double sensorValue = ReadBLEData(sensorCharacteristic);
203+
Serial.print(sensorValue);
204+
205+
if (vecMyoWareShields.size() > 1)
206+
Serial.print(",");
207+
}
208+
Serial.println("");
209+
}
210+
211+
// Read the sensor values from the characteristic
212+
double ReadBLEData(BLECharacteristic& dataCharacteristic)
213+
{
214+
if (dataCharacteristic)
215+
{
216+
if (dataCharacteristic.canRead())
217+
{
218+
// read the characteristic value as string
219+
char characteristicValue[20];
220+
dataCharacteristic.readValue( &characteristicValue,20);
221+
const String characteristicString(characteristicValue);
222+
223+
return characteristicString.toDouble();
224+
}
225+
else
226+
{
227+
if (debugLogging)
228+
{
229+
Serial.print("Unable to read characteristic: ");
230+
Serial.println(dataCharacteristic.uuid());
231+
}
232+
return 0.0;
233+
}
234+
}
235+
else
236+
{
237+
if (debugLogging)
238+
Serial.println("Characteristic not found!");
239+
}
240+
return 0.0;
241+
}
242+
243+
void PrintPeripheralInfo(BLEDevice peripheral)
244+
{
245+
Serial.print(peripheral.address());
246+
Serial.print(" '");
247+
Serial.print(peripheral.localName());
248+
Serial.print("' ");
249+
Serial.println(peripheral.advertisedServiceUuid());
250+
}

0 commit comments

Comments
 (0)