Go Down

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


Great news, if you want I can also test. I have a wanscam IP camera (similar  to foscam)


Great news, if you want I can also test. I have a wanscam IP camera (similar  to foscam)

Why not  :)

This a screen shot of "Total RC Commander" V0.1B:

The application is working but for the moment, the screen is optimized only for a 8" tablet
I suspect the application needs at least 7" to display the information correctly
sorry, no phones  :~ :~

Do you have a tablet ??
Please let me have size and resolution


Wow, that was quick.
Yes I do have a tablet. Nexus 7 (2012) 7" 1280*800


Let me have your email via PM



Hi, kas!
I am unable to implement your VERY COOL 8) app simply due to  my inability to modify the Arduino sketch to meet my needs.  I have little experience with microcontrollers, or in any programming in general, having started about 6 months ago with the Arduino, and have spent countless brain numbing hours since trying to understand basic sketch examples with little results.  But I am very interested in figuring this out, as you mentioned in post #1, the possibilities are endless!

I have installed V.3.1 of your joystick app on my phone(samsung galaxy s3) and installed the v10.2 sketch from your post #99.  I have the JY_MCU bluetooth module and everything seems to be communicating properly.

I wonder if you would consider my intentions, and provide some guidance on modifying the code/code snippets to ease me along?

      My interest right now is simply to turn on and off three LEDs with the Android buttons(pressing Android button one turns on led1, press it again turns it off, same for button2 for led2 and button3 for led3) and drive one standard r/c servo both directions(CW, 0, CCW) using the joystick x axis.  So far, I have been able to get some results with LEDs by using "digital.write" following several of the eight "case" statements, but for the most part the results are unreliable/unpredictable from what I expect.  In viewing the serial monitor after my sketch modifications, I can not make sense of what is happening and why.  I have not even attempted anything with the joystick, figured the LEDs would be easier first.

Many thanks for sharing your work, it is very nice!


Jan 12, 2014, 09:19 pm Last Edit: Jan 12, 2014, 09:36 pm by kas Reason: 1
I wonder if you would consider my intentions, and provide some guidance on modifying the code/code snippets to ease me along?


First step

1) Which Arduino board are you using ?

2) download and run this sketch and confirm baurate + firmware version

Code: [Select]
// JY-MCU Bluetooth Dongle configurator
// Credit to Jeff Simpson

// Utility will display actual Baud rate and as an option,
// set up a new Baud rate

// TX BT board pin to Arduino D2
// RX BT board pin to Arduino D3
// 5V BT board pin to Arduino 5V
// GND BT board pin to Arduino GND

#include "SoftwareSerial.h"

SoftwareSerial mySerial(2, 3);          // BlueTooth module TX RX
char response[21];                      // responses from module
int rv = 0;                             // return value
boolean found = false;                  // module found
int bps;

