Show Posts
Pages: 1 ... 13 14 [15] 16 17 ... 197
211  Using Arduino / Project Guidance / Re: Creating a bluetooth controller on: March 10, 2014, 09:01:41 pm
SOP(Start of Packet) and EOP(End of Packet) are defined at the top of the code as
Quote
#define SOP '<'
#define EOP '>'

So wherever SOP or EOP are, they get substituted with < or >. The data you need to send in, needs to be formated as such

Example: <123,45,6789>
<1,12345,67,89>
<1,2,3,4,5>

Whatever you send in, will be converted to an integer. You can only enter a value within a range from -32,768 to 32,767, unless coded otherwise.

There is another way to do this without needing to convert anything, and that is with using a structure.

Example:
typedef struct someData
{
  int A;
  long B;
  char C;
  boolean D;
} myData;

You would gather the data then send out a refference to someData. This method is better code wise, but from a test that I did using virtualwire, it wasn't really any faster. I will do more tests on it, but I for right not, you can use what I gave you.

Another thing,  if you know exactly how much data your sending, you can change the 5 in "for(byte i = 0; i < 5; i++)" to however many you want to see back. So if you send 3 ints, you dont need to see 5 values, two of which are zero.
212  Using Arduino / Project Guidance / Re: Help with password on: March 08, 2014, 03:29:24 pm
Well your password sketch does compile, so that's good, but now the issues is, you didn't make it, so you don't really know how it works or how to add in the things you need.

Quote
the whole system is to control the +VCC on ping sensor " ON-OFF Control " i ll attach the VCC pin of the sensor instead off the ledPin as my sensor needs 5v
This can be done but the digital pins can only supply so much current, so you might need to get some NPN transistors or even some opto-couplers in order to control the power to the sensors, if they are not going directly to the 5V line.

Quote
is it possible to make another password to turn it off i mean when i enter 4321 it turns on when i press 5678 turn off ????
Yes it is possible to have multiple passwords. This link HERE is to another post with the same question. Look at reply #21 for a working code. NOTE: that sketch uses 3 passwords.

As for your ping sensors, you may want to download the NewPing library, as it is faster and more precise.
213  Using Arduino / Project Guidance / Re: Creating a bluetooth controller on: March 07, 2014, 03:38:15 pm
Buffer sorting example.
Code:
#define SOP '<'
#define EOP '>'

byte idx = 0, N_idx = 0;
boolean convert = false;
char c = NULL;
char * T_holder;
int * tmp = NULL;

#define MAXSIZE 20
char Data[ MAXSIZE ];
int buffer[MAXSIZE];

void setup()
{
  Serial.begin(115200);       
}

void loop()
{
  tmp = getData(); // call the function to collect the incoming data and return a pointer to the collected data
  if(tmp) // make sure something is in there
  {
    for(byte i = 0; i < 5; i++)
      Serial.println(tmp [ i ]);
  }
}

int * getData()
{
  if( Serial.available() > 0)       // if data is available to read
  {
    c = Serial.read(); // read in the first character
    if(c == SOP) // compare that character to <
    {
      idx = 0;
      while( true ) // if the first char equals <, then collect the rest.
      {
        if( Serial.available() > 0) // this is needed again to make sure no junk is collected
        {
          c = Serial.read(); // read in the new chars

          if(c == EOP) // compare char to >
          {
            Data[ idx + 1 ] = EOP; // if char is equal to > then add it to the end of the packet
            convert = true; // tell the code to convert the chars to useable ints
            break; // break out of while loop
          }
          else // if char is NOT equal to >, continue to store them.
          {
            Data[ idx ] = c; // store new char in Data array
          }

          if(idx < MAXSIZE) // check to see the number of incoming chars does not exceed the set maximum
          {
            idx++; // number of char did not exceed the maximum chars allowed
          }
          else
          {
            Serial.println("Input data has exceeded the maximum data allowed.");
            break;
          }
        }
      }
     
      if(convert == true)
      {
        clearBuffer(); // make sure the buffer is clean before adding to it

        T_holder = strtok(Data, ", EOP");// read the first data index, and store it in a temporary pointer
        buffer[ N_idx ] = atoi(T_holder); // convert the pointer to an integer, and store into an index in buffer

        while(T_holder != NULL) // convert the rest of the data until no more data can be read
        {
          N_idx++; // increment new index for next converted data
          T_holder = strtok(NULL, ",>"); // search the data array for a comma, and >
          buffer[ N_idx ] = atoi(T_holder);
        }
        convert = false;
        return buffer; // when all data is converted, return it.
      }
    }
    else Serial.println("Incoming data must be formated as < ... >"); // if the first char is not <, then display error message.
  }
}

