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

Joystick Issues over bluetooth


#1

I am working on creating an interface that will allow me to control a robot with the joystick widget. However, the joystick will randomly give out bad data and give the message “Your app is outdated.” I am connecting to the app with the HC-06 bluetooth module which is connected to an Arduino Mega 2560.


BLE connection problems / a question to all blynk users
#2

Your request for assistance has produced the error message “Your code is missing, unable to analyse”.

PS, make sure your app is up to date and please format any code you post as per forum instructions.


#3
/*************************************************************
  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.
    Downloads, docs, tutorials: http://www.blynk.cc
    Blynk community:            http://community.blynk.cc
    Social networks:            http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app
  Blynk library is licensed under MIT license
  This example code is in public domain.
 *************************************************************
  This example shows how to use Arduino with HC-06/HC-05
  Bluetooth 2.0 Serial Port Profile (SPP) module
  to connect your project to Blynk.
  Note: This only works on Android! iOS does not support SPP :(
        You may need to pair the module with your smartphone
        via Bluetooth settings. Default pairing password is 1234
  Feel free to apply it to any other example. It's simple!
  NOTE: Bluetooth support is in beta!
  You can receive x and y coords for joystick movement within App.
  App project setup:
    Two Axis Joystick on V1 in MERGE output mode.
    MERGE mode means device will receive both x and y within 1 message
 *************************************************************/

/* Comment this out to disable prints and save space */
//#define BLYNK_PRINT Serial


#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>
#include "const.h"

int  app_x = ZERO_POS_1;
int  app_y = ZERO_POS_1;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
//char auth[] = "5b3c219d02064bf6a5d64ed986864d76"; // Samsung
char auth[] = "398ee9323e1b4d2a9ffb911a0a04107f"; // Billy's Phone
//char auth[] = "57164fa41a1046d8bc7c224b13981802"; // Moriah's Phone
//char auth[] = "1cf0a97c2cdb445ba218caeacd8d5e18"; // Kenyon's Phone


SoftwareSerial SerialBLE(10, 11); // RX, TX
//int pwrBtn;     //the soft kill switch for the app
//int irBtn;      //Button turning on and off Ir system
int joyUp;      //joystick in the up directions
int joySide;    //Joystick in the side directions

double bar;     //Sliding Bar used for maximum speed

void killSwitch(){
  int pwrBtn = !digitalRead(2);
  if(pwrBtn){
//    Serial.print("pwr = ");
//    Serial.println(pwrBtn);
    Blynk.notify("Yaaay... button is pressed!");
  }
}
void irSwitch(){
  int irBtn = !digitalRead(3);
  if(irBtn){
//    Serial.print("ir = ");
//    Serial.println(irBtn);
    Blynk.notify("Yaaay... button is pressed!");
  }
}
WidgetMap myMap(V4);
void deviceLocation(){
  myMap.clear();
  int index = 1;
  float lat = 51.5074;
  float lon = 115.1278;
  myMap.location(index, lat, lon, "value");
  
}
BLYNK_WRITE(V2){
  bar = param.asDouble();

  Serial.print("Bar = ");
  Serial.println(bar);
}

BLYNK_WRITE(V1) {
  joyUp = param[1].asInt();//-127)*(bar/100)+127;
  joySide = param[0].asInt();
 
  // Do something with x and y
/*  Serial.print("X = ");
  Serial.print(joySide);
  Serial.print("; Y = ");
  Serial.println(joyUp);
*/  app_x = joySide;
  app_y = joyUp;
 
}

int app_x_axis() {
  return app_x;
}

int app_y_axis() {
  return app_y;
}

void setup_app()
{
  // Debug console
  // Serial.begin(9600);

  SerialBLE.begin(9600);
  Blynk.begin(SerialBLE, auth);
  //pinMode(2, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(2), killSwitch, CHANGE);
  //pinMode(1, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(3), irSwitch, CHANGE);
  Serial.println("Waiting for connections...");
}

