Go Down

Topic: Android Bluetooth joystick (Read 293432 times) previous topic - next topic

kas

Hi Kas
A thought for the future.
Would it be possible to have the Android device get Button Labels and Datafield Labels from the Arduino IDE via the BlueTooth comms.
e.g  B1 = "LED <On/Off>"
     Data3 = "Status"
Interesting idea

I also have in mind to create a config file within the App
to store specific Button and Datafield Labels for several bots



Enerik

#871
Dec 23, 2017, 11:10 pm Last Edit: Dec 24, 2017, 05:35 pm by Enerik
Hello Kas ,


I am having a bit of trouble using the demo sketch on the atmega328P.
I am trying to do a BT controled arduino robot using two servos and the L9110 IC to control them as normal dc motors .
The problem is that the motor control works ok but i cant get any data transmited from the robot to android app , for example battery .
Also i am trying to set up an auto mode using a HC-sr04 sensor to measure distance but until now i cant figure out how to do it so ican activate it and deactivate it from a button on android app .
Attached is my code based on the demo code v2 , the app version is 5.5.



Cheers
Enerik

kas

Quote
The problem is that the motor control works ok but i cant get any data transmitted from the robot to android app , for example battery
Probably a wiring problem

Please forget your current project and go back to the basics
 - genuine Arduino Uno
 - original AndroTest V2.0 plain sketch
 
Let me know if it works



christophe_schmol

Hello Kas,

I am using your android application together with L298 driver module and hc05 Bluetooth module to control the tyco rebound RC car.

So far I am very happy about the app and it is very useful to me, thank you.

I have a few inquiries about the android app:

1. The RC car has 4 wheels, 2 left wheels are on one motor, 2 right wheels on the other motor.
Is it possible to modify the android application to have 2 controls (instead of one 2D-joystick), one for each motor?

2. I get a lot of 200 200 packets that do not correspond to joystick in (0,0) position and I have to filter these packets out in the android part, is this a known bug or am I doing something wrong? Because of this I can currently not use the "return-to-zero"-feature.

3. I would also like to have the possibility to engage active breaking (when thumb in 0 position) and free running motor (return to zero activated and no thumb on touch screen). Is it possible to send different flags also?

4. I have not found the source code anywhere, is it correct to assume that the code will not be released?

It would be nice if I you could answer some of my questions :)


kas

Quote
I am using your android application together with L298 driver module and hc05 Bluetooth module to control the tyco rebound RC car.
So far I am very happy about the app and it is very useful to me, thank you.
Thanks for the kind words   ;)

Sorry, this is a free robust multipurpose k.i.s.s App, I won't add additional features
The code is not public, as it is the base of a paid App



Quote
I get a lot of 200 200 packets that do not correspond to joystick in (0,0) position and I have to filter these packets out in the android part, is this a known bug or am I doing something wrong? Because of this I can currently not use the "return-to-zero"-feature.
Joystick BT has no known bugs AFAIK
Please let me have additional info, you may use the debug code
also make sure your communication is set at 57600 bps




christophe_schmol

Hello Kas,


Sorry, this is a free robust multipurpose k.i.s.s App, I won't add additional features
Ok that makes sense, I guess I will have to write an app myself, if I find the time for it :/



The code is not public, as it is the base of a paid App
What additional features does the paid app provide?
I have not found the app in the play store so far.


Joystick BT has no known bugs AFAIK
Please let me have additional info, you may use the debug code
also make sure your communication is set at 57600 bps
I use the hc05 bluetooth module and set the baud rate to 57600 via AT commands, then I connect the android application to the module and hook up my salea logic analyzer.
There I find out that indeed some "erronous" packets (with contents 200200) are sent over the bluetooth link.

App configuration:
- return to center: off
- two buttons displayed (not used)
- 3 data fields (not used)
- refresh interval: 25 milli
- timeout count: every 100 intervals
- no baud rate setting in the app (why?)