void clearBuffer()
{
  while(N_idx !=0)
  {
    buffer[N_idx] = 0; // cleans the buffer for new data.
    N_idx--;
  }
}
214  Using Arduino / Project Guidance / Re: Creating a bluetooth controller on: March 07, 2014, 02:42:20 pm
Ok, thankfully I keep all my older sketches.
This code is not using bluetooth, but the only thing that would need to change is how the incoming data is stored into the buf[ ] array.

Most accelerometers are 3 axis, so they send out x,y, and z data. This code is designed to read in a string of data composed of x,y,z and a state/option. This option is what im using to control my gripper claw, but it can be used to toggle between motion and autonomous control.

Code:
/*
  simple control test
*/
 
#include <VirtualWire.h>
int DRV1,DRV2,STRR,STRL;

int x = 0;
int y = 0;
int z = 0;
int s = 0;
char c[30];

int ledpin = 13;
byte Mopen = 4;
byte Mclosed = 2;
byte M1L = 3;// PWM
byte M2L = 5;// PWM
byte M1R = 11;// PWM
byte M2R = 6;// PWM
// LED connected to pin 13 (on-board LED)

void setup()
{
  pinMode(ledpin, OUTPUT);  // pin 13 (on-board LED) as OUTPUT
  pinMode(Mopen, OUTPUT);                               
  pinMode(Mclosed, OUTPUT);
  pinMode(M1L, OUTPUT);                               
  pinMode(M1R, OUTPUT);
  pinMode(M2L, OUTPUT);                               
  pinMode(M2R, OUTPUT);
  Serial.begin(9600);       // start serial communication at 115200bps
 
  vw_setup(2000); // Bits per sec
  vw_set_rx_pin(8);
  vw_rx_start();
}

