Virtual Wire - Send More byte like Number

Good Afternoon Friend,
I'm working with virtual wire library this is my scenario :

Device Address:

Byte

001 - Led1 --> Connected to Arduino
002 - Led2 --> Connected to another arduino
003 - Led3 --> Connected to another arduino

Command List:

Byte

001 - Turn On
002 - Turn Off

State List:
001 - Turned On
002 - Turned Off
003 - Bad State

My Message Structure will Be:

Destination Address + Command

then I'll have

003 001

How I can do for send out this message ?

is there a protocol that i can use ? :slight_smile:

Thanks in advance,
Andrea

VirtualWire is no longer supported. You should probably try to use the RadioHead library that replaced it.

http://www.airspayce.com/mikem/arduino/RadioHead/

Thanks I will have a look :slight_smile:

Regards,
Andrea

Ciao where i can found the connection schema ?

Thanks
Andrea

You will need to provide more information on your TX, RX hardware.

Could kindly someone explain me how to inizialize …

baud rate
tx pin
rx pin

in ask with new radio head library ?

thansk
Andrea

gnusso:
Could kindly someone explain me how to inizialize ...

baud rate
tx pin
rx pin

in ask with new radio head library ?

thansk
Andrea

You should probably look at the library examples:
ask_reliable_datagram_client
ask_reliable_datagram_server

It you are confused by the examples johnwasser suggested you can get going with the more simple examples in the library ask_receiver and ask_transmitter.

The library will use default values of 2000 bps, rx pin 11, and tx pin 12.

You can confirm that the software is running by connecting pin 11 on the RX Arduino to pin 12 of your TX Arduino and bypassing the radios to start.

You have still not confirmed what hardware you are using. Not all modules use RadioHead or VirtualWire.

Thanks I’ve done a first test

with this simple sketch:

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

RH_ASK driver;



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

void loop()
{
    const char *msg = "hello";
    driver.send((uint8_t *)msg, strlen(msg));
    driver.waitPacketSent();
    delay(200);
}

Receive code:

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

RH_ASK driver(2000,8,9);

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

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

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

	// Message with a good checksum received, dump it.
	driver.printBuffer("Got:", buf, buflen);
      
    }
}

ok on the receiver I receive this:

Got:
68 65 6C 6C 6F

Ok now I would lke from sender staind point send-out the message “hello” in this way

104 101 108 108 111

that looking the ascii table
http://arduino.cc/en/Reference/ASCIIchart

should be hello but where i sendout byte in stead of character is possible ?

Thanks
Andrea

Here is some code to send and receive a byte array.

//Send Byte Array

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

RH_ASK driver(2000,8,9);
//RH_ASK driver;//using defaults

void setup()
{
  driver.init();
}

void loop()
{
  byte data[] = {104, 101, 108, 108, 111};
  long interval = 2000; //send every 2 seconds
  static unsigned long millisLast = millis();

  if(millis() - millisLast > interval){

    driver.send(data, sizeof(data));
    driver.waitPacketSent();
    delay(200);

    millisLast = millis();

  }

}
//Receive Byte Array
#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile
RH_ASK driver(2000,8,9;
//RH_ASK driver;//using defaults

void setup()
{
 driver.init();
 Serial.begin(9600);
}

void loop()
{ 
  byte Data[5] = {};
  uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
  uint8_t buflen = sizeof(buf);

  if (driver.recv(buf, &buflen)) // Non-blocking  Data is sent every minute
  {
       // Message with a good checksum received, dump it.
 driver.printBuffer("Got:", buf, buflen);
    
    Serial.println("Received");
    
    memcpy (&Data, buf, buflen);

    for (int i=0; i<5; i++){
      Serial.println(Data[i]);
   }
  
  }
}

On the RX I use memcpy to get the data into the sending format and then use it from there.

Thanks :slight_smile: I've done,

could I'm checking documentation and I'm trying like in virtual wire to wait until message is avaiable function ... but I'm not find it :frowning: do you know how is named the function ?

thanks
Andrea

These are the VirtualWire RX functions. Which one are you trying to match? And Why?

Reception Functions

vw_rx_start()
Activate the receiver process. You must call this function before any reception can occur. An interrupt-based background process is started which monitors the reception of data.
vw_have_message()
Returns true if message has been received. This is similar to the "available" function of most other libraries.
vw_wait_rx()
Wait for a message to be received. This will only return when a message has been received, otherwise it will wait forever.
vw_wait_rx_max(timeout_ms)
Wait for a message, but give up after "timeout_ms". Returns true if a message was received, or false if the timeout period elapsed.
vw_get_message(buf, &buflen))
Read the last received message. This should be called only when a message is known to be received with any of the 3 functions above. "buf" is an array where the message is copied. "buflen" should have the array's maximum size upon input, and upon return the number of bytes actually copied is retured. The function itself returns true if the message was verified correct, or false if a message was received but appears to have been corrupted.
vw_rx_stop()
Disable the receiver process.

ok thanks but I'm using the new RadioHead Version :frowning: ...

I'm trying like in virtual wire to wait until message is avaiable function

I understand that you are using RadioHead. Which VW function are you trying to replace with an equivalent RadioHead function?