Problems with Virtual Wire

Hello Everybody,

I want to transmit some measured Values via 433MHZ transmitter and receiver from one Arduino nano to the other.
For testing purpose I am using fixed Values. I can transmit these values but now I need to split the received data into 8 values.
And I dont know how to split these values.
This is what I receive in the Serial Monitor:

100|101|102|103|110|111|112|113x

I want to use | to split the values and the x indicated the end of the transmitted data

Transmitter Script

#include <VirtualWire.h>

#undef int
#undef abs
#undef double
#undef float
#undef round
char buf[30];
byte A1 = 100;
byte B = 101;
byte C = 102;
byte D = 103;
byte E = 110;
byte F = 111;
byte G = 112;
byte H = 113;

void setup()
{
vw_set_ptt_inverted(true);
vw_setup(2000);
vw_set_tx_pin(7);
Serial.begin(9600);
}

void loop()
{
sprintf(buf,"%d|%d|%d|%d|%d|%d|%d|%dx" ,A, B, C, D, E, F, G, H);
send(buf);
delay(200);
}

void send (char *message)
{
vw_send((uint8_t *)message, strlen(message));
vw_wait_tx();
}

Receiver Script

#include <VirtualWire.h>

#undef int
#undef abs
#undef double
#undef float
#undef round

void setup()
{
Serial.begin(9600);
vw_set_ptt_inverted(true);
vw_setup(2000);
vw_set_rx_pin(8);
vw_rx_start();
}

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

if (vw_get_message(buf, &buflen))
{
int i;
for (i = 0; i < buflen; i++)
{
Serial.print((char)buf*);*

  • }*
  • Serial.println("");*
  • } *
    }
    [/quote]

You could do worse than read up on the strtok function (although for the Arduino I believe it's called strtok_r as it is "re-entrant safe", like that's going to bother you!).

Plenty of examples in this forum and on the 'net. I hope this points you in a positive direction :)

No one uses a text string to transmit binary data. Use an array of bytes or integers or floats, or a struct or union. What is the maximum size for VirtualWire ? I forgot what it was, was it about 28 bytes ? You transmit more.

What is this?

#undef int
#undef abs
#undef double
#undef float
#undef round

I have seen that before, but I don't understand it. If you don't understand it as well, I suggest to remove it.

Koepel: No one uses a text string to transmit binary data. Use an array of bytes or integers or floats, or a struct or union. What is the maximum size for VirtualWire ? I forgot what it was, was it about 28 bytes ? You transmit more.

What is this?

#undef int
#undef abs
#undef double
#undef float
#undef round

I have seen that before, but I don't understand it. If you don't understand it as well, I suggest to remove it.

Sorry this is from an sample I found in the internet. How should I do this with an array?

// create an array of bytes
byte myData[8];

// fill it with data
myData[0] = 100;
myData[1] = 101;
myData[2] = 150;

// transmit it
// Use 8 for size, or sizeof(myData)
vw_send((uint8_t *) myData, sizeof(myData));

// receive it
// Use the 'buf' directly or copy it in a myData array
if (vw_get_message(buf, &buflen))
{
  for (int i = 0; i < buflen; i++)
  {
    Serial.print( buf[i]);
    Serial.print( ", ");
  }
  ...