Let's Make Robots!

Question about sending integers using virtualwire.

// Tested with IDE 20 and VirtualWire 1.4, only working with those.
// RF Link using VirtualWire to Transmit messages
// simplex (one-way) receiver with a 315MHz RF Link Transmitter module
// tx pin 3 on Duemilanova (arduino)
//vw_setup(300) works 
//vw_setup(2400) works
//vw_setup(4800) works
double dewPointFast(double celsius, double humidity) //calculate tbe dewpoint
	double a = 17.271;
	double b = 237.7;
	double temp = (a * celsius) / (b + celsius) + log(humidity/100);
	double Td = (b * temp) / (a - temp);
	return Td;

#include   //include the library
#define DHT11PIN 2   //set where the DATA-Pin is connected to
#include   // you must download and install the VirtualWire.h to your hardware/libraries folder
#undef int
#undef abs
#undef double
#undef float
#undef round
dht11 DHT11;

void setup()
     // Initialise the IO and ISR
    vw_set_ptt_inverted(true); // Required for RF Link module
    vw_setup(4800);                 // Bits per sec
    vw_set_tx_pin(3);                // pin 3 is used as the transmit data out into the TX Link module, change this to suit your needs. 


void loop()
  int chk = DHT11.read(DHT11PIN);  // Data I get from my Sensor, these are ints
  const char *c = "Hello my friends.";   //with this one it works.
   vw_send((uint8_t *)c, strlen(c));   // Now, I would like to send the int chk from the upper part
   vw_wait_tx();                                          // Wait for message to finish
Is it possible to send int with VirtualWire and also 16bit int?
I am always using: vw_send((uint8_t *)msg, strlen(msg)); and msg is a message (string). So i would like to send:
int chk = DHT11.read(DHT11PIN); 
DHT11.read(DHT11PIN); is the data i get from my sensor(DHT11)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
You face a int to byte array problem. The vw_send takes two parameters. The first one is a byte array. The second one is the size of that byte array. To send 16 bit int as a byte array you need two bytes since one byte has 8 bits. Now bit-shifting is your friend. Can you work from there? And: are you expecting to have negative numbers? If so make shure you get the shifting right.

Maybe you can post the correct code... I am not shure what you mean. Thanks

:-) next time I have this setup in front of me i'll do that. Look for HighByte and LowByte and Arduino.