Show Posts
Pages: [1] 2 3
1  Using Arduino / Motors, Mechanics, and Power / TB6612FNG via Bluetooth on: March 25, 2014, 03:33:43 pm
Hi there,i am posting here in Motor Section hoping to get a answer...i have allready ask for help in Bluetooth comunicaction Section but i didn't get the answer...i don't know what to do..please help me
Using KAS Android Bluetooth Joystick aplication i  am triyng to control a RC car,modifying it and hook up a servo for steering (Horizontal Axis) ,and a DC Motor with TB6612FNG (on Vertical Axis) ...so i took the code and modifying it :
I will try to explain it the clear as possible so can everybody understand it:
The Android aplicacion send to the Arduino via HC-06 the Joystick position.
Using this code now the Servo move as it should (Horizontal Axis) ,
The DC Motor (Vertical Axis of joystick) work both directions FWD /BACKWRD, goes to StandBy when the joystick is in middle , BUT it moves very slow....on the Serial Monitor it goes from -255   0  255 exactly how i move the joystick
Code:

#include <Servo.h>

boolean    DEBUG = true;

#define    pinServo_X     9
#define    PWM_Y          3
#define    STX            0x02
#define    ETX            0x03

#define    MAX_Y          255      // PWM limit
#define    ZERO_Y         0        
#define    MIN_Y          -255      

#define AIN1  4  
#define AIN2  5   // AIN1 and AIN2 as Direction pins
#define STBY  7   // StandBy

int i=0;
byte cmd[6] = {0, 0, 0, 0, 0, 0};
Servo myservoX;                    
Servo myY;                 // ???? it is not a servo
byte buttonStatus = 0;              
byte dataByte = 0;                    
long previousMillis = 0;            
boolean setButtonFeedback = false;    
long interval = 1000;                


void setup()  {
  Serial.begin(9600);
  myservoX.attach(pinServo_X);  
  myY.attach(PWM_Y);  

pinMode(AIN1,OUTPUT);
pinMode(AIN2,OUTPUT);
pinMode(PWM_Y,OUTPUT);
pinMode(STBY,OUTPUT);
  
}

void loop() {
  if(Serial.available())  {                   // data received from smartphone
    delay(5);
    cmd[0] =  Serial.read();  
    if(cmd[0] == STX)  {  
      i=1;      
      while(Serial.available())  {
        cmd[i] = Serial.read();
        if(cmd[i] == ETX)  {
          if(i==2 && cmd[1]>48)                break;    // Button data
          if(i==5 && cmd[1]<3 && cmd[3]<3)     break;    // Joystick data
        }
        if(i>5)   break;
        i++;
      }
        if(i==5)   setServoPosition(cmd);                                     // 5 Bytes
      else            Serial.println("Communication error");
    }
  }  else  {
    long currentMillis = millis();
    if(setButtonFeedback == true)  {                      // allow momentary button visual effect (500 ms)
      previousMillis = currentMillis - interval*0.5;  
      setButtonFeedback = false;
    }  
  }
  delay(5);
}

void setServoPosition(byte data[5])    {
  int joyX = (data[1]<<7) + data[2];
  int joyY = (data[3]<<7) + data[4];
  joyX = joyX - 200;                         // Offset to avoid
  joyY = joyY - 200;                         // transmitting negative numbers
  
  joyX = map(joyX, -180, 180, 180, 0);      // (-180/+180 JBC range)
  joyY = map(joyY,  -100, +100, -255, 255);

  joyY+=ZERO_Y;
  joyY = constrain(joyY, MIN_Y, MAX_Y);
  myservoX.write(joyX);
  myY.write(joyY);
  digitalWrite(STBY, HIGH); //disable standby
  if(DEBUG)  {
  //Serial.print(joyX); Serial.print(", ");
  Serial.println(joyY);}


  if(joyY > 0) {
      digitalWrite (AIN1,HIGH);
      digitalWrite (AIN2,LOW);
  } else if(joyY < 0)  {
      digitalWrite (AIN1,LOW);
      digitalWrite (AIN2,HIGH);
  } else if(joyY == 0)  {
      digitalWrite(STBY, LOW); //enable standby

  analogWrite(PWM_Y,joyY);
 }
}


