Sending over 433 VirtialWire Understanding help

I want to send triggers from one arduino to another using 433Mhz RF hardware, and need help understanding how this works. I am not good with arrays. Can I assign a byte and directly send that byte over the RF? I believe I understand the TX, or at least the majority?? But don’t understand a lot about the RX like what is “uint8_t”?? I know i need something above the RX if(Trigger == 111) I could use help on the RX end. If I am sending bytes do i need “uint8_t buf[VW_MAX_MESSAGE_LEN]; uint8_t buflen = VW_MAX_MESSAGE_LEN;”?? And, here “vw_get_message(buf, &buflen)” can I just assign it like “vw_get_message(Trigger)”?

TX Code:

#include <VirtualWire.h>

const byte Trigger = 111;

void setup()
{
    // Initialise the IO and ISR
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000);	 // Bits per sec
}

void loop()
{
    vw_send(Trigger, 1);
    vw_wait_tx(); // Wait until the whole message is gone
    delay(200);
}

RX Code:

#include <VirtualWire.h>

byte Trigger = 0;

void setup()
{
    pinMode(LED_BUILTIN, OUTPUT);
    // Initialise the IO and ISR
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000);	 // Bits per sec
    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
    {
      if(Trigger == 111)
      {
        digitalWrite(LED_BUILTIN, HIGH);
      }
      else
      {
        digitalWrite(LED_BUILTIN, LOW);
      }
    }
}

Have you tried googling uint8_t?

aarg:
Have you tried googling uint8_t?

So google says that byte, and unsigned char are the same as uint8_t. So why use it at all?

lineman2208: So google says that byte, and unsigned char are the same as uint8_t. So why use it at all?

Because it guarantees the bit length, whereas unsigned char does not, and byte (I believe) is defined in Arduino.h. It is done in the name of portability.

aarg: Because it guarantees the bit length, whereas unsigned char does not, and byte (I believe) is defined in Arduino.h. It is done in the name of portability.

would on the TX end work like how I stated in the first??

lineman2208: would on the TX end work like how I stated in the first??

Can you elucidate? Most people would find the first post a little confusing. Do you mean the fact that Trigger is declared as a byte? What happens when you compile and test it?

aarg: Can you elucidate? Most people would find the first post a little confusing. Do you mean the fact that Trigger is declared as a byte? What happens when you compile and test it?

It is only so confusing because I have multiple questions, that probably are not to the norm for this. I have not compiled and tried this yet. I wanted to have a check on my TX code with, "vw_send(Trigger, 1);". And, I do not think my RX code will work at all. Also wanting a check on, "vw_get_message(Trigger)"? I hope that simplified my question.

lineman2208: I have not compiled and tried this yet.

Doing that will answer 99% of your questions.

aarg:
Doing that will answer 99% of your questions.

As I thought something is not working on the RX end. Unless you see a problem in the TX?
TX code:

#include <VirtualWire.h>
const byte Trigger = 111;

void setup()
{
    // Initialise the IO and ISR
    vw_set_tx_pin(0);
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000);	 // Bits per sec
}

void loop()
{
    vw_send(Trigger, 1);
    vw_wait_tx(); // Wait until the whole message is gone
    delay(200);
}

RX code:

#include <VirtualWire.h>
int Trigger = 0;
int LED = 4;

void setup()
{
  pinMode(LED, OUTPUT);
  // Initialise the IO and ISR
  vw_set_rx_pin(0);
  vw_set_ptt_inverted(true); // Required for DR3100
  vw_setup(2000);   // Bits per sec
  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))
  {
    Trigger = buf;
    if(Trigger == 111)
    {
      digitalWrite(LED, HIGH);
      delay(1000);
      digitalWrite(LED, LOW);
      delay(1000);
    }
    else
    {
      digitalWrite(LED, LOW);
    }
  }
}

I compiled this with a serial monitor to debug. And, my Trigger value of 111 is 2220. Can I get some insight into why that is? what am i missing?

