Go Down

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

kas

Quote
Thanks, but no luck.  The CarMoniter app automatically finds the video signal when the phone is connected to the cameras WiFi router.
Total Rc Commander seems to need an ip address and port but I have no way of knowing that.
Please confirm that  nothing   was entered in CarMoniter (user, password...), to obtain a video connection

AntonioLopez

Thanks Kas and Woody,

I'll be posting a new video later today, showing the sequence of events to make sure that isn't my problem.

I appreciate your help............Thanks..........Antonio

woodygb

#392
Dec 14, 2014, 04:43 pm Last Edit: Dec 14, 2014, 08:43 pm by woodygb Reason: additional info
Please confirm that  nothing   was entered in CarMoniter (user, password...), to obtain a video connection
Kas ..here's a transcript of the conversion.

Quote
Hi Pat,

I've also been asked to confirm that once the Wifi  connection has been setup on the phone ...all you do is start the App and bingo a video appears?.

I assume that the Car monitor's WiFi shows up on the Android phone under Settings -WiFi- with the name GLW-CAR-R and simply requires a password to connect ?  
 
Note that we are asking questions blind and making assumptions ...so feel free to say "no no"  that's not how it works.... AND STEP ME THRU THE PROCESS.

Any chance of a scan of the relevant page from the manual?

Woody
Quote
Yes thats correct. If you start the app before you connect to WiFi, you have an option to choose "Normal" or "High" video quality.  But if the phone, Samsung Galaxy Note 4 in my case, is already connected to the WiFi, which is GLW-CAR-R0000795, then when you open the CarMoniter App, the video just starts automatically full screen like a backup moniter.  There are no options within the app for any setup
Hope this helps.

Woody


EDIT :- This seems to be the installation manual for the same backup camera but for a different supplier.

medias.pearl.fr/technique/notice/PX3745.pdf

woodygb

Thanks Kas and Woody,

I'll be posting a new video later today, showing the sequence of events to make sure that isn't my problem.

I appreciate your help............Thanks..........Antonio
The communication TO the Android phone ( TX of Arduino to RX of Blue Tooth ) seems fine.

The problem appears to be one of Blue Tooth communication FROM the Android phone to the Arduino ( TX of Blue Tooth to RX of Arduino ).


This could just be a bad connection or wire as indicated by Kas ... or it's remotely possible that it is the UNO's pin... or a damaged Blue Tooth module.

woodygb

#394
Dec 14, 2014, 09:09 pm Last Edit: Dec 14, 2014, 11:14 pm by woodygb
Thanks Kas and Woody,

I'll be posting a new video later today, showing the sequence of events to make sure that isn't my problem.

I appreciate your help............Thanks..........Antonio
Here's a screen shot of the pot outputs after I've integrated the stepper App into the BT Commander.
The first column after the PotValA & B  swing from 0 - 2047 with 1023 as the center using the BT Joystick as an input.


AntonioLopez

Hi Woody, and Kass,

Wow, great work Woddy, that screen shot is amazing and proof that everything I'm doing is doing absolutely nothing.


Here's another short video showing you my sequence of events.

https://www.youtube.com/watch?v=JVjXsk76gw4&feature=youtu.be


I don't want to take up any more of your and Kass's time, so at this point, how do you feel about fixing this problem and I can pay you through Paypal, hopefully this isn't frowned upon on this site. 

I'm pretty burned out, this is the second bluetooth module that I've tried, and I've been to what seems a thousand - how to sites, so I  don't know what to say, except that I want to move forward.

Here's the code that I've been using with the potentiometer and the small stepper.
Code: [Select]
/*------------------------------------------------------
StepperPot_11
Arduining.com 13 APRIL 2013

A stepper motor follows a potentiometer on analog input 5.
A software low-pass filter is used to reduce the noise in the analog reading.
After 3 seconds of inactivity the motor coils are turned OFF to save energy.
The RED_LED is used to signal when the stepper is powered.

Hardware:
LaunchPad with MSP430G2553.
Driver: ULN2003A
Stepper Motor:  28BYJ48, 5VDC, step pangle 5.625 °
                Gear reduction 64:1
                No-load starting frequency:> = 500PPS (4 rpm)
                Coil resistance 60 Ohms.               
 -----------------------------------------------------*/

#include <Stepper.h>

// change this to the number of steps on your motor
#define  STEPSREV    2047    // 64(fullsteps) * 64 (reduction ratio)
#define  COIL1       11
#define  COIL2       9
#define  COIL3       10
#define  COIL4       8
#define  POT         0
#define  ENER        13
#define  TIMEOUT     3000    //Turns off after 3 secs of inactivity.

