Hello everyone. I am currently working on a project of muscle sensor as remote controller. It's a bit complicated and I am just getting started and what I am thinking is making data from muscle sensor when flexed as if it is moving the joystick forward. Currently trying out the ESP32-BLE-gamepad but I think it might only work with a proper controller like those DIY ones and not where I am substituting the sensor as controller. So my question is, are there any other libraries or any other way to make it work?
I've actually also done on scenario where the muscle flexing output is converted into keyboard button-> keyboard inputted as joystick in a virtual controller. However, because the muscle sensor uMyo used BLE to connect with ESP32, it clashes with ESP32-BLEkeyboard. So that is out. I am still brainstorming ideas but if there are anyone that could offer any sort of help it is greatly appreciated!!
For reference, this is the example code of the gamepad
/*
* This example turns the ESP32 into a Bluetooth LE gamepad that presses buttons and moves axis
*
* At the moment we are using the default settings, but they can be canged using a BleGamepadConfig instance as parameter for the begin function.
*
* Possible buttons are:
* BUTTON_1 through to BUTTON_16
* (16 buttons by default. Library can be configured to use up to 128)
*
* Possible DPAD/HAT switch position values are:
* DPAD_CENTERED, DPAD_UP, DPAD_UP_RIGHT, DPAD_RIGHT, DPAD_DOWN_RIGHT, DPAD_DOWN, DPAD_DOWN_LEFT, DPAD_LEFT, DPAD_UP_LEFT
* (or HAT_CENTERED, HAT_UP etc)
*
* bleGamepad.setAxes sets all axes at once. There are a few:
* (x axis, y axis, z axis, rx axis, ry axis, rz axis, slider 1, slider 2)
*
* Library can also be configured to support up to 5 simulation controls
* (rudder, throttle, accelerator, brake, steering), but they are not enabled by default.
*
* Library can also be configured to support different function buttons
* (start, select, menu, home, back, volume increase, volume decrease, volume mute)
* start and select are enabled by default
*/
#include <Arduino.h>
#include <BleGamepad.h>
BleGamepad bleGamepad;
void setup()
{
Serial.begin(115200);
Serial.println("Starting BLE work!");
bleGamepad.begin();
// The default bleGamepad.begin() above enables 16 buttons, all axes, one hat, and no simulation controls or special buttons
}
void loop()
{
if (bleGamepad.isConnected())
{
Serial.println("Press buttons 5, 16 and start. Move all enabled axes to max. Set DPAD (hat 1) to down right.");
bleGamepad.press(BUTTON_5);
bleGamepad.press(BUTTON_16);
bleGamepad.pressStart();
bleGamepad.setAxes(32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767);
bleGamepad.setHat1(HAT_DOWN_RIGHT);
// All axes, sliders, hats etc can also be set independently. See the IndividualAxes.ino example
delay(500);
Serial.println("Release button 5 and start. Move all axes to min. Set DPAD (hat 1) to centred.");
bleGamepad.release(BUTTON_5);
bleGamepad.releaseStart();
bleGamepad.setHat1(HAT_CENTERED);
bleGamepad.setAxes(0, 0, 0, 0, 0, 0, 0, 0);
delay(500);
}
}
and this one is the code I've done so far using BLE keyboard
#include <BleKeyboard.h>
BleKeyboard bleKeyboard;
/*
Obtaining muscle data from uMyo via BLE on various Arduino boards
Usage: install ArduinoBLE library, run the code on BLE enabled Arduino (nRF52 or ESP32 core)
- open Serial Plotter (or Serial Monitor) at 115200 speed
- turn on uMyo device
- switch it into BLE mode if necessary (to switch, press button once or twice, depending on current mode)
- you should see muscle activity chart on a plot (or as serial output)
*/
#include <uMyo_BLE.h>
int emgv=0;
void setup() {
Serial.begin(115200);
uMyo.begin();
Serial.println("Starting BLE work!");
bleKeyboard.begin();
}
void loop()
{
uMyo.run();
int dev_count = uMyo.getDeviceCount(); //if more than one device is present, show all of them
for(int d = 0; d < dev_count; d++)
{
// Serial.print(uMyo.getMuscleLevel(d));
Serial.print(uMyo.getAverageMuscleLevel(d));
int emgv = uMyo.getAverageMuscleLevel(d);
if (emgv >= 300){
bleKeyboard.press('W');
}
if(d < dev_count-1) Serial.print(' ');
else Serial.println();
}
/*
* byte idxL = 255;
*
* void loop(){
*
if(idxL > 250) //initialization, determine left/right hands indexes (idxL, idxR) by their orientation
{
float pitch0 = uMyo.getPitch(0);
float pitch1 = uMyo.getPitch(1);
if(pitch0 > 0 && pitch1 < 0)
{
idxL = 0;
idxR = 1;
}
else
{
idxL = 1;
idxR = 0;
}
}
int thrust = uMyo.getMuscleLevel(idxL);//lvl_l;// - 300;
*
*/
delay(30);
}