void loop() {
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

   if (vw_get_message(buf, &buflen)) // Non-blocking
   {
     int i;
     // Message with a good checksum received, dump it.
Serial.print("Got: ");

for (i = 0; i < buflen; i++){
           digitalWrite(ledpin, HIGH);
           c[i] = buf[i];
         }
         
        x=atoi(strtok(c,","));
        y=atoi(strtok(NULL,","));
        z=atoi(strtok(NULL,","));
        s=atoi(strtok(NULL," "));
       /* Serial.print(x);
        Serial.print(",");
        Serial.print(y);
        Serial.print(",");
        Serial.print(z);
        Serial.print(",");
        Serial.print(s);
        Serial.println();*/
        move(z, y, s); 
   }
}
   
  void move(int z, int y, int s)
  { 

  //Movement varibles
 
  int DRV2 = map(z, 0, 9, 255, 0);
  int DRV1 = map(z, 10, 20, 0, 255);
  int STRL = map(y, 0, 9, 255, 0);
  int STRR = map(y, 10, 20, 0, 255);
 
  /*
  Serial.println(DRV1);
  Serial.print(",");
  Serial.print(DRV2);
  Serial.print(",");
  Serial.print(STRL);
  Serial.print(",");
  Serial.print(STRR);
  Serial.println();
  */
  if(z > 10)//forwards               
  {
    //Serial.println("Forward with turning");
    analogWrite(M1L, constrain(abs(DRV1 - STRL),0,255)); analogWrite(M1R, constrain(abs(DRV1 - STRR),0,255));   
    digitalWrite(M2L, LOW); digitalWrite(M2R, LOW);   
  }
  else if(z < 9)//backwards               
  {
    //Serial.println("Reverse with turning");
    digitalWrite(M1L, LOW); digitalWrite(M1R, LOW);   
    analogWrite(M2L, constrain(abs(DRV2 - STRL),0,255)); analogWrite(M2R, constrain(abs(DRV2 - STRR),0,255));   
  }
   else if(z < 14 && z > 6 && y > 10)//Right               
  {
    //Serial.println("360 left");
    digitalWrite(M2L, LOW); analogWrite(M2R, STRR);   
    analogWrite(M1L, STRR); digitalWrite(M1R, LOW);
  }
  else if(z < 14 && z > 6 && y < 9)//Left             
  {
     //Serial.println("360 right");
    analogWrite(M2L, STRL); digitalWrite(M2R, LOW);   
    digitalWrite(M1L, LOW); analogWrite(M1R, STRL);   
  }

  else //full stop
  {
    digitalWrite(M1L, LOW); digitalWrite(M1R, LOW);       
    digitalWrite(M2L, LOW); digitalWrite(M2R, LOW);   
  }

   if(s == 1)
    {
      Serial.println("Claw Opening");
      digitalWrite(Mopen, HIGH); digitalWrite(Mclosed, LOW);
    }
    if(s == 2)
    {
      Serial.println("Claw Closing");
      digitalWrite(Mopen, LOW); digitalWrite(Mclosed, HIGH);
    }
    if(s == 0)
    {
      digitalWrite(Mopen, LOW);  digitalWrite(Mclosed, LOW);
    }
   else{
    digitalWrite(ledpin, LOW);
    x=0; y=0; z=0; s=0;
  }
}
215  Using Arduino / Project Guidance / Re: Creating a bluetooth controller on: March 07, 2014, 12:48:23 pm
Let me ask you this, how do you want to control it? Do you want to send single characters ('W', 'S', 'A', 'D') or a string of accelerometer data ( -20 ... 20, -20 ... 20) -> (forward/reverse, left/right)?

216  Using Arduino / Project Guidance / Re: Creating a bluetooth controller on: March 07, 2014, 11:49:12 am
I just took a look at your code, and I'm not surprised it doesn't respond. You have so many delays and a while loop that is unneeded. I see your using the meetandroid library too, I personally don't really like that library. So if you want, I will show you how to fix your library so that it responds much better. But first you need to learn about the Blink without delay example sketch because that's is what will help your code a lot.
217  Using Arduino / Project Guidance / Re: Creating a bluetooth controller on: March 07, 2014, 02:32:14 am
Could you post the robots code, I'm curious as to what it looks like.
218  Using Arduino / Project Guidance / Re: Creating a bluetooth controller on: March 06, 2014, 11:58:23 pm
I have four bluetooth modules, two are HC-05, and the other 06(which ones were which, I dont remember), which I took the time to test and see how they work and how far they can go before cutting out.

The far wall of my bedroom to my front door is 37.2ft, in which I wanted to know how far I could be and still have them pair up. I found out that they can still find each other, pair up at 34 - 36 ft, but given my house is mesh lined, I thought the number would vary. Turns out, not by much. I tested the paring range again outside and roughly at 40ft they could just barely pair up. (They would pair up for a few seconds then lose connection)

As I said, yes they can be difficult to set up if you're doing it for the first time, but once you get a hang of it, its simple plug and play. At least with the modules I have. They are all currently set to the default setting, 9600, no parity bit...etc. Yet, I can throw together a simple Serial sketch to send one char from one arduino to the other and see it on the serial monitor.

