315 Mhz transmitter - Receiver

Hi,

Tonight I plugged in my new 315 MHz Trasmistter - Receiver from Ebay. I finally had them to work, I think.

Here is my code.

TX

#include <VirtualWire.h>


void setup()
{

  pinMode(13, OUTPUT);

  vw_set_ptt_inverted(true);
  vw_setup(2000);            // Bits per sec
  vw_set_tx_pin(3);          //Tx pin
  
}


void loop()
{
  
  delay(500);               //Send a message every half second

  char *msg = "12321";
  digitalWrite(13, HIGH ); // 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, LOW);


}

RX

#include <VirtualWire.h>


int i =0;


void setup()
{

  Serial.begin(9600);
  Serial.println("Started");
  
  vw_set_ptt_inverted(true); 
  vw_setup(2000);	         // Bits per sec
  vw_set_rx_pin(2);              //Rx pin
  vw_rx_start();               

  pinMode(13, OUTPUT);  

}

void loop()
{


  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

  if (vw_get_message(buf, &buflen)) // Non-blocking
  {
    
    digitalWrite(13, HIGH);
    
    Serial.print('\n');
    Serial.println("Receiving data");
    Serial.print('\n');
    
    for (i = 0; i < buflen; i++)
    {
      Serial.print(buf[i]);

    }
    
    Serial.print('\n');
    Serial.print("------------------------");
    
    
    delay(10);
    digitalWrite(13, LOW);

  }
}

The questions are:

1 - What is that kind of variable : char *msg = "12321";
2 - If I send 12321 and I reveived 4950515049, how to put it back in 12321 format? Is it something like HEX TO INT?

It seem's that 49 is the start and end delimiter for a transmission, am I right? So what are those: 3 = 1 , 2 = 5 and 1 = 0.....

EDIT: I substract 48 from each value so I came back to 12321 I have tested with different value and everything is fine

3 - What are those kind of variable? uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
I have worked on arduino since a long time now and never seen those type of variable. Could it be replaced with some more common one?

Thanks for the help!

The Tx sends characters, as you've figured out.

uint8_t buf[VW_MAX_MESSAGE_LEN];
unsigned 8 bit array called 'buf' that is "VW_MAX_MESSAGE_LEN" bytes in length - if you read the virtual wire documentatio, I think this is 30 bytes.

uint8_t buflen = VW_MAX_MESSAGE_LEN;
unsigned 8 bit variable called 'buflen'. I think 30 bytes unless you change it in pre-setup area:

byte VW_MAX_MESSAGE_LEN = 20;
or maybe there's a library call to make that change.

Thanks for the clarifications CrossRoads.

Hey guys. I'm rather new to the scene. Where does the line "byte VW_MAX_MESSAGE_LEN = 20;" get inserted? I have replicated the same issue. How do we get the code to match on the receiving board? Thanks