// create an instance of the stepper class, specifying
// the number of steps per revolution and pins atached to motor coils.
Stepper myStepper(STEPSREV, COIL1, COIL2, COIL3, COIL4);
int PotVal;
int LastPotVal= 0 ;          // To implement a software Low-Pass-Filter
int pos = 0;              // stepper position(0-4096)->(0-360°)
unsigned long stamp = 0;  // last move time stamped.

void setup()
{
  myStepper.setSpeed(4);  // set the motor speed to 4 RPM
  pinMode(ENER, OUTPUT);  // status led (coils energized).
//  Serial.begin(9600);   //for debuging.
}

void loop(){

  PotVal = analogRead(POT);       // Potentiometer value range 0-1023

  PotVal= map(PotVal,0,1023,0,2047);      // Map pot range in the stepper range.
  PotVal= PotVal * 0.1 + LastPotVal * 0.9 ;  // Filtering to reduce noise.
  LastPotVal= PotVal;

//  Serial.print(Val);              // For debuging.
//  Serial.print("   ");            //    "
//  Serial.println(pos);            //    "
//  delay(500);                     //    " 

  if(abs(PotVal - pos)> 4){              //if diference is greater than 4 steps.
      if((PotVal - pos)> 0){
          digitalWrite(ENER, HIGH);   //Motor energized.     
          myStepper.step(1);           // move one step to the right.
          pos++;
          }
      if((PotVal - pos)< 0){
          digitalWrite(ENER, HIGH);   //Motor energized.
          myStepper.step(-1);            // move one step to the left.
          pos--;
          }
      stamp = millis();               // stamp actual time.
      }
  else {     
      if((millis() - stamp) > TIMEOUT){   //Turn Off coils after TIMEOUT.
          digitalWrite(COIL1, LOW);
          digitalWrite(COIL2, LOW);
          digitalWrite(COIL3, LOW);
          digitalWrite(COIL4, LOW);
          digitalWrite(ENER, LOW);    //Motor de-energized.
          }   
      }

}


Thanks to the both of you again............Antonio

kas

Antonio,

For the moment
  Android >> Arduino   not OK
  Arduino >> Android   OK

Joystick BT Commander V4.x would create this exact situation 
Just to make sure, uninstall the App and reload from Google Play

woodygb

Quote
I don't want to take up any more of your and Kass's time, so at this point, how do you feel about fixing this problem and I can pay you through Paypal, hopefully this isn't frowned upon on this site. 

I'm pretty burned out, this is the second bluetooth module that I've tried, and I've been to what seems a thousand - how to sites, so I  don't know what to say, except that I want to move forward.
I could easily program a pro mini and post it to you... BUT ..the fix is likely to be simple if you persevere with the guidance being provided.

Follow Kas's advice ...uninstall BT Commander from your phone & download the latest version of the App



If your interested in knowing what version of Kas's software your currently running go to the screen line that pops up at the bottom of the App with  Connect  Options  reset Opt  About and press About.

Mine says Joystick BT Commander V5.2

AntonioLopez

Hi Guys, and once again thanks for your help.


I reinstalled Commander to make sure and I do have V5.2 installed, problem is the same.

Later on today I'll setup the HC5 to see what happens, I didn't want to setup a voltage divider, that's why I bought an HC6.



 Woody, what do you mean, program a pro mini?

Thanks...........Antonio

woodygb

#399
Dec 15, 2014, 09:24 pm Last Edit: Dec 15, 2014, 09:39 pm by woodygb
http://arduino.cc/en/Main/ArduinoBoardProMini




I'm fairly confident ... seeing as how you have managed to reprogram it ...that your Blue Tooth is working fine.

So....


I'm going to suggest that you move the connection from pin2 of the UNO to pin4

The SoftwareSerial mySerial(2,3);  in the program code will become SoftwareSerial mySerial(4,3);




kas

#400
Dec 15, 2014, 10:53 pm Last Edit: Dec 15, 2014, 11:01 pm by kas
You may try this bare minimum sketch to test incoming data from your smartphone

Code: [Select]

#include "SoftwareSerial.h"

#define txPin 3
#define rxPin 2

SoftwareSerial mySerial(rxPin,txPin);

void setup()  {
  mySerial.begin(57600);
  Serial.begin(57600);
  Serial.println("Test Soft_Serial");
}

void loop() {
  if(mySerial.available())    Serial.print(mySerial.read());  
}


Bytes received by the Bluetooth card will be echoed to the Arduino Serial Monitor
Upload sketch, start and connect Joystick BT Commander

Should display series of numbers:
250545050525332505450505253325054505052533250545050525332505450505253325054505052533 ..................


As suggested by Woody, try changing rxPin to #4