Here are the screenshots:
Overview of the saved transmissions:


Correct transmission:


Incorrect transmission:


This is the output from the logic analyzer async serial decoder.
Code: [Select]
Time [s],Value,Parity Error,Framing Error
0.000351500000000,'2' (0x02),,
0.000525125000000,2 (0x32),,
0.000698750000000,7 (0x37),,
0.000872375000000,1 (0x31),,
0.001046000000000,2 (0x32),,
0.001219625000000,8 (0x38),,
0.001393250000000,8 (0x38),,
0.001566875000000,'3' (0x03),,
0.026932958333333,'2' (0x02),,
0.027106583333333,2 (0x32),,
0.027280166666667,6 (0x36),,
0.027453833333333,7 (0x37),,
0.027627458333333,2 (0x32),,
0.027801083333333,9 (0x39),,
0.027974666666667,1 (0x31),,
0.028148291666667,'3' (0x03),,
0.050441291666667,'2' (0x02),,
0.050614916666667,2 (0x32),,
0.050788500000000,6 (0x36),,
0.050962166666667,6 (0x36),,
0.051135791666667,2 (0x32),,
0.051309375000000,9 (0x39),,
0.051483000000000,3 (0x33),,
0.051656625000000,'3' (0x03),,
0.076988000000000,'2' (0x02),,
0.077161625000000,2 (0x32),,
0.077335250000000,6 (0x36),,
0.077508875000000,4 (0x34),,
0.077682500000000,2 (0x32),,
0.077856125000000,9 (0x39),,
0.078029708333333,4 (0x34),,
0.078203333333333,'3' (0x03),,
0.100392166666667,'2' (0x02),,
0.100565750000000,2 (0x32),,
0.100739375000000,6 (0x36),,
0.100913000000000,0 (0x30),,
0.101086625000000,2 (0x32),,
0.101260250000000,9 (0x39),,
0.101433875000000,6 (0x36),,
0.101607500000000,'3' (0x03),,
0.125688791666667,'2' (0x02),,
0.125862416666667,2 (0x32),,
0.126036041666667,5 (0x35),,
0.126209666666667,9 (0x39),,
0.126383291666667,2 (0x32),,
0.126556916666667,9 (0x39),,
0.126730541666667,6 (0x36),,
0.126904125000000,'3' (0x03),,
0.150707583333333,'2' (0x02),,
0.150881208333333,2 (0x32),,
0.151054833333333,5 (0x35),,
0.151228458333333,8 (0x38),,
0.151402083333333,2 (0x32),,
0.151575708333333,9 (0x39),,
0.151749333333333,7 (0x37),,
0.151922958333333,'3' (0x03),,
0.179407208333333,'2' (0x02),,
0.179580833333333,2 (0x32),,
0.179754458333333,5 (0x35),,
0.179928083333333,7 (0x37),,
0.180101708333333,2 (0x32),,
0.180275333333333,9 (0x39),,
0.180448958333333,7 (0x37),,
0.180622583333333,'3' (0x03),,
0.180796208333333,'2' (0x02),,
0.180969833333333,2 (0x32),,
0.181143458333333,0 (0x30),,
0.181317083333333,0 (0x30),,
0.181490625000000,2 (0x32),,
0.181664291666667,0 (0x30),,
0.181837875000000,0 (0x30),,
0.182011500000000,'3' (0x03),,
0.182185125000000,'2' (0x02),,
0.182358750000000,2 (0x32),,
0.182532375000000,4 (0x34),,
0.182706000000000,3 (0x33),,
0.182879625000000,2 (0x32),,
0.183053250000000,6 (0x36),,
0.183226875000000,0 (0x30),,
0.183400500000000,'3' (0x03),,
0.204183000000000,'2' (0x02),,
0.204356625000000,2 (0x32),,
0.204530250000000,5 (0x35),,
0.204703875000000,5 (0x35),,
0.204877500000000,2 (0x32),,
0.205051041666667,9 (0x39),,
0.205224666666667,6 (0x36),,
0.205398291666667,'3' (0x03),,
0.227969125000000,'2' (0x02),,
0.228142750000000,2 (0x32),,
0.228316375000000,5 (0x35),,
0.228490000000000,4 (0x34),,
0.228663625000000,2 (0x32),,
0.228837166666667,9 (0x39),,
0.229010791666667,5 (0x35),,
0.229184416666667,'3' (0x03),,
0.252970541666667,'2' (0x02),,
0.253144166666667,2 (0x32),,
0.253317791666667,5 (0x35),,
0.253491416666667,1 (0x31),,
0.253665041666667,2 (0x32),,
0.253838666666667,9 (0x39),,
0.254012291666667,4 (0x34),,
0.254185916666667,'3' (0x03),,
0.276982375000000,'2' (0x02),,
0.277156000000000,2 (0x32),,
0.277329625000000,5 (0x35),,
0.277503250000000,0 (0x30),,
0.277676875000000,2 (0x32),,
0.277850500000000,9 (0x39),,
0.278024125000000,3 (0x33),,
0.278197750000000,'3' (0x03),,
0.328374291666667,'2' (0x02),,
0.328547916666667,2 (0x32),,
0.328721541666667,5 (0x35),,
0.328895166666667,0 (0x30),,
0.329068791666667,2 (0x32),,
0.329242416666667,9 (0x39),,
0.329416041666667,2 (0x32),,
0.329589666666667,'3' (0x03),,
0.378325208333333,'2' (0x02),,
0.378498833333333,2 (0x32),,
0.378672458333333,5 (0x35),,
0.378846083333333,1 (0x31),,
0.379019708333333,2 (0x32),,
0.379193250000000,9 (0x39),,
0.379366875000000,1 (0x31),,
0.379540500000000,'3' (0x03),,
0.404316291666667,'2' (0x02),,
0.404489916666667,2 (0x32),,
0.404663541666667,5 (0x35),,
0.404837166666667,2 (0x32),,
0.405010791666667,2 (0x32),,
0.405184416666667,9 (0x39),,
0.405358041666667,1 (0x31),,
0.405531666666667,'3' (0x03),,
0.429248333333333,'2' (0x02),,
0.429421958333333,2 (0x32),,
0.429595583333333,5 (0x35),,
0.429769208333333,5 (0x35),,
0.429942833333333,2 (0x32),,
0.430116458333333,8 (0x38),,
0.430290083333333,9 (0x39),,
0.430463708333333,'3' (0x03),,
0.456732583333333,'2' (0x02),,
0.456906208333333,2 (0x32),,
0.457079833333333,5 (0x35),,
0.457253458333333,7 (0x37),,
0.457427083333333,2 (0x32),,
0.457600708333333,8 (0x38),,
0.457774333333333,8 (0x38),,
0.457947958333333,'3' (0x03),,
0.480553416666667,'2' (0x02),,
0.480727041666667,2 (0x32),,
0.480900666666667,5 (0x35),,
0.481074291666667,9 (0x39),,
0.481247916666667,2 (0x32),,
0.481421541666667,8 (0x38),,
0.481595166666667,7 (0x37),,
0.481768791666667,'3' (0x03),,


