HELP!! in rc car using radiohead

hi,

Im doing a rc car using radiohead. For RX im using a mega and a motor shield and for TX im using an arduino uno and pot joystick. The problem is im only able to receive few values and the other values its not receiving. I uploaded the example code and it worked properly but its not working with my rc car code. Can you please solve the issue.Im using 434 Mhz. Pls.

This is TX code.

// ask_transmitter.pde
// -*- mode: C++ -*-
// Simple example of how to use RadioHead to transmit messages
// with a simple ASK transmitter in a very simple way.
// Implements a simplex (one-way) transmitter with an TX-C1 module

#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile

RH_ASK driver(2000,22,5,10,false);
 int xaxis = A0;
 int yaxis = A1;
 int valuex = 0;
 int valuey = 0;
 



void setup()
{
    Serial.begin(9600);	  // Debugging only
    if (!driver.init())
         Serial.println("init failed");
         
}

void loop()
{
  
    int xst = analogRead(xaxis);
    int yst = analogRead(yaxis);

    if(xst <508 && xst >= 0)
   { valuex = 100;}
   else if(xst > 511 && xst < 1025)
   { valuex = 200; }
   else 
   {valuex = 0;}
   if(yst < 495 && yst >=0)
   {valuey = 1000;}
   else if(yst > 498 && yst <=1025)
  {valuey = 2000; }
  else
  {valuey = 0;}
  int valt = valuex + valuey;
char *  msg = (char *) valt ;
  driver.send((uint8_t *) msg, strlen(msg));
  driver.waitPacketSent();
  Serial.println(int(msg));
  
  
    
    
    

   
}

This is Rx code for only printing the hex values.

// ask_receiver.pde
// -*- mode: C++ -*-
// Simple example of how to use RadioHead to receive messages
// with a simple ASK transmitter in a very simple way.
// Implements a simplex (one-way) receiver with an Rx-B1 module

#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile

RH_ASK driver(2000,22,5,10,false);

void setup()
{
    Serial.begin(9600);	// Debugging only
    if (!driver.init())
         Serial.println("init failed");
}

void loop()
{
    uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
    uint8_t buflen = sizeof(buf);
    int val;

    if (driver.recv(buf, &buflen)) // Non-blocking
    {
	int i;

	// Message with a good checksum received, dump it.
	driver.printbuffer("got",buf,buflen);
    }
}

Thanks

Please edit your post to use code tags, rather than quote tags.

char *  msg = (char *) valt ;
  driver.send((uint8_t *) msg, strlen(msg));

This won't work, because msg will not be a zero terminated character array (C string), as required by strlen(). Use itoa() or some other method to format the value into a string.

sorry ill use code tag and can u add it in the code because i dint understand where to add

Read about the itoa() function here.

Now it doesn’t receive any value

// ask_transmitter.pde
// -*- mode: C++ -*-
// Simple example of how to use RadioHead to transmit messages
// with a simple ASK transmitter in a very simple way.
// Implements a simplex (one-way) transmitter with an TX-C1 module

#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile
#include<stdlib.h>

RH_ASK driver(2000,22,5,10,false);
 int xaxis = A0;
 int yaxis = A1;
 int valuex = 0;
 int valuey = 0;
 



void setup()
{
    Serial.begin(9600);  // Debugging only
    if (!driver.init())
         Serial.println("init failed");
         
}

void loop()
{
  
    int xst = analogRead(xaxis);
    int yst = analogRead(yaxis);
     char* msg;

    if(xst <508 && xst >= 0)
   { valuex = 100;}
   else if(xst > 511 && xst < 1025)
   { valuex = 200; }
   else 
   {valuex = 0;}
   if(yst < 495 && yst >=0)
   {valuey = 1000;}
   else if(yst > 498 && yst <=1025)
  {valuey = 2000; }
  else
  {valuey = 0;}
  int valt = valuex + valuey;
 itoa(valt,msg,10);
  driver.send((uint8_t *) msg, strlen(msg));
  driver.waitPacketSent();
  Serial.println(int(msg));
char* msg;

You have reserve enough space for "msg" to hold the largest string you will transmit. This doesn't reserve any.

Try:

char msg[10];

I recommend studying the Arduino examples and learning the programming language, before blindly jumping into a project this complicated.

it throws this error i tried with different array vals too.

exit status 1 cannot convert 'char*' to 'char' for argument '2' to 'char* itoa(int, char*, int)'

Thnx a lot (the error came because i added the * symbol) but i got another problem, the receiving value is different from the values i assigned in the tx code.

tx code

// ask_transmitter.pde
// -*- mode: C++ -*-
// Simple example of how to use RadioHead to transmit messages
// with a simple ASK transmitter in a very simple way.
// Implements a simplex (one-way) transmitter with an TX-C1 module

#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile
#include<stdlib.h>

RH_ASK driver(2000,22,5,10,false);
 int xaxis = A0;
 int yaxis = A1;
 int valuex = 0;
 int valuey = 0;
 



void setup()
{
    Serial.begin(9600);	  // Debugging only
    if (!driver.init())
         Serial.println("init failed");
         
}

void loop()
{
  
    int xst = analogRead(xaxis);
    int yst = analogRead(yaxis);
     char msg[10];

    if(xst <508 && xst >= 0)
   { valuex = 100;}
   else if(xst > 511 && xst < 1025)
   { valuex = 200; }
   else 
   {valuex = 0;}
   if(yst < 495 && yst >=0)
   {valuey = 1000;}
   else if(yst > 498 && yst <=1025)
  {valuey = 2000; }
  else
  {valuey = 0;}
  int valt = valuex + valuey;
 itoa(valt,msg,10);
  driver.send((uint8_t *) msg, strlen(msg));
  driver.waitPacketSent();
  Serial.println(msg);
  
  
    
    
    

   
}

rx code

// ask_receiver.pde
// -*- mode: C++ -*-
// Simple example of how to use RadioHead to receive messages
// with a simple ASK transmitter in a very simple way.
// Implements a simplex (one-way) receiver with an Rx-B1 module

#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile

RH_ASK driver(2000,22,5,10,false);
uint8_t nbytes = 2;

void setup()
{
    Serial.begin(9600);	// Debugging only
    if (!driver.init())
         Serial.println("init failed");
}

void loop()
{
    uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
    uint8_t buflen = sizeof(buf);
    int val = int(buf);;

    if (driver.recv(buf), &buflen)) // Non-blocking
    {
	int i;

	// Message with a good checksum received, dump it.
Serial.println(buf);
    }
}