A V1.2 will not pair with a V1.02 nor to a V1.05, but two V1.05 will. So technically I only have one working pair, but I can still use the other slave, (V1.2) to debug to my computer if needed.

These are the only modules I own, so the same can't be said with confidence for the blue, Silver or GoldSmirf. Their protocol may be completely different or they could be the same, but if I don't have them, then I can't test them.

I tried to resize the image as best I could without losing quality.

Added: the two on the left do automaticly pair to one another, but the other two, since they are not the same version, I can't be certain. I do know that all four need to be manually paired when connecting to my laptop.
219  Using Arduino / Project Guidance / Re: Creating a bluetooth controller on: March 06, 2014, 08:39:37 pm
Quote
I'm not surprised you have no idea how to do it and, while Hazard may be inclined to elaborate, I don't think the HC-0x are a good place to start.
It's a simple serial connection, why is that hard to understand? No, there is no actually library dedicated to bluetooth, but there really doesn't need to be. If you can send a single character to the arduino with the serial monitor, then it should not be so difficult to remove the connection and make it wireless.

I'll admit it is tough to understand how the bluetooth modules need to be set up, but once you get past that, it's a breeze. I myself had a hard time getting my modules to work and it wasn't until much trial and error that I found out that most modules can only pair to their counterpart if they are  same versions.  I also found out that a master wont connect to the bluetooth in a computer or laptop nor will it connect to another master. You can have Master to slave and slave to slave but that's it.

The module AgentNoise has, must be a slave otherwise it would not have connect to his phone, unless his phone knows to change the state of the module from master to slave, but I doubt it.

Another thing to know is most bluetooth modules, both masters and slaves, are usually set to 9600 by default. So if or when they do auto connect, you can run a simple sketch on both to send and receive a single character between the two. Maybe have one blink the LED on the others board.
220  Using Arduino / Project Guidance / Re: Creating a bluetooth controller on: March 06, 2014, 05:18:42 pm
What bluetooth modules are you using, most HC-05/06 modules pair automatically when they are within a 30 ft range of each other.
221  Using Arduino / Project Guidance / Re: Creating a bluetooth controller on: March 06, 2014, 03:58:17 pm
Quote
I have a robot created that I can control with my Android phone via Bluetooth
This is a bit confusing, if you created a robot that already work with your phone over bluetooth, then how are you having trouble creating a bluetooth controller? Did you create the code for your phone or did you just copy and paste in someone elses without actually understanding it? I would think the controller would be extremely easy to make considering you should already know what to send to the robot to get it to work. Are you looking to have the robot control the controller? No, so I would think you would want the bluetooth in the robot, to be the slave and the bluetooth in the controller be the master.

What seems to be giving you trouble that you can't figure out yourself?
222  Using Arduino / Programming Questions / Re: [SOLVED]Need help referencing two classes in one constructor. on: March 06, 2014, 12:34:43 am
The way the library is written, it should work with a regular Lcd too.
223  Using Arduino / Programming Questions / Re: Transfer data to arduino via bluetooth on: March 05, 2014, 09:19:53 pm
Quote
Basically I found it online and modifying according to my need.

That never usually works out correctly. Try the example program BluetoothChat and see if that allows you to connect to your BT module.
224  Using Arduino / Programming Questions / Re: [SOLVED]Need help referencing two classes in one constructor. on: March 05, 2014, 09:03:36 pm
I absolutely do, Thank you for all of your help. I learned a great deal, and I'm actually using what you taught me for my other libraries.

Again Thank you very much.
225  Using Arduino / Programming Questions / Re: Transfer data to arduino via bluetooth on: March 05, 2014, 08:10:16 pm
Did you make the android code yourself, if so, let me take a look at it. I'm wondering if its the UUID that is the issue,or if you even coded it correctly in the first place.
Pages: 1 ... 13 14 [15] 16 17 ... 197