https://ibb.co/cpNuCG
https://ibb.co/bJjkKw
https://ibb.co/fRBAmb


I hope I can help you in finding the issue with this information.
Please tell me when you need further data, I will be happy to provide.


kas

#876
Jan 04, 2018, 08:26 am Last Edit: Jan 04, 2018, 08:27 am by kas
Quote
What additional features does the paid app provide?
I have not found the app in the play store so far.
Have a look at Total  RC Commander


Quote
no baud rate setting in the app (why?)
The Bluetooth wireless transmission is by no way related to the HC-xx board Serial output


Quote
refresh interval: 25 milli
Which smartphone are you using ??
Please try 50 ms refresh interval and let me know if it helps



murcha

#877
Jan 30, 2018, 10:01 pm Last Edit: Jan 30, 2018, 10:09 pm by murcha
Hi kas,

Thanks for your excellent Joystick bluetooth Commander app.

This may have already been covered, but why do you need the delay(2) after Serial.available() in the arduino code ? I realise if delay(2) is removed the Serial.read() doesn't receive the bt data, but just wondering why a time delay is needed after Serial.available() ?

I am running a delay sensitive app on the arduino and wish to remove the delay(2)/delay(1) function from the code. FYI, I modified the arduino code to eliminate the delay() function, but it woud be nice to eliminate the need for a time delay after Serial.available().



