BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

HM10 says its connected but nothing happens

arduino

#1

Hello,

i have an blynk app which controls many LEDs with an HM10 module. And since this year the Bluetooth Connection with the HM10 module dosent work anymore. Sometimes i can connect and control the app for a short time but then it stops working. Maybe it is the initialisation of the HM10 module?

Here is a part of the sketch:


#include <Blynk.h>

//#define BLYNK_PRINT Serial   <------ comment here

#define BLYNK_USE_DIRECT_CONNECT

#include <BlynkSimpleSerialBLE.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "bc91216cb249448fb6952f200dca808f";
int var = 0;
//            0           1          2          3          4          5          6          7          8          9
byte e[10] = { B1111110, B0110000, B1101101, B1111001, B0110011, B1011011, B1011111, B1110000, B1111111, B1111011 };

unsigned long secondpreviousMillis = 0;
unsigned long secondinterval = 1000;
//initialisierung des Anzeigewerte.
//n-tes element des Arrays ist n-te 7Segment-Anzeige (SA)
int SAStatus[5] = {0, 0, 0, 0, 0};
int SAStatus45[5] = {0, 0, 5, 4, 0};
int SAStatus90[5] = {0, 0, 0, 9, 0};
int SAStatus105[5] = {0, 0, 5, 0, 1};

#define SerialBLE  Serial      // Set Serial object

void setup()
{
  for (int i = 0; i < 55; i++) {
    pinMode(i, OUTPUT);
    digitalWrite(i, HIGH);
  }
  digitalWrite(44, !HIGH);
  digitalWrite(45, !HIGH);
  digitalWrite(46, !HIGH);
  digitalWrite(47, !HIGH);
  digitalWrite(48, !HIGH);
  digitalWrite(49, !HIGH);
  digitalWrite(5, !HIGH);
  digitalWrite(6, !HIGH);
  digitalWrite(7, !HIGH);
  digitalWrite(8, !HIGH);
  digitalWrite(9, !HIGH);
  digitalWrite(10, !HIGH);
  SerialBLE.begin(9600);        // Set Serial baud rate
  Blynk.begin(auth, SerialBLE);

  {
    Serial.begin(9600);
  }
}

I hope you can help me!
Thank you!


#2

Where is your loop method in sketch?


#3

Sorry forgot to paste… here it comes

//Inkrementiere nächsthöhere Segment-Anzeige wenn Limit, z.B. 10 oder 6, erreicht
//falls nicht erreicht, dann behalte wert bei
void EditSA(int NummerSA, int limit)
{
  if (SAStatus[NummerSA] == limit)
  {
    SAStatus[NummerSA] = 0;
    SAStatus[NummerSA + 1]++;
  }
  else if(SAStatus45[NummerSA] == limit)
  {
    SAStatus45[NummerSA] = 0;
    SAStatus45[NummerSA + 1]++;
  }
    else if(SAStatus90[NummerSA] == limit)
  {
    SAStatus90[NummerSA] = 0;
    SAStatus90[NummerSA + 1]++;
  }
  else if(SAStatus105[NummerSA] == limit)
  {
    SAStatus105[NummerSA] = 0;
    SAStatus105[NummerSA + 1]++;
  }
}

//setzt die n1-te segmentanzeige auf den "value" im array e[] zugeordneten wert
void segmentzugriff(int n1, byte value) {

  //n-tes element des arrays ist pinnummer des ersten Segments der n1-ten Segmentanzeige
  int ErsterPinSegment[5] = {34, 27, 20, 13, 12};


  //der erste Pin der insgesamt als digital output verwendet wird
  int ErsterPin = 2;

  //code n für versuch von NR
  //n-tes element des arrays ist pinnummer des ersten Segments der n1-ten Segmentanzeige
  //int ErsterPinSegment[9] = {0, 7, 14, 21, 28, 35, 42, 49, 56};
  //int ErsterPinSegment[9] = {ErsterPin, ErsterPin+7, ErsterPin+2*7, ErsterPin+3*7, ErsterPin+4*7, ErsterPin+5*7, ErsterPin+6*7, ErsterPin+7*7, ErsterPin+8*7};



  //Annahme, dass die steuerung einer Anzeige immer über sieben aufeinander folgende Pins geschieht
  //k2 ist zaehlvariable; k1 ist das k2-te segment der n1-ten segmentanzeige, gerechnet in pins;
  for (int k2 = 0; k2 <= 6; k2++)
  {
    if (ErsterPinSegment[n1] == 12) {
      digitalWrite(19, LOW);//geändert Lukas eben grade
    } else {
      int k1 = ErsterPinSegment[n1] + k2;

      if ((value & B1000000) > 0)
        digitalWrite(k1, LOW);
      else
        digitalWrite(k1, HIGH);
      value = value << 1;
    }
  }
}

void loop()
{
  Blynk.run();
}
'''

#4

Is there anyone who can help me?
I had thoughts that there is a bug in blynk app maybe because in former times it worked.


#5

Okay maybe i found my problem but i cant solve it.
For your understanding:
I have build a big scoreboard where you can show the actueal game time and the score of a football game.

In our Program there is a method which displayes the time like a stopp watch.
But it is an infinity loop as long a button is pressed. But at the same time I have to control a step widget which counts point from 0 - 29. So my workaround was it to call Blynk.run every second so that i can jump into my counting method.

Do you have an idea how i can control both actions at the same time?
If you need it i can provide you the complete sketch but you may laughting because of my bad coding skills^^

Sorry for my bad English.
Hope you can help me!


Kudos to non-english speakers
#6

Sounds to me like you just need a timer to increment the game time. Here I’m using a Button widget to start and stop the clock. You’d likely have a second Button widget to reset the clock and possibly a Time Input Widget. Does this clock count down? I’m using a Numeric Input widget to increment and decrement the score. The game clock increments are one second.

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "xxx";
char ssid[] = "xxx";
char pass[] = "xxx";

BlynkTimer timer;

#define START_STOP_CLOCK_BUTTON V0
#define SCORE_NUMERIC_INPUT     V2

int game_timer_id;
int game_clock = 0;
int score = 0;

BLYNK_WRITE(START_STOP_CLOCK_BUTTON) {  // <- tied to Button widget
   int button = param.asInt();
   if (button)
      timer.enable(game_timer_id);
   else
      timer.disable(game_timer_id);
}

BLYNK_WRITE(SCORE_NUMERIC_INPUT) {  // <- tied to Numeric Input widget
   score = param.asInt();
}

void setup(void) {
   Serial.begin(115200);
   Blynk.begin(auth, ssid, pass);
   while (!Blynk.connect());
   game_timer_id = timer.setInterval(1000L, game_time);
   timer.disable(game_timer_id);
}

void loop(void) {
   Blynk.run();
   timer.run();
}

void game_time(void) {
   game_clock++;
}

#7

Thanks for your anwser.
My Clock counts up.
I think i understand now how to use the Blynk timer.

Does the timer block the system like the delay() function?


#8

It’s not a question of whether the BlynkTimer blocks the system. It’s a question of whether your per-interval function, game_time() in my example, blocks the system. If you do “bad things” in the context of your per-interval function, it’s fundamentally no different than if you do bad things in the context of the loop() function. The BlynkTimer in and of itself isn’t a panacea. The BlynkTimer simply ensures your function is only invoked as-needed, rather than being invoked continuously as part of the loop() function. You want to set the timer interval as large as possible while still satisfying your needs. You want to get what you need to get done in the context of your per-interval function and get out of there.