Quote
how do you feel about fixing this problem and I can pay you through Paypal, hopefully this isn't frowned upon on this site
Please discuss this point via PM's.  Personally not interested   ;)


AntonioLopez

Hi Kas and Woody,

Kas, I just say your latest post, I try that code in a bit, meanwhile it take a look at my video.

https://www.youtube.com/watch?v=XWZ_Co76doM

It does seem to be working.


Woody, how do I contact you PM?

AntonioLopez

Kas,

I just tried your code and the Commander is sending data to the arduino, GREAT, THANKS.

woodygb

#403
Dec 16, 2014, 12:35 am Last Edit: Dec 16, 2014, 12:37 am by woodygb
click on my user name or avatar

page opens

bottom left

click on send PM

woodygb

#404
Dec 16, 2014, 01:03 am Last Edit: Dec 16, 2014, 01:13 am by woodygb
Code is in 2 lumps as the forum complained about it's size.
2nd lump on next page.

Code: [Select]

#define VERSION     "\n\nAndroTest V2.0 - @kas2014\ndemo for V5.x App"
#include "SoftwareSerial.h"
#include <Stepper.h>

#define rxPin 2
#define txPin 3

// change this to the number of steps on your motor
#define  STEPSREV    2047    // 64(fullsteps) * 64 (reduction ratio)= 4096

#define  COIL1_A    11
#define  COIL2_A     9
#define  COIL3_A    10
#define  COIL4_A     8

#define  COIL1_B    4 // ???  PIN NUMBERS GUESSED
#define  COIL2_B    5
#define  COIL3_B    6
#define  COIL4_B    7

#define  ENER_A       13       //Motor A Status led
//#define  ENER_B       ?     //Motor B Status led do you wish a seperate one?

#define  TIMEOUT     3000    //Turns off after 3 secs of inactivity.

// create an instance of the stepper class, specifying
// the number of steps per revolution and pins atached to motor coils.
Stepper myStepperA(STEPSREV, COIL1_A, COIL2_A, COIL3_A, COIL4_A);
Stepper myStepperB(STEPSREV, COIL1_B, COIL2_B, COIL3_B, COIL4_B);
int PotValA;
int PotValB;
int pos_A = 1024;              // stepper A position(0-4096)->(0-360°) CENTERED
int pos_B = 1024;              // stepper B position (0-4096)->(0-360°)CENTERED
unsigned long stamp_A = 0;  // last A move time stamped.
unsigned long stamp_B = 0;  // last B move time stamped.
#define    STX          0x02
#define    ETX          0x03
//#define    ledPin       13
#define    SLOW         750                            // Datafields refresh rate (ms)
#define    FAST         250                             // Datafields refresh rate (ms)

SoftwareSerial mySerial(rxPin,txPin);  // BlueTooth module: pin#2=TX  pin#3=RX
byte cmd[8] = {
  0, 0, 0, 0, 0, 0, 0, 0};                 // bytes received
byte buttonStatus = 0;                                  // first Byte sent to Android device
long previousMillis = 0;                                // will store last time Buttons status was updated
long sendInterval = SLOW;                               // interval between Buttons status transmission (milliseconds)
String displayStatus = "xxxx";                          // message to Android device

void setup()  {
  Serial.begin(57600);
  mySerial.begin(57600);   // 57600 = max value for softserial
  pinMode(txPin, OUTPUT);
  pinMode(rxPin, INPUT);
  myStepperA.setSpeed(4);  // set the motor speed to 4 RPM
  myStepperB.setSpeed(4);  // set the motor speed to 4 RPM
  pinMode(ENER_A , OUTPUT);
  //  pinMode(ENER_B , OUTPUT);   
  Serial.println(VERSION);
  while(mySerial.available())  mySerial.read();         // empty RX buffer
}

