1

Topic: More input cause bluetooth disconnected.

I have a few successful projects with RemoteXY, really like it. But for new project with 4 input, bluetooth connection was terminated within about 20 second.  This in not a free version time limit, use RemoteXY paid version. And, this is not a hardware problem, since this set of hardware work well in other RemoteXY projects. I notice that if use one input, such as 1 text edit field, system run with no problem. But, if when place more input in a loop, bluetooth get disconnected within about 20 second. I've tried another approach, read input first, then store data in EEPROM in void setup state, then read from EEPROM into a loop , but, no luck, bluetooth still get disconnected. Have you ever got this problem? How do you deal with it? Any ideas from all you guys are more than appreciated. Thank you.

BTW, i've tried different 5v power sources for HC-05, excepted 3.3 v.

2

Re: More input cause bluetooth disconnected.

Hello. Can you share a sketch that does not work?

3 (edited by mac 2017-07-26 08:37:18)

Re: More input cause bluetooth disconnected.

Sure, and i have more info that may help clarify the problem. I found that if i remove  delay commands, the system work fine. So, problem may be on the code side, not the App. or hardware. I think new question should be; how can i make program wait for amount of time without using delay command.

void loop()
{

  RemoteXY_Handler ();
 
    for ( int i=0; i<RemoteXY.total; i++){

  if (RemoteXY.start_button==0){
  }
   else {

  digitalWrite(relay, HIGH);
  delay(RemoteXY.wait_1);

  if (RemoteXY.start_button==1){
  digitalWrite(relay, LOW);
    delay(RemoteXY.wait_2);

    }
}
}

}

4

Re: More input cause bluetooth disconnected.

Of course you should not use delay. It locks your code during that time. It's bad practice, especially when you have a wireless UI which must be responsive.

You have to use the method shown in the arduino's "blink without delay" example.

This will require that you use another coding style, the program flow will be harder to visualize, so I recommend that you also look at how to make a finite state machine.

5

Re: More input cause bluetooth disconnected.

Hi Guillaume, thank you for your reply.

I've read that example and tried to use 'millis' for a while. This lead me to new trouble. Can I ask about coding here.?

6 (edited by Guillaume 2017-08-04 05:03:22)

Re: More input cause bluetooth disconnected.

Hello,

Here is a simple FSM I just wrote, I hope it can serve as an example to help you understand how to write your program.

This is for a modification of my computer display so that I can turn it on and off with RemoteXY. It simulates a press of 400ms on the "on/off" momentary pushbutton of the display, and then do nothing (but doesn't lock the microcontroller) during 4 seconds to avoid possible spam.

uint8_t pwrBtnSimState = 0;

void pwrBtnSimTry()
{
    if ( pwrBtnSimState == 0 )
    {
        pwrBtnSimState = 1;
    }
}

void pwrBtnSimFSM()
{
    static uint32_t timer = 0;

    switch ( pwrBtnSimState )
    {
        case 1 :
        {
            digitalWrite( powerButtonPin, HIGH );
            timer = millis();
            pwrBtnSimState = 2;
            break;
        }
        case 2 :
        {
            if ( millis() - timer >= 400UL )
            {
                digitalWrite( powerButtonPin, LOW );
                timer = millis();
                pwrBtnSimState = 3;
            }
            break;
        }
        case 3 :
        {
            if ( millis() - timer >= 4000UL )
            {
                pwrBtnSimState = 0;
            }
            break;
        }
    }
}


void loop()
{
    // Try to start the simulation of the display's power button when the corresponding RemoteXY button is pressed
    uint8_t rxyPwrBtn = RemoteXY.pwrBtn;
    static uint8_t rxyPwrBtn_prev = rxyPwrBtn;

    if ( rxyPwrBtn_prev != rxyPwrBtn )
    {
        rxyPwrBtn_prev = rxyPwrBtn;

        if ( rxyPwrBtn == 1 )
        {
            pwrBtnSimTry();
        }
    }

    // Always run the FSM
    pwrBtnSimFSM();

    ...
}

7

Re: More input cause bluetooth disconnected.

Oh, thank you, man.