Arduino + myo via bluetooth HC-06// led control

Hello everybody, I'm new in this forum. I'm trying to control leds with MYO armband.
Myo is connected to PC(bridge between myo and arduino) with it's dongle and arduino is connected via HC-06 to PC. I'm using ARDUINO 1.6.4 software and myoduino.
Underneath is my code. What is wrong.

#include <MyoController.h>
char val;


#define FIST_PIN 7
#define WAVEIN_PIN 10
#define WAVEOUT_PIN 11
#define FINGERSSPREAD_PIN 12
#define DOUBLETAP_PIN 13

MyoController myo = MyoController();

void setup() {

  Serial1.begin(9600);
  pinMode(FIST_PIN, OUTPUT);
  pinMode(WAVEIN_PIN, OUTPUT);
  pinMode(WAVEOUT_PIN, OUTPUT);
  pinMode(FINGERSSPREAD_PIN, OUTPUT);
  pinMode(DOUBLETAP_PIN, OUTPUT);
  
  myo.initMyo();
}

void loop()
{
    if( Serial1.available()>0)      
  {
    val = Serial1.read();        
   //Serial.println("HI");
   myo.updatePose();
   
   switch ( val == myo.getCurrentPose() ) {
    case rest:
      digitalWrite(FIST_PIN,LOW); 
      digitalWrite(WAVEIN_PIN,LOW);
      digitalWrite(WAVEOUT_PIN,LOW);
      digitalWrite(FINGERSSPREAD_PIN,LOW);
      digitalWrite(DOUBLETAP_PIN,LOW);
      delay(100);
      break;
    case fist:
      digitalWrite(FIST_PIN,HIGH);
      delay(100);
      break;
    case waveIn:
      digitalWrite(WAVEIN_PIN,HIGH);
      delay(100);
      break;
    case waveOut:
      digitalWrite(WAVEOUT_PIN,HIGH);
      delay(100);
      break;
    case fingersSpread:
      digitalWrite(FINGERSSPREAD_PIN,HIGH);
      delay(100);
      break;
    case doubleTap:
      digitalWrite(DOUBLETAP_PIN,HIGH);
      delay(100);
      break;
   } 
   delay(100);
}
}

Hello and welcome,

switch ( val == myo.getCurrentPose() ) {
    case rest:
    ...

A comparison can only have two results: true or false

val = Serial1.read();

Serial.read() will read only one character and removes it from the serial input buffer. So your val will contain only one character. Is this what you want to do?

Other than that, it's not possible to tell you what is wrong, because you don't explain what it is doing that you think is wrong..

Have a look at the examples in serial input basics for simple reliable ways to receive data.

...R

Thank's for your response.

Underneath is wiring shema
and original code(leds controlled via usb by myo)
I want to control leds via bluetooth:

#include <MyoController.h>

#define FIST_PIN 13
#define WAVEIN_PIN 12
#define WAVEOUT_PIN 11
#define FINGERSSPREAD_PIN 10
#define DOUBLETAP_PIN 9

MyoController myo = MyoController();

void setup() {

  pinMode(FIST_PIN, OUTPUT);
  pinMode(WAVEIN_PIN, OUTPUT);
  pinMode(WAVEOUT_PIN, OUTPUT);
  pinMode(FINGERSSPREAD_PIN, OUTPUT);
  pinMode(DOUBLETAP_PIN, OUTPUT);
  
  myo.initMyo();
}

void loop()
{
   //Serial.println("HI");
   myo.updatePose();
   switch ( myo.getCurrentPose() ) {
    case rest:
      digitalWrite(FIST_PIN,LOW); 
      digitalWrite(WAVEIN_PIN,LOW);
      digitalWrite(WAVEOUT_PIN,LOW);
      digitalWrite(FINGERSSPREAD_PIN,LOW);
      digitalWrite(DOUBLETAP_PIN,LOW);
      break;
    case fist:
      digitalWrite(FIST_PIN,HIGH);
      break;
    case waveIn:
      digitalWrite(WAVEIN_PIN,HIGH);
      break;
    case waveOut:
      digitalWrite(WAVEOUT_PIN,HIGH);
      break;
    case fingersSpread:
      digitalWrite(FINGERSSPREAD_PIN,HIGH);
      break;
    case doubleTap:
      digitalWrite(DOUBLETAP_PIN,HIGH);
      break;
   } 
   delay(100);
}

How does the MyController instance know where to get data? I suspect that it is expecting to get data from the hardware serial port. If that is the case, you will need to re-write the library to make it get data from a SoftwareSerial instance, using the pins the bluetooth device is connected to.

PaulS:
I suspect that it is expecting to get data from the hardware serial port

It looks like I misunderstood what was wanted when I wrote Reply #2

If there is no need for the USB connection, why not just connect the Bluetooth device to pins 0 and 1 so it uses HardwareSerial ?

...R

I would use the MYO with Arduino without the PC, it is possible?

The Myo bluetooth protocol is available here, if you want to try a direct connection: http://developerblog.myo.com/myo-bluetooth-spec-released/

There have been a few implementations for other platforms (check out GitHub - mamo91/Dongleless-myo: Replacement for MyoConnect on linux without the official Myo dongle. and PyoConnect - MyoConnect for Linux), but the only Myo<->Adruino connection I've seen actually released is the one that uses a PC as a bridge (http://www.instructables.com/id/Gesture-Enable-your-Arduino-Project-with-a-Myo-Arm/)