void loop() {
  if(mySerial.available())  {                           // data received from smartphone
    delay(2);
    cmd[0] =  mySerial.read(); 
    if(cmd[0] == STX)  {
      int i=1;     
      while(mySerial.available())  {
        delay(1);
        cmd[i] = mySerial.read();
        if(cmd[i]>127 || i>7)                 break;     // Communication error
        if((cmd[i]==ETX) && (i==2 || i==7))   break;     // Button or Joystick data
        i++;
      }
      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 >
    }

    if(abs(PotValA - pos_A)> 4){  //if diference is greater than 4 steps.
      if((PotValA - pos_A)> 0){
        digitalWrite(ENER_A, HIGH);   //Motor ENER_Agized.     
        myStepperA.step(1);    // move one step to the right.
        pos_A++;
      }
      if((PotValA - pos_A)< 0){
        digitalWrite(ENER_A, HIGH);   //Motor ENER_Agized.
        myStepperA.step(-1);    // move one step to the left.
        pos_A--;
      }
      stamp_A = millis();  // stamp actual time. 
    }

    if(abs(PotValB - pos_B)> 4){ //if diference is greater than 4 steps.
      if((PotValB - pos_B)> 0){
        digitalWrite(ENER_A, HIGH);  //Motor ENER_Agized. ********   ENER_A led used ...change to ENER_B if required and define another led number
        myStepperB.step(1);  // move one step to the right.
        pos_B++;
      }
      if((PotValB - pos_B)< 0){
        digitalWrite(ENER_A, HIGH);   //Motor ENER_Agized.********  ENER_A led used ...change to ENER_B if required and define another led number
        myStepperB.step(-1);  // move one step to the left.
        pos_B--;
      }
      stamp_B = millis(); // stamp actual time.
    }
    else {     
      if((millis() - stamp_A) > TIMEOUT){   //Turn Off coils after TIMEOUT.
        digitalWrite(COIL1_A, LOW);
        digitalWrite(COIL2_A, LOW);
        digitalWrite(COIL3_A, LOW);
        digitalWrite(COIL4_A, LOW);
        digitalWrite(ENER_A, LOW); //Motor de-ENER_Agized.

        if((millis() - stamp_B) > TIMEOUT)//Turn Off coils after TIMEOUT.
          digitalWrite(COIL1_B, LOW);
        digitalWrite(COIL2_B, LOW);
        digitalWrite(COIL3_B, LOW);
        digitalWrite(COIL4_B, LOW);
        digitalWrite(ENER_A, LOW);//Motor de-ENER_Agized.Motor *********   ENER_A led used ...change to ENER_B if required and define another led number
      }

    }
  }

  sendBlueToothData();
}

void sendBlueToothData()  {
  static long previousMillis = 0;                             
  long currentMillis = millis();
  if(currentMillis - previousMillis > sendInterval) {   // send data back to smartphone
    previousMillis = currentMillis;

    // Data frame transmitted back from Arduino to Android device:
    // < 0X02   Buttons state   0X01   DataField#1   0x04   DataField#2   0x05   DataField#3    0x03 > 
    // < 0X02      "01011"      0X01     "120.00"    0x04     "-4500"     0x05  "Motor enabled" 0x03 >    // example

    mySerial.print((char)STX);                                             // Start of Transmission
    mySerial.print(getButtonStatusString()); 
    mySerial.print((char)0x1);   // buttons status feedback
    mySerial.print(GetdataInt1());           
    mySerial.print((char)0x4);   // datafield #1
    mySerial.print(GetdataFloat2());         
    mySerial.print((char)0x5);   // datafield #2
    mySerial.print(displayStatus);                                         // datafield #3
    mySerial.print((char)ETX);                                             // End of Transmission
  } 
}

String getButtonStatusString()  {
  String bStatus = "";
  for(int i=0; i<6; i++)  {
    if(buttonStatus & (B100000 >>i))      bStatus += "1";
    else                                  bStatus += "0";
  }
  return bStatus;
}

int GetdataInt1()  {   // Data dummy values sent to Android device for demo purpos_Ae
  static int i= -30;  // Replace with your own code
  i ++;
  if(i >0)    i = -30;
  return i; 
}

float GetdataFloat2()  { // Data dummy values sent to Android device for demo purpos_Ae
  static float i=50; // Replace with your own code
  i-=.5;
  if(i <-50)    i = 50;
  return i; 
}

void getJoystickState(byte data[8])    {
  int joyX = (data[1]-48)*100 + (data[2]-48)*10 + (data[3]-48);       // obtain the Int from the ASCII representation
  int joyY = (data[4]-48)*100 + (data[5]-48)*10 + (data[6]-48);
  joyX = joyX - 200;                                                  // Offset to avoid
  joyY = joyY - 200;                                                  // transmitting negative numbers

  if(joyX<-100 || joyX>100 || joyY<-100 || joyY>100)       return;   // commmunication error

  PotValA =  map (joyX,-100,100,0,2047);//  Map joyX range in the stepper range motor 1
  PotValB =  map (joyY,-100,100,0,2047);//  Map joyY  range in the stepper range motor 2



  Serial.print("PotValA");
  Serial.print("  :  ");
  Serial.print(PotValA);         
  Serial.print("  :  "); 
  Serial.print("pos_A");
  Serial.print("  :  ");
  Serial.print(pos_A);   
  Serial.print("  :  ");
  Serial.print("PotValB");
  Serial.print("  :  ");
  Serial.print(PotValB);
  Serial.print("  :  "); 
  Serial.print("pos_B");
  Serial.print("  :  ");
  Serial.println(pos_B);       
}



Go Up