i got another problem, the receiving value is different from the values i assigned in the tx code.

And it never occurred to you to tell the forum what those values are?

the values assigned are in the tx code and im receiving only 8635 when i convert the buffer to integer and display it in serial monitor. If i try displaying buffer, an error is thrown telling that it is overloaded

rx code

// ask_receiver.pde
// -*- mode: C++ -*-
// Simple example of how to use RadioHead to receive messages
// with a simple ASK transmitter in a very simple way.
// Implements a simplex (one-way) receiver with an Rx-B1 module

#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile

RH_ASK driver(2000,22,5,10,false);
uint8_t nbytes = 2;

void setup()
{
    Serial.begin(9600);	// Debugging only
    if (!driver.init())
         Serial.println("init failed");
}

void loop()
{
    uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
    uint8_t buflen = sizeof(buf);
    int val = int(buf);

    if (driver.recv(buf, &buflen)) // Non-blocking
    {
Serial.println(int(buf));
delay(1000);
	// Message with a good checksum received, dump it.

    }
}

Pls help me in the receiver code

If i try displaying buffer, an error is thrown telling that it is overloaded

But did it never occur to you that the exact error message might be important, and to tell us what it is?

I think it is about time that you read the "How to use this forum" post. It has [u]great[/u] advice on how to ask intelligent questions, which leads to helpful answers.

Ill surely read it. I resolved that error with this receiver code.

// ask_receiver.pde
// -*- mode: C++ -*-
// Simple example of how to use RadioHead to receive messages
// with a simple ASK transmitter in a very simple way.
// Implements a simplex (one-way) receiver with an Rx-B1 module

#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile
#include<stdlib.h>

RH_ASK driver(2000,22,5,10,false);;

void setup()
{
    Serial.begin(9600); // Debugging only
    if (!driver.init())
         Serial.println("init failed");
}

void loop()
{
    uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
    uint8_t buflen = sizeof(buf);
   int val = int(buf);
   
    

    if (driver.recv((uint8_t *)(&val), &buflen)) // Non-blocking
    {

Serial.println(val);

 // Message with a good checksum received, dump it.
 

 
    }
}

but now the problem is im receiving different values from the values I assigned.

The values are :

if the joystick is in center - receiving 8496 - assigned value is 0.
if i move the joystick up - 12337 - assigned value is 1000.
if move the jystick right - 12338 - assigned value is 200.
if i move the joysticck down - 12338 - assigned value is 2000.
if i move it lefft - 12337 - assigned value is 100.
if i move it to the top left diagonal - 12593 - assigned 1100.
if i move it to the top right diagonal - 12849 - assigned 1200.
if i move it bottom right diagonal - 12850 - assigned 2200.
if i move it bottom left diagonal - 12594 - assigned 2100.

please help me out.

For the overload message
call of overloaded ‘println(uint8_t [60])’ is ambiguous

for this code

// ask_receiver.pde
// -*- mode: C++ -*-
// Simple example of how to use RadioHead to receive messages
// with a simple ASK transmitter in a very simple way.
// Implements a simplex (one-way) receiver with an Rx-B1 module

#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile
#include<stdlib.h>

RH_ASK driver(2000,22,5,10,false);;

void setup()
{
    Serial.begin(9600); // Debugging only
    if (!driver.init())
         Serial.println("init failed");
}

void loop()
{
    uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
    uint8_t buflen = sizeof(buf);
   int val = int(buf);
   
    

    if (driver.recv(buf, &buflen)) // Non-blocking
    {

Serial.println(buf);
delay(400);

 // Message with a good checksum received, dump it.
 

 
    }
}

Ive posted the problems and a detailed list of the values

pls help