I would reay apreciate if you can help me with the code,Thank you
2  Using Arduino / Networking, Protocols, and Devices / Re: Android Bluetooth joystick on: March 22, 2014, 06:24:39 am
You was right about this ...i just change it
Code:
} else if(joyY == 0)  {         // comparison operator, the way to go
...as for the Stanby  it   is  enabled again :
Code:
 myY.write(joyY);
  digitalWrite(STBY, HIGH); //disable standby   <----

Made some small modification and works (but not how it should) : it only have one speed fwd and backword (very very slow smiley-sad(  ) in the middle get in Standby but it have no speed .On Serial monitor it goes from -255   0  255 ...and i test the motor and it works,
What am i doing rong? I just don't get it,I don't wanna give up this project...shoud i open a new topic and ask for some advice ?
Thank you KAS

3  Using Arduino / Networking, Protocols, and Devices / Re: Android Bluetooth joystick on: March 21, 2014, 03:00:05 pm
Can anyone give me a hand with some errors i have ...
I am trying to run the TB6612FNG on the vertical and a Servo on Horizontal ...so far the code only moves the motor only when you keep moving a little the joystick (i mean if u stay still with the finger on maximum speed i have no movement) :

Code:

#include <Servo.h>

boolean    DEBUG = true;

#define    pinServo_X     9
#define    PWM_Y          3
#define    STX            0x02
#define    ETX            0x03

#define    MAX_Y          255      // PWM limit
#define    ZERO_Y         0         
#define    MIN_Y          -255       

#define AIN1  4   
#define AIN2  5   // AIN1 and AIN2 as Direction pins
#define STBY  7   // StandBy

int i=0;
byte cmd[6] = {0, 0, 0, 0, 0, 0};
Servo myservoX;                     
Servo myY;                 // ???? it is not a servo
byte buttonStatus = 0;             
byte dataByte = 0;                   
long previousMillis = 0;           
boolean setButtonFeedback = false;   
long interval = 1000;                 


void setup()  {
  Serial.begin(9600);
  myservoX.attach(pinServo_X); 
  myY.attach(PWM_Y);   

pinMode(AIN1,OUTPUT);
pinMode(AIN2,OUTPUT);
pinMode(PWM_Y,OUTPUT);
pinMode(STBY,OUTPUT);
 
}

void loop() {
  if(Serial.available())  {                   // data received from smartphone
    delay(5);
    cmd[0] =  Serial.read(); 
    if(cmd[0] == STX)  { 
      i=1;     
      while(Serial.available())  {
        cmd[i] = Serial.read();
        if(cmd[i] == ETX)  {
          if(i==2 && cmd[1]>48)                break;    // Button data
          if(i==5 && cmd[1]<3 && cmd[3]<3)     break;    // Joystick data
        }
        if(i>5)   break;
        i++;
      }
        if(i==5)   setServoPosition(cmd);                                     // 5 Bytes
      else            Serial.println("Communication error");
    }
  }  else  {
    long currentMillis = millis();
    if(setButtonFeedback == true)  {                      // allow momentary button visual effect (500 ms)
      previousMillis = currentMillis - interval*0.5;   
      setButtonFeedback = false;
    } 
  }
  delay(5);
}

void setServoPosition(byte data[5])    {
  int joyX = (data[1]<<7) + data[2];
  int joyY = (data[3]<<7) + data[4];
  joyX = joyX - 200;                         // Offset to avoid
  joyY = joyY - 200;                         // transmitting negative numbers
 
  joyX = map(joyX, -180, 180, 180, 0);      // (-180/+180 JBC range)
  joyY = map(joyY,  -100, +100, -255, 255);

  joyY+=ZERO_Y;
  joyY = constrain(joyY, MIN_Y, MAX_Y);
  myservoX.write(joyX);
  myY.write(joyY);
  digitalWrite(STBY, HIGH); //disable standby
  if(DEBUG)  {
  //Serial.print(joyX); Serial.print(", ");
  Serial.println(joyY);}


  if(joyY > 0) {
      digitalWrite (AIN1,HIGH);
      digitalWrite (AIN2,LOW);
  } else if(joyY < 0)  {
      digitalWrite (AIN1,LOW);
      digitalWrite (AIN2,HIGH);
  } else if(joyY = 0)  {
      digitalWrite(STBY, LOW); //enable standby

  analogWrite(PWM_Y,joyY);
 }
}


I know that i shouldn't use servo library for the Vertical Axis (DC Motor) ....but i don't know how to do it ,i tried to change it with PWM but i got errors...also motor kepp making noise (without moving) when joystick is in the middle posicion
On Serial Monitor i get the right values  :  255 when joystick full up   ----  0 in the middle ---- and -255 when is down
I apreciate your help,thank you,i hope to get this work smiley-wink
4  Using Arduino / Networking, Protocols, and Devices / Re: Android Bluetooth joystick on: March 16, 2014, 03:05:41 pm
this is the code i have modified a little so i can control the speed (on Vertical) of a continuous servo ,and the normal servo on horizontal .... in case someone need it smiley-wink  :

Code:

// Andro_Pan&Tilt      V3.1
// Arduino demo sketch for Joystick BT commander V3.X
// Controls two servo motors

// V3.0: Android BT Commander V3.X compatible, no button data management
// V2.5 can receive both Byte & Integer data
// V2.0: removed SoftwareSerial

// Android BT Commander settings:
// Options/Options for advanced users/Data Range        >>>  -180 to +180
// Options/Options for advanced users/Refresh interval  >>>  25ms

//  Arduino pin #0 to TX BlueTooth module
// BT TX to be disconnected from D0 during sketch upload

#include <Servo.h>

boolean    DEBUG = false;

#define    pinServo_X     9
#define    pinServo_Y     10        //continuous servo
#define    STX            0x02
#define    ETX            0x03
#define    MAX_Y          2000      // max servo speed limit       
#define    ZERO_Y         1500      // middle servo point
#define    MIN_Y          1000      // min servo speed limit
#define    ledPin1        13
#define    ledPin2        12

int i=0;
byte cmd[6] = {0, 0, 0, 0, 0, 0};
Servo myservoX;                       // create servo object
Servo myservoY;
byte buttonStatus = 0;                // first Byte sent to Android device
byte dataByte = 0;                    // second Byte sent to Android device
long previousMillis = 0;              // will store last time Buttons status was updated
boolean setButtonFeedback = false;    // momentary buttons feedback to Android device
long interval = 1000;                 // interval between Buttons status transmission (milliseconds)


void setup()  {
  Serial.begin(9600);
  myservoX.attach(pinServo_X); 
  myservoY.attach(pinServo_Y); 
  pinMode(ledPin1, OUTPUT);     
  pinMode(ledPin2, OUTPUT);   
  if(DEBUG)  Serial.println("Stepper demo for Android BT Commander V3.X");
}

void loop() {
  if(Serial.available())  {                   // data received from smartphone
    delay(5);
    cmd[0] =  Serial.read(); 
    if(cmd[0] == STX)  { 
      i=1;     
      while(Serial.available())  {
        cmd[i] = Serial.read();
        if(cmd[i] == ETX)  {
          if(i==2 && cmd[1]>48)                break;    // Button data
          if(i==5 && cmd[1]<3 && cmd[3]<3)     break;    // Joystick data
        }
        if(i>5)   break;
        i++;
      }
      if     (i==2)   getButtonState(cmd[1]);             // 3 Bytes
      else if(i==5)   setServoPosition(cmd);                                     // 5 Bytes
      else            Serial.println("Communication error");
    }
  }  else  {
    long currentMillis = millis();
    if(setButtonFeedback == true)  {                      // allow momentary button visual effect (500 ms)
      previousMillis = currentMillis - interval*0.5;   
      setButtonFeedback = false;
    } 
  }
  delay(5);
}

void setServoPosition(byte data[5])    {
  int joyX = (data[1]<<7) + data[2];
  int joyY = (data[3]<<7) + data[4];
  joyX = joyX - 200;                     
  joyY = joyY - 200;                       
 
  joyX = map(joyX, -180, 180, 180, 0);      // (-180/+180 JBC range)
  joyY = map(joyY,  0, 423, 0, 1023);       // vertical continuous servo value

  joyY+=ZERO_Y;
  joyY = constrain(joyY, MIN_Y, MAX_Y);
  myservoX.write(joyX);
  myservoY.write(joyY);
  if(DEBUG)  {
  Serial.print(joyX); Serial.print(", ");Serial.println(joyY);}
}

void getButtonState(int bStatus)  {
  switch (bStatus) {
    case '1':
      buttonStatus |= B0001;        // Button_1: ON
      Serial.println("Button_1: ON");
      digitalWrite(ledPin1, HIGH);   // LED 1 "ON"
      break;
    case '2':
      buttonStatus &= B1110;        // Button_1: OFF
      Serial.println("Button_1: OFF");
      // your code...     
      digitalWrite(ledPin1, LOW);    // LED 1 "OFF"
      break;
     
    case '3':
      buttonStatus |= B0010;        // Button_2: ON
      DEBUG = true;
      digitalWrite(ledPin2, HIGH);   // LED 2 "ON"   
      break;
     
    case '4':
      buttonStatus &= B1101;        // Button_2: OFF
      DEBUG = false;
      Serial.println("Button_2: OFF");
      digitalWrite(ledPin2, LOW);     
      break;
  }
}
... now i am working on the hard part...control a DC motor on the vertical axis with the TB6612FNG with the PWM
                                          i will need some help
5  Using Arduino / Networking, Protocols, and Devices / Re: Android Bluetooth joystick on: March 13, 2014, 12:19:22 pm
Great job KAS , i test again and you was right,your app works great with Android 2.3.5,and the HC-06 also compatible (bad thing is i don't recive any data,i can only send) smiley-grin:D    so...
Based on your replay at post #146 i am trying to modify the arduino code with your permision,so that on vertical move a DC Motor, and the orizontal a Servo (for steering)...
 the joyY control Vertical joystick movement    ,and "joyX" the horizontal right ?
I will post the code as soon i will get it work ... Thank you ,Congratulations again for the app,Karma up smiley-wink

6  Using Arduino / Networking, Protocols, and Devices / Re: Android Bluetooth joystick on: January 27, 2014, 01:09:24 pm
Hello Kas,these days i've been diggin more about bluetooth arduino comunicancion and this is what i found:
 JY-MCU HC 06 is compatible with android comunicacion (running ArduDroid app,it works flawlesly,i can control all pins on board Digital,PWM,and Analog) with my phone(HTC Wildfire S).But refuse to pair your app...so i tried to run it from another phone (Samsung S3) and yes it pairs just like u said...so i belive the BT Joystick app is not compatible with Android 2.3.5 smiley-sad( ....even so...if i had BT connection i couldn't get any movement ,joystick or Leds...i tried default config and changing parameters with no result
Could you post the first versions of the Bluetooth Joystick Aplicacion so i can trie it out? thank you for you help
7  Using Arduino / Networking, Protocols, and Devices / Re: Android Bluetooth joystick on: January 24, 2014, 11:43:37 am
i just recived my JY-MCU V1.06 but i can't figure out how to pair it with the phone...I load the sketch (with the TX,RX pin disconected) search it with the phone pair it (1234) then open the app and it say Unable to connect device" , and Led wont get solid
I guess it is not compatible with the V1.06 smiley-sad ....any ideeas

..i tried all the codes you post..even that one that only control 2 servo ...thx
8  Using Arduino / Networking, Protocols, and Devices / Re: Android Bluetooth joystick on: January 19, 2014, 03:46:29 pm
This is looking better and better Kas, i belive you should go for the app,i am shore more than one would want a app like this,that can control a rc car toy with video ...with your phone.I am going to trie it soon,for the moment i am wayting the bluetooth JY MCU HC6 (hope its compatible)..
My ideea is to fit the Arduino and the JY-MCU with one servo for steering,one TB6612FNG motor driver,and cuple Leds,and a buzzer
If all this will work properly i will try out the camera funcion,so one again,im telling you,this app will have succes,you should look at how many visit this post had.Nice job..Thank you smiley-wink
9  Using Arduino / Networking, Protocols, and Devices / Re: Android Bluetooth joystick on: January 05, 2014, 05:54:00 am
Great app KAS, bad thing is not working on IOIO board,just tested out smiley-sad ,do u think in a future could make one to be IOIO otg compatible?...once again ,this app is the best,on Google Store smiley-wink Thank you
10  Using Arduino / Sensors / Re: capacitive switch variable on: February 13, 2013, 06:00:52 am
Yupii smiley-grin:D thank you so much Johnwasser and Robtillaart ...code works great,i've been with this problem for a long time,i was getting a conflict because of the library,but with your help it is solved.Thank you again guys for help smiley-wink
                                                                                                                                                                  Juycce
11  Using Arduino / Sensors / capacitive switch variable on: February 12, 2013, 05:22:01 am
hi there everyone...i need your help with a capacity code.What im trying to do is a toggle switch(when i touch the foil led turn HIGH,when i touch again led turn LOW).the code i have is this one,but i don't know how to add the variable where to store the led status,so it can change every time i touch the foil.
Code:
#include <CapSense.h>

CapSense   cs_4_2 = CapSense(4,2);         // 10 megohm resistor between pins 4 & 2, pin 2 is sensor pin, add Bare Paint
int ledPin1 = 13;

void setup()                
{
   cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example  
   Serial.begin(9600);
}

void loop()                    
{    
    long start = millis();    
    long total1 =  cs_4_2.capSense(30);  
 
    if (total1 > 1100) {
      digitalWrite(ledPin1, HIGH);  // turn LED ON
      
    } else{
      digitalWrite(ledPin1, LOW);  // turn LED OFF
 }

Serial.println(total1);                                

delay(100);                                          // arbitrary delay to limit data to serial port
}

thank you so much for help...  smiley
12  Topics / Home Automation and Networked Objects / Re: Room control on: February 12, 2013, 05:05:49 am
you should take your project on parts.You can conect a 5v relay(i have some from ebay) if you will not exeed 1000w,in their datasheet those relay handless up to 10Amps AC(but i''m not that shore),so with the formula  Amp x V = Watts,theoreticly it should handle 2200W...now u cannot conect a big fan,like u want....for that u need to conect a second relay to the first relay(like a biger one 12V)
As for the fan regulator the easyest way i think is a servo....Bluetooth is great for that but is a lot of coding.Good luck Niner
13  Topics / Home Automation and Networked Objects / Re: Auto door unlock on: February 05, 2013, 06:27:38 pm
im not saying is easy,the bad part is all this rfid works on 125khz,i simply prefer other protocols of identificacion...like Viper does  smiley-yell..good luck binfazen
14  Topics / Home Automation and Networked Objects / Re: Auto door unlock on: February 05, 2013, 06:14:17 pm
the ID20 have the biggest antena of his rfid class..the bad part is that the range is not so big.You can buy the ID-02 that have no antena and buil one yourself,getting longer range,but that depend of your electronic skill.Wireing is easy 2 digital pins,5v and Gnd(careful with soldering the pins,the aligniment of pins doesn't fit on the usualy breadboard).The identificacion rfid tag comes in button,card,glass capsule..the bigger it is,the larger is the range.It is a great project,but it's not fit for me...since is quite easy to hack it
..anyway check out:           http://www.instructables.com/id/Arduino-RFID-Door-Lock/
15  Topics / Home Automation and Networked Objects / Re: Auto door unlock on: February 05, 2013, 03:38:26 pm
you could use radio frequency like ID20(it has about 5 cm ~ range),and the Arduino conected to the relay smiley-wink
Pages: [1] 2 3