void loop_app()
{
  
  Blynk.run();
  Blynk.virtualWrite(V3,3.14);
  deviceLocation();
  //Serial.println("This will make me happy if I see this.");
  
}

#4

Wow… OK, without even digging into the code, I see three (out of 4) problems… Even if each of those four devices have the same version app (which might explain part of the error msg)… each app’s joystick widget will be competing with the other three for control of the hardware.

Just get these same four people to simultaneously move your car’s steering wheel, as it boogies down the road, and you will understand :wink:


#5

but he apparently is using only one token, not all 4! i think probably is because he tried if the app works better on different phones…

so this should not be the problem.

regarding the “Your app is outdated.” message: it was the same for me, further back when tried to use bluetooth with blynk (without success). i’ve got this same message at random intervals and no matter what i tried, couldn’t get rid of it. it is not related to app version, but i think is some bug in the app.

maybe @BlynkAndroidDev should look into this…
@Usuafrl2017, please give some more details about your app version, phone models you tried so far and android versions!


#6

Good catch… perhaps I should have “dug into” the code :blush:

Being that he is controlling a moving object, over bluetooth, then I think there is probably just a combination of too much too fast, but not enough loss to trigger a full disconnect? That could explain the joystick commands being misinterpreted.

No idea on the message… maybe a Bluetooth thing?


#7

i do not know what to say… i had a very bad experience using blynk + bluetooth / ble some time ago. and debugging for days / weeks, trying 5 different bluetooth / ble modules, different phones, etc, but i never could isolate what was the problem. in the end i dropped the whole idea with bluetooth communication, and moved the whole project to wifi (d1 mini pro)… since than the wifi communication it works flawless.

this is why it would be better to look the devs into this topic. maybe there are some bugs in the sketch (i’m on phone right now, so i can not analyse the sketch in detail) - but maybe it is something else.


#8

The two phone I currently am using are a Nexus 6p with Android 7.1.1 and Blynk version 2.10.1 and a Samsung S6 with Android 6.0.1 and Blynk version 2.10.1. What wifi module would you recommend for Arduino Mega?


#9

depending what you want with your final project, and how many digital / analog pins you will need, maybe you can try a wemos d1 mini pro. (it has fast cpu, incorporated wifi, tons of ram and flash, ota sketch upload, but very limited on pins)

if you need lots of pins, or have some special reason to use the arduino mega, you can consider enc28j60 ethernet module.

maybe you should try a debug version of the app, to see whats happening…
@Dmitriy or @BlynkAndroidDev, could you please look into this bluetooth issue?


#10

Please install the build by the following link: https://www.dropbox.com/s/5nmh2rn9182b377/blynk_app_log.apk?dl=0

It will collect a log of your communication via the bluetooth. To send it please open app’s about screen and select ‘send log’ option there. Also, could you show devices list screen for this project?


#11

@BlynkAndroidDev Thanks for the respone. I sent the log file via email. I have attached a screen shot of the device list.

From the joysick I got as inaccurate as X = 14140 and Y as 2


#12

After the logs check I could say that app is sending data in the [0, 255] range. But there are some issues with strange responses - will update this topic later with a new build.


#13

it seems actually there is some wifi module for arduino. i don’t know if it is compatible with mega, you should find out:
https://www.arduino.cc/en/Main/ArduinoWiFiShield

and, also, theoretically could be possible to use an esp8266 module for wifi with arduino mega, but i do not have any experience with this. you should search for this…


#14

Thank you. I have found some ways to add wifi to the Arduino Mega however, I need the robot to be mobile outside so I would also need a router on the robot which I would like to avoid if at all possible.


#15

@BlynkAndroidDev Hello, I was just checking in to see if there was any update available for possible resolution of this problem.


#16

We are working on new app’s update and after release I’ll provide you with new logging build, as I don’t see any errors in app’s sent data.


#17

I’ve made additional logging build for BLE issues: https://drive.google.com/open?id=0B9c7bWQmIMfHMTRQZkF1TE1YTWs. If you could try it with your BLE boards and reproduce your bugs - you can send a log file from about screen.