Robot Software Problematic!

i built a Robot which however works fine by utilizing the Virtual wire Library for wireless controlling and had the following code on Transmitter :

#include <VirtualWire.h>
void setup()
{
Serial.begin(9600); // Debugging only
Serial.println("setup");
vw_set_tx_pin(9);
// Initialise the IO and IS
vw_setup(2000); // Bits per sec
}

void loop()
{
if (Serial.read() == 's') {
const char *msg = "s";
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
Serial.println("s is there");
}

if (Serial.read() == 'f') {
const char *msg = "f";
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
Serial.println("f is there");
}

if (Serial.read() == 'r') {
const char *msg = "r";
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
Serial.println("r is there");
}

if (Serial.read() == 'b') {
const char *msg = "b";
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
Serial.println("b is there");
}

if (Serial.read() == 'l') {
const char *msg = "l";
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
Serial.println("l is there");
}
}

and the Receiver code is :

#include <VirtualWire.h>

void setup()
{
Serial.begin(9600); // Debugging only
Serial.println("setup");
pinMode(10,OUTPUT);
pinMode(13,OUTPUT);//logical pin's for 1st motor
pinMode(12,OUTPUT);//logical pin for 1st motor
pinMode(8,OUTPUT); //logical pin for 2nd motor
pinMode(2,OUTPUT);//logical pin for 2nd motor
pinMode(9,OUTPUT);
digitalWrite(9,HIGH); //enable pin motor 1
digitalWrite(10,HIGH); // enable pin motor 2
vw_setup(2000); // Bits per sec
vw_set_rx_pin(11); // explicitly defining the signal pin for ATmega
vw_rx_start(); // Start the receiver PLL running
}

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: ");

for (i = 0; i < buflen; i++)
{
Serial.print(buf*);*

  • }*
  • switch (buf[0]) { //catching the first array instance received*
  • case 'r': //Received r from the Transmitter for moving right*
  • digitalWrite(13,HIGH);*
  • digitalWrite(12,LOW);*
  • digitalWrite(8,LOW);*
  • digitalWrite(2,HIGH);*
  • break;*
  • case 's': //Received s from the Transmitter for moving straight*
  • digitalWrite(13,HIGH);*
  • digitalWrite(12,LOW);*
  • digitalWrite(8,HIGH);*
  • digitalWrite(2,LOW);*
  • break;*
  • case 'b': //Received b from the Transmitter for moving back*
  • digitalWrite(13,LOW);*
  • digitalWrite(12,HIGH);*
  • digitalWrite(8,LOW);*
  • digitalWrite(2,HIGH);*
  • break;*
  • case 'f': //Received f from the Transmitter for stopping*
  • digitalWrite(13,LOW);*
  • digitalWrite(12,LOW);*
  • digitalWrite(8,LOW);*
  • digitalWrite(2,LOW);*
  • break;*
  • case 'l': //Received l from the Transmitter for moving left*
  • digitalWrite(13,LOW);*
  • digitalWrite(12,HIGH);*
  • digitalWrite(8,HIGH);*
  • digitalWrite(2,LOW);*
  • break;*
  • }*
    _ Serial.println("");_
  • }*
    }
    [/quote]
    i send the commands by using the serial monitor of arduino and then transmitter sends the commands to receiver.

THE PROBLEM goes like if i have written s on serial console in arduino it gives out "s" standing for straight that the robo will move in straight direction but if i put the other command to stop, move left or right immidiately say in 2-3 seconds then it's taken by the receiver and the motor's run as specified but if i take a little longer say 5-7 seconds or more to issue new command's to the receiver then the commands are not OBEYED ]:smiley: .
I'm using the H-Bridges L293D's for this purpose STACKED one on one to increase the Power Support and use RF modules of 434 MHz frequency as supplied by the Spark fun (The common one's that are one way).

for MORE INFO How it is ORGANIZED works : these are the following Videos and Pic's:

SOME PICTURE"S :

Is it possible your radio transmission line is a bit noisy, and is adding unwanted characters every few seconds? You're only looking at the first character in whatever data you receive, check to see if you got more data than expected first. You probably want the LAST character received instead.

Oh, and nice robot, by the way! I loved the pictures. It ain't no R2D2, but that's how you do it... just jump in and go. Solve the problems as you go along.

thanks Tesla man! it is the ONLY thing that made some People comment or get Attracted to me ON FACEBOOK Or i was Anonymous inspite of having classmates there. Yes i think it could be a bit noisy because it is linked to the same power supply that is given to ATmega and H-Bridges too so Receiver + ATmega + H-Bridge's on same power supply channel.

What you'll figure out, is that you need a protocol that handles extra crud characters that get inserted when the line is 'quiet'.

Here's a real simple one that goes in with your single character command structure:

Send your messages with a 2 byte 'header' before the actual character. For example, use the ESC char (0x1B) or... if you want to keep in ascii, use any character, really. It doesn't matter. Then, when you send your single char command... sent it AFTER the 2 header characters.

For example: To go forward, you send ESC ESC s

The receiver goes through the buffer, looking for 2 ESC chars. It then knows for a fact that the NEXT char is a valid command.

In my protocol, the character after the header is the length of the rest of the data, as a byte. The receiver routine then knows how many characters to pull in to get the entire message.

Something really interesting , i'll do it.

Thank you TeslaFan

TeslaFan i discovered that the Virtual Wire library already has the buffering support.

So any other Idea?

Oh yeah! Look at that, it even checksums it during the transmission process.

The only thing I see iffy in here is this, in the receiver's loop():

for (i = 0; i < buflen; i++)
{
Serial.print(buf);
}

This sends the entire buffer, initialized or received or not, VW_MAX_MESSAGE_LEN number of times. And it's doing this as often as it possibly can over a serial port to nowhere. That can't be helping, although I can't really see where that would stop the real messages from getting through.

I think you intended to use Serial.write(), which sends one byte... but changed it when you realized you wanted it to print a readable character instead of the numerical ASCII code.