void setup()  {
 Serial.print("\n\nJY-MCU Bluetooth Dongle configurator ");
 Serial.print("\nSearching ");            // Search for BT module on 12 possible baudrates
 long baud[12] = {1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600, 1382400};
 for(int a = 0; a < 12; a++)
 {  mySerial.begin(baud[a]);
    mySerial.write("AT");               // "AT" will respond with "OK" if it is working
    mySerial.readBytes(response, 2);
    if (strncmp(response, "OK", 2) == 0)
    {  Serial.print("\nBluetooth Module found at BAUD ");
    } else  Serial.print(".");
 if (found==false)
 { Serial.println("\nERROR: Bluetooth Module not responding!");
   Serial.println("Make sure there are no active bluetooth connection and try again");
 mySerial.write("AT+VERSION");           // Check the firmware version
 while(mySerial.available() == 0);
 if (strncmp(response, "OK", 2)==0)
 { rv = mySerial.readBytes(response, 20);
   response[rv] = 0;
   Serial.print("Firmware Version: ");
 }  else  {  
   Serial.println("Error checking BT Version");

 while(Serial.available())   Serial.read();
 Serial.println("To modify Baud rate, enter:");  
 Serial.println("  1  for   1200 bps");  
 Serial.println("  2  for   2400 bps");  
 Serial.println("  3  for   4800 bps");  
 Serial.println("  4  for   9600 bps");  
 Serial.println("  5  for  19200 bps");  
 Serial.println("  6  for  38400 bps");  
 Serial.println("  7  for  57600 bps");  
 Serial.println("  0  to Exit\n");
 Serial.print("Selected: ");
 bps = Serial.read();
 if(bps>=48 & bps<=56)  {    // '0' < bps < '8'
   if(bps>48)  {
     mySerial.write("AT+BAUD");           // Set the BAUD
     mySerial.readBytes(response, 2);
     if (strncmp(response, "OK", 2)==0)  {
       rv = mySerial.readBytes(response, 7);
       response[rv] = 0;
       Serial.print("New BAUD setting: ");
     }  else  {
       Serial.println("Error Setting BAUD");
     Serial.println("Bluetooth Setup Completed  ** End **");
   }  else  {
     Serial.println("No modification  ** End **");
 else    Serial.println("non valid entry  ** End **");

void loop() { }

Exit code by pressing "0"

3) for the good sake, confirm that the JY_MCU led changes from blinking to solid red when connecting within Android BT Joystick


Jan 13, 2014, 02:22 am Last Edit: Jan 13, 2014, 02:34 am by billcat Reason: 1
thanks kas for the help! :) ....If I could return the favor in any way...feel free to ask.

1) breadboarded UNO
2)yes, I previously did the BT configuration.  Baudrate is 57600, firmware is limnor(?) 1.8.  I used the openpilot sketch for the configuration if you are familiar.
3) yes the JY-MCU red led goes solid upon connection, I definitely have BT comms working.

since my last post......I have had some success with the led portion.   I am able to turn on and off one led with button1 using the following code snippets.  However, the operation of the green button indicator lights on the phone eludes me.  I would expect the indicator to stay on as long as the ledpin is on, however it just lights briefly after I press the button.  I'm sure this is exactly as the code intends, But I don't understand which portion of the sketch controls this.

I tried blindly playing with this line with no idea what I was doing:
Code: [Select]
buttonStatus &= B0001;  including deleting it altogether, with no obvious affect on the operation.  I can't figure out what action these lines in each of the case blocks perform .

this is the code I modified to some success. Is it reasonable?
Code: [Select]

int b1state=1

switch (buttonStatus) {
   case '1':
     buttonStatus &= B0001;          // Button_1: ON
     if (b1state==1){
     Serial.println("Button_1: ON");  
     digitalWrite(ledPin, HIGH);}
     if (b1state==0){
     Serial.println("Button_1: OFF");
     b1state= 1- b1state;               // toggle led

forgot to mention that I also had to comment out the lines following "case 2" or else it would immediately turn the ledpin back off.

edited for clarity


Jan 13, 2014, 03:47 pm Last Edit: Jan 13, 2014, 03:51 pm by kas Reason: 1
Hi billcat

I finally could reproduce the problem, my fault   :smiley-red:
Please download and run attached sketch (V10.3)

- button #1 controls on board LED (D13)
- button #2 controls debug mode (output to Serial Monitor)
- button #3 and #4 are just configured as push button (momentary contact)

Please let me know the outcome, especially for button #1


Hello kas,
Thanks for the updated sketch, I will try it out when I get a chance, but I wont be able to for a few days.   I will let you know my outcome as soon as I can.

best wishes and thanks again for the cool app.


best wishes and thanks again for the cool app

Thanks billcat
Please let us have your feedback whenever you can


Jan 15, 2014, 06:30 pm Last Edit: Jan 21, 2014, 08:19 am by kas Reason: 1
Great News

I got it working with this URL

Now, let me think out-loud some functionality questions if I may.

1. is it possible to increase the number of buttons ?
2. What data can the controller poll?
can I split it up and show for example

3. Can you increase the video size ?
4. Can you decrease the size of the joystick ? (to conserve space ?)
5. Can you add another option so instead of a joystick it shows 4 arrows to control the bot?
6. Is it possible to include toggle indicators ?

Sorry for all the loud thinking but I'm really exited with this. I was searching for something like this for a long time.
Thanks very much for all you hard work and sharing

OK  ;)

Previous design:

Proposed layout based on your comments:

- 640X480 video stream
- 1 joystick
- 6 buttons (latch or momentary)
- 4 robot parameter displays sent back from Arduino (voltage, heading, rpm, temp ...)

Actually I had to lower the resolution of the camera (320x240) because there was a terrible video lag of about 1 second or so
I don't get any lag with my Xperia Mini configured as an IP camera, check your camera settings, you may have to reduce fps value

Please let me have your comments
Thanks again for your suggestions and your positive feedback  


Boy are you a coding machine. This is perfect.
Lets build on this and see how it works out.
Thanks a million


Please let me know the outcome, especially for button #1

Works perfect!  Thanks for the fix, I am now able to do what I want with the leds I mentioned.  Wish I understood the code fully so that I could modify as needed in the future.

Now I need to address the r/c servo scenario. I will try to figure it out myself first, but will probably end up needing advice on that later.


Go Up