#include <VirtualWire.h>
int Trigger = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  // Initialise the IO and ISR
  vw_set_rx_pin(8);
  vw_set_ptt_inverted(true); // Required for DR3100
  vw_setup(2000);   // Bits per sec
  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))
  {
    Trigger = buf;
    Serial.println(Trigger);
    if(Trigger == 111)
    {
      digitalWrite(LED_BUILTIN, HIGH);
      delay(1000);
      digitalWrite(LED_BUILTIN, LOW);
      delay(1000);
    }
    else
    {
      digitalWrite(LED_BUILTIN, LOW);
    }
  }
}

And, my Trigger value of 111 is 2220.

What does that mean?

Trigger = buf;

The above won't work as you expect, because buf[] is an array.

Try

Trigger = buf[0]; //for a 1 byte transmission

jremington: What does that mean?

Trigger = buf;

The above won't work as you expect, because buf[] is an array.

Try

Trigger = buf[0]; //for a 1 byte transmission

The first question, on the receving end with serial print going in the print it returned 2220. I used a letter as char on the TX end and the RX end picked up the ASCII value and i am using the ASCII value for my triggers. I got it figured out but not like i originally hoped. I have "Trigger = buf[1];" and it works with the ASCII

buff[1] is the second character that was transmitted. Is that what you intend?
Array elements are numbered starting from zero.

jremington: buff[1] is the [u]second[/u] character that was transmitted. Is that what you intend? Array elements are numbered starting from zero.

I do not know much about arrays. If I send 'B'. I receive 66. So it is working. But it isn't correct you are saying?

Dunno. Post your current code, both TX and RX, using code tags.

TX code:

#include <VirtualWire.h>
char msg[1] = {'B'};

void setup()
{
    // Initialise the IO and ISR
    vw_set_tx_pin(0);
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000);	 // Bits per sec
}

void loop()
{
    vw_send((uint8_t *)msg, 1);
    vw_wait_tx(); // Wait until the whole message is gone
    delay(200);
}

RX code:

#include <VirtualWire.h>

int Trigger = 0;           //Variable for the Recived Trigger
int i;
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

void setup()
{
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  // Initialise the IO and ISR
  vw_set_rx_pin(8);
  vw_set_ptt_inverted(true); // Required for DR3100
  vw_setup(2000);	           // Bits per sec
  vw_rx_start();             // Start the receiver PLL running
}

void loop()
{
  if(vw_get_message(buf, &buflen)) // Non-blocking
  {
    Trigger = buf[i];
    Serial.println(Trigger);
  }
    if(Trigger == 66)     //ASCII for B, 066
    {
      digitalWrite(LED_BUILTIN, HIGH);
    }
   else()
   {
     digitalWrite(LED_BUILTIN, LOW);
   }
}

That works purely by accident. In the receive code, the variable i is never defined to have any particular value, so the compiler must be initializing it to zero.

Also, in the receive code, it is required to reset the maximum allowed receive buffer length, every time through the loop.

    int i;
...
   if(vw_get_message(buf, &buflen)) // Non-blocking
  {
    Trigger = buf[i];

Try these somewhat simplified examples (not tested) and let me know if it works.

TX:

#include <VirtualWire.h>
char msg = 'B';  //no array necessary for a single character

void setup()
{
    // Initialise the IO and ISR
    vw_set_tx_pin(0);
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000); // Bits per sec
}

void loop()
{
    vw_send((uint8_t *)msg, 1);
    vw_wait_tx(); // Wait until the whole message is gone
    delay(200);
}

RX:

#include <VirtualWire.h>

int Trigger = 0;           //Variable for the Received Trigger
uint8_t buf;  //one character buffer
uint8_t buflen = 1;  //buffer length

void setup()
{
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  // Initialise the IO and ISR
  vw_set_rx_pin(8);
  vw_set_ptt_inverted(true); // Required for DR3100
  vw_setup(2000);           // Bits per sec
  vw_rx_start();             // Start the receiver PLL running
}

void loop()
{
  buflen=1;  //*** it is required to reset max value of buflen, every iteration of loop ***

if(vw_get_message(buf, &buflen)) // Non-blocking
  {
    Trigger = buf;
    Serial.println(Trigger);
  }
    if(Trigger == 66)     //ASCII for B, 066
    {
      digitalWrite(LED_BUILTIN, HIGH);
    }
   else
   {
     digitalWrite(LED_BUILTIN, LOW);
   }
}

You should use character literals in C, it's more self descriptive:

    if(Trigger == 'B')