Code: [Select]
  if(Serial.available())  {
    if (bt_read==0){
      bt_timer=micros()+1500;         // add 1.5ms delay
      bt_read=1;
    }
  }


  if ((bt_timer < micros())&&(bt_read==1)){ 
    bt_read=0;
    if (cmd_start==0) {
      cmd[0] = Serial.read();
      if(cmd[0] == STX)  {
        cmd_start=1;
        i=1;
      }
    }
    else if (cmd_start==1) {
      cmd[i] = Serial.read();
      if(cmd[i]>127 || i>7) cmd_start=0;
      if((cmd[i]==ETX) && (i==2 || i==7)) {
        if     (i==2)          getButtonState(cmd[1]);    // 3 Bytes  ex: < STX "C" ETX >
        else if(i==7)          getJoystickState(cmd);     // 6 Bytes  ex: < STX "200" "180" ETX >
        cmd_start=0;
      }
      i++;
    }
  }     


Again many thanks for your app.

Cheers

kas

#878
Jan 31, 2018, 08:25 am Last Edit: Jan 31, 2018, 08:26 am by kas
Hi murcha

Quote
Thanks for your excellent Joystick bluetooth Commander app.
Thanks for your feedback  :)



Quote
I realise if delay(2) is removed the Serial.read() doesn't receive the bt data, but just wondering why a time delay is needed after Serial.available() ?
if(Serial.available() == true)  means one byte at least has entered the received buffer
it takes some physical time for the complete data frame to get in



Quote
I am running a delay sensitive app on the arduino and wish to remove the delay(2)/delay(1) function from the code
Possible solutions:
 - increase baud rate to speed up the process, use 115200bps if you don't need softSerial
 - wait for additional Bytes to come: if(Serial.available())>2  (button data frame is 3 Bytes)
 - check for the [ETX] byte (0x03) availability in the buffer to get a complete data frame
 - combine #1 and #3

Communication protocol is here

Please experiment and let us know the result



manutroncoso

hola, soy nuevo en el uso de bluetooth y cargue código y reconoce el teléfono el arduino pero no he podido configurar la aplicación en el celu para que funcione... necesito ayuda porfa munutroncoso@yahoo.es

murcha

Hi Kas,

Thanks for your suggestions re using delay() after Serial.available() - I changed to using 115200 and everything is fine.

I have one other question, is it possible to use BLE with Joystick bluetooth Commander app ?

When I connect a HM-10 BLE module to the Arduino and try to connection with Joystick bluetooth Commander app I get connection failed.

Thanks again.

kind regards

kas

Quote
I have one other question, is it possible to use BLE with Joystick bluetooth Commander app ?
This version only support plain Bluetooth protocol, you can't use BLE



chilin

Hello kas. I really appreciate your android soft. It saved me a lot of time. I have a question.
How can I detect the event of the BT joystick connection and disconnection? I couldn't think of anything better than to check activity of mySerial.available() for 10000 millis after starting sketch. If there was zero activity then there was no connection. Perhaps you know a more proper way to do this?

kas

Quote
How can I detect the event of the BT joystick connection and disconnection?
Hi chilin

Your request is similar to the "Dead Man" feature, have a look here
Also adjust "refresh interval" in the App




RULDI

can you help me, with code, bt comander, to control my wheelchair

Go Up