Go Down

Topic: troubles in making gesture based robot using arduino (Read 1 time) previous topic - next topic

rupinder

i am making gesure based robot for that i have made transmitter and reciever section my transmitter is working properly but my bot is not moving which is configured with rf 433 mhz reciver accordingly. my hardware is fine i think i my code is errorneous (but there are no errors in arduino ide)
here is my code

Code: [Select]
void setup()
{
 //Serial.begin(9600);//Initialise the serial connection debugging

 pinMode(ledPin,OUTPUT);
 pinMode(rm,OUTPUT);
 pinMode(rmr,OUTPUT);
 pinMode(lm,OUTPUT);
 pinMode(lmr,OUTPUT);

 vw_setup(2000); // Bits per sec
 vw_rx_start(); // Start the receiver
}
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;

  //Serial.print("Got: ");//debugging
 
  for (i = 0; i < buflen; i++)
  {
     // Serial.print(buf[i],HEX);//You may also use integer values debugging
      //Serial.print(' ');// debugging

          if (buf[i]==0x73)//Stationary
          {
            digitalWrite(rm,LOW); 
            digitalWrite(rmr,LOW);
            digitalWrite(lm,LOW);
            digitalWrite(lmr,LOW);
         
            digitalWrite(ledPin,LOW);
          }
          else
          {
            if(buf[i]==0x66)//Forward
            {
              digitalWrite(rm,LOW); 
              digitalWrite(rmr,HIGH);
              digitalWrite(lm,LOW);
              digitalWrite(lmr,HIGH);
             
              digitalWrite(ledPin,HIGH);
            }
         
            if (buf[i]==0x61)//Backward
            {
              digitalWrite(rm,HIGH); 
              digitalWrite(rmr,LOW);
              digitalWrite(lm,HIGH);
              digitalWrite(lmr,LOW);
             
              digitalWrite(ledPin,HIGH);
          }
         
            if (buf[i]==0x72)//Left
            {
              digitalWrite(rm,LOW); 
              digitalWrite(rmr,HIGH);
              digitalWrite(lm,HIGH);
              digitalWrite(lmr,HIGH);
              digitalWrite(ledPin,HIGH);
            }
         
            if (buf[i]==0x6C)//Right
            {
              digitalWrite(rm,LOW); 
              digitalWrite(rmr,LOW);
              digitalWrite(lm,LOW);
              digitalWrite(lmr,HIGH);
              digitalWrite(ledPin,HIGH);
            }
           }   
    }
    //Serial.print("\n");// debugging
        }
        //delay(1000);
}[code]
[/code]


and one more thing i am using adlx335 acclerometer for gestures with transmitter and arduino do i need to use encoder at transmitter and decoder at reciever section??
 
         

DrDiettrich

What do you receive? Nothing at all, or not what has been sent?

When you claim "non blocking" message read, you'll have to wait until the message has been received. In this case a global buffer array is required, not a local one in loop(). I also guess that you want to read single characters, not wait until 8 bytes have been transmitted.

If you want to transmit more information, you should design your own transmission (message) protocol. Every message includes a command code, and possibly further parameters depending on the command. Then you also should secure the entire protocol against lost bytes, which otherwise would cause loss of synchronization between transmitter and receiver.

rupinder

will you help me to create a program for reciever ?
here is the code for transmitter
Code: [Select]

#include <VirtualWire.h>

int xPin=0;
int yPin=1;

int ledPin=13;//led on pin 13 is ON except when transmitter is parallel to the ground

void setup()
{
  vw_setup(2000);//Bits per second
  pinMode(ledPin,OUTPUT);
  //Serial.begin(9600);//Initialise the serial connection debugging
}

void loop()
{
  int xval=analogRead(xPin);
  int yval=analogRead(yPin);
 
  //Serial.print("xval=");
  //Serial.println(xval);
 
  //Serial.print("yval=");
//Serial.println(yval);
 
  //delay(1000); //used to display values after 1s delay
 
  //Serial.print("\n");
 
  if ((xval>339 && xval<345) && (yval>334 && yval<339)) //stationary or stop(transmitter parallel to ground)
  {
    digitalWrite(ledPin,LOW);
    send("s");
  }
  else
  {
    if ((xval>307 && xval<320) && (yval>336 && yval<344)) //forward(transmitter tilted forward)
    {
      digitalWrite(ledPin,HIGH);
      send("f");
     
    }
    if ((xval>365 && xval<372) && (yval>674 && yval<678)) //backward(transmitter tilted backward)
    {
      digitalWrite(ledPin,HIGH);
      send("a");
     
    }
    if ((xval>343 && xval<349) && (yval>297 && yval<310)) //left(transmitter tilted to left)
    {
      digitalWrite(ledPin,HIGH);
      send("l");
     }
     if ((xval>344 && xval<348) && (yval>368&& yval<381))//right(transmitter tilted to right)
    {
      digitalWrite(ledPin,HIGH);
      send("r");
     
    }
  }
  //delay(1000);
 
}


void send(char *message)//send function definition
{
  vw_send((uint8_t *)message, strlen(message));
  vw_wait_tx(); // Wait until the whole message is gone
}[code]
[/code]

rupinder


DrDiettrich

Forum help provides assistance for free, but not complete solutions. You should at least study related projects and examples, then try to write some code. If you cannot write anything yourself, hire somebody to do it for you.

rupinder

here is the code for reciever section.... i didnt able to catch errors
Code: [Select]
//Connect the Receiver data pin to Arduino pin 11

#include <VirtualWire.h>
byte message[VW_MAX_MESSAGE_LEN]; // a buffer to store the incoming messages
byte messageLength = VW_MAX_MESSAGE_LEN; // the size of the message

int ledPin=13;//led on pin 13 is ON except when bot is stationary

int lm=9;//pin 9 of arduino to pin 7 of ic

int lmr=8;//pin 8 of arduino to pin 2 of ic

int rm=10;//pin 10 of arduino to pin 10 of ic

int rmr=7;//pin 7 of arduino to pin 15 of ic

//+ve of lm to pin 6,-ve to pin 3 //+ve of rm to pin 11,-ve to pin 14

void setup()
{
 //Serial.begin(9600);//Initialise the serial connection debugging

 pinMode(ledPin,OUTPUT);
 pinMode(rm,OUTPUT);
 pinMode(rmr,OUTPUT);
 pinMode(lm,OUTPUT);
 pinMode(lmr,OUTPUT);

 vw_setup(2000); // Bits per sec
 vw_rx_start(); // Start the receiver
}
void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

  vw_have_message();
  Serial.print("message ");
 
    {
  int i;

  Serial.print("Got: ");//debugging
 
  for (i = 0; i < buflen; i++)
  {
     Serial.print(buf,HEX);//You may also use integer values debugging
      Serial.print(' ');// debugging

          if (buf==0x73)//Stationary
          {
            digitalWrite(rm,LOW); 
            digitalWrite(rmr,LOW);
            digitalWrite(lm,LOW);
            digitalWrite(lmr,LOW);
         
            digitalWrite(ledPin,LOW);
          }
          else
          {
            if(buf==0x66)//Forward
            {
              digitalWrite(rm,LOW); 
              digitalWrite(rmr,HIGH);
              digitalWrite(lm,LOW);
              digitalWrite(lmr,HIGH);
             
              digitalWrite(ledPin,HIGH);
            }
         
            if (buf==0x61)//Backward
            {
              digitalWrite(rm,HIGH); 
              digitalWrite(rmr,LOW);
              digitalWrite(lm,HIGH);
              digitalWrite(lmr,LOW);
             
              digitalWrite(ledPin,HIGH);
          }
         
            if (buf==0x72)//Left
            {
              digitalWrite(rm,LOW); 
              digitalWrite(rmr,HIGH);
              digitalWrite(lm,HIGH);
              digitalWrite(lmr,HIGH);
              digitalWrite(ledPin,HIGH);
            }
         
            if (buf==0x6C)//Right
            {
              digitalWrite(rm,LOW); 
              digitalWrite(rmr,LOW);
              digitalWrite(lm,LOW);
              digitalWrite(lmr,HIGH);
              digitalWrite(ledPin,HIGH);
            }
           }   
    }
    Serial.print("\n");// debugging
        }
       
        delay(1000);
}
Code: [Select]

DrDiettrich

You used the code tags in wrong way. Edit your posting, select the entire code, then click on </> to properly enclose the selected text.

About your problem, how do you think will any information come into buf[]? Programs are based on logic, not on woodoo :-]

You better run a receiver example first, then modify it to match your needs.

rupinder

here is the code for recicever please specify problems i am newbie to arduino and have tried a lot to correct this program please help me to replace the codes that are wrong
Code: [Select]
//Connect the Receiver data pin to Arduino pin 11

#include <VirtualWire.h>
byte message[VW_MAX_MESSAGE_LEN]; // a buffer to store the incoming messages
byte messageLength = VW_MAX_MESSAGE_LEN; // the size of the message


int ledPin=13;//led on pin 13 is ON except when bot is stationary

int lm=9;//pin 9 of arduino to pin 7 of ic

int lmr=8;//pin 8 of arduino to pin 2 of ic

int rm=10;//pin 10 of arduino to pin 10 of ic

int rmr=7;//pin 7 of arduino to pin 15 of ic

//+ve of lm to pin 6,-ve to pin 3 //+ve of rm to pin 11,-ve to pin 14

void setup()
{
Serial.begin(9600);//Initialise the serial connection debugging

pinMode(ledPin,OUTPUT);
pinMode(rm,OUTPUT);
pinMode(rmr,OUTPUT);
pinMode(lm,OUTPUT);
pinMode(lmr,OUTPUT);

vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver
}
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;

 Serial.print("Got: ");//debugging
 
 for (i = 0; i < buflen; i++)
 {
     Serial.print(buf[i],HEX);//You may also use integer values debugging
     Serial.print(' ');// debugging

         if (buf[i]==0x73)//Stationary
         {
           digitalWrite(rm,LOW);  
           digitalWrite(rmr,LOW);
           digitalWrite(lm,LOW);
           digitalWrite(lmr,LOW);
         
           digitalWrite(ledPin,LOW);
         }
         else
         {
           if(buf[i]==0x66)//Forward
           {
             digitalWrite(rm,LOW);  
             digitalWrite(rmr,HIGH);
             digitalWrite(lm,LOW);
             digitalWrite(lmr,HIGH);
             
             digitalWrite(ledPin,HIGH);
           }
         
           if (buf[i]==0x61)//Backward
           {
             digitalWrite(rm,HIGH);  
             digitalWrite(rmr,LOW);
             digitalWrite(lm,HIGH);
             digitalWrite(lmr,LOW);
             
             digitalWrite(ledPin,HIGH);
         }
         
           if (buf[i]==0x72)//Left
           {
             digitalWrite(rm,LOW);  
             digitalWrite(rmr,HIGH);
             digitalWrite(lm,HIGH);
             digitalWrite(lmr,HIGH);
             digitalWrite(ledPin,HIGH);
           }
         
           if (buf[i]==0x6C)//Right
           {
             digitalWrite(rm,LOW);  
             digitalWrite(rmr,LOW);
             digitalWrite(lm,LOW);
             digitalWrite(lmr,HIGH);
             digitalWrite(ledPin,HIGH);
           }
          }  
   }
   Serial.print("\n");// debugging
       }
       delay(1000);
}

i would be thankful if you help me

DrDiettrich

What do you receive with the original example code?

rupinder

Blank screen of serial monitor with scroller automatically down

DrDiettrich

That means you never received a printable character. The first problem resides in your sender code.

rupinder

#11
Aug 28, 2016, 12:01 pm Last Edit: Aug 28, 2016, 12:09 pm by rupinder
Code: [Select]
#include <VirtualWire.h>

int xPin=0;
int yPin=1;

int ledPin=13;//led on pin 13 is ON except when transmitter is parallel to the ground

void setup()
{
 vw_setup(2000);//Bits per second
 pinMode(ledPin,OUTPUT);
 //Serial.begin(9600);//Initialise the serial connection debugging
}

void loop()
{
 int xval=analogRead(xPin);
 int yval=analogRead(yPin);
 
 //Serial.print("xval=");
 //Serial.println(xval);
 
 //Serial.print("yval=");
//Serial.println(yval);
 
 //delay(1000); //used to display values after 1s delay
 
 //Serial.print("\n");
 
 if ((xval>339 && xval<345) && (yval>334 && yval<339)) //stationary or stop(transmitter parallel to ground)
 {
   digitalWrite(ledPin,LOW);
   send("s");
 }
 else
 {
   if ((xval>307 && xval<320) && (yval>336 && yval<344)) //forward(transmitter tilted forward)
   {
     digitalWrite(ledPin,HIGH);
     send("f");
    
   }
   if ((xval>365 && xval<372) && (yval>674 && yval<678)) //backward(transmitter tilted backward)
   {
     digitalWrite(ledPin,HIGH);
     send("a");
    
   }
   if ((xval>343 && xval<349) && (yval>297 && yval<310)) //left(transmitter tilted to left)
   {
     digitalWrite(ledPin,HIGH);
     send("l");
    }
    if ((xval>344 && xval<348) && (yval>368&& yval<381))//right(transmitter tilted to right)
   {
     digitalWrite(ledPin,HIGH);
     send("r");
    
   }
 }
 //delay(1000);
 
}


void send(char *message)//send function definition
{
 vw_send((uint8_t *)message, strlen(message));
 vw_wait_tx(); // Wait until the whole message is gone
}

this is sender code

DrDiettrich

You still use the code tags in a wrong way :-(

The posted code doesn't match the used code. Either the sender sends empty packages, or the receiver receives packages never sent.

Start with the example sender and receiver code, and verify that the receiver only displays what has been sent, not less and not more.

rupinder

i have myself checked rf reciever and transmitter using hello world message transmittr and reciever reciever is exacltyl showing what has been transmitted in serial monitor... rf pair is absolutely fine there is problem with code somewhere?? i am student i am not been able to catch that error you ar a expert you can help me getting that

DrDiettrich

You better start with much simpler projects, until you learned the basics of writing and debugging code. Or hire somebody else who writes the code for you.

Go Up