Sending Variables for weather station over Virtual Wire

I am trying to create a wireless weather station, but am having a lot of trouble with the virtual wire library. Whenever I try to use this program I get the error code:

expected primary-expression before ‘)’ token

on the line of:

vw_send(pressure,uint8_t);

If someone would please look at this code and tell me what I am doing wrong that would be very helpful. Also, I am a complete newbie and know next to nothing about C or Arduino coding, so heavy commenting would help me a lot.

#include <VirtualWire.h> // Library for radio transmitting
#include “cactus_io_BME280_I2C.h” // Library for BME280 Weather Sensor
#include <Wire.h>
int pressure = 0;
int humidity = 0;
int tempc = 0;
int temp = 0;
int pressurevalue = 0;
int humidityvalue = 0;
int tempvalue = 0; // Variables for the sensor values

BME280_I2C bme;

void setup() {
Serial.begin(9600);

pinMode(13,OUTPUT); // Testing Indicator setup
pinMode(12,OUTPUT); // Default transmitter pin

vw_setup(4000); // Radio Setup

if (!bme.begin()) {
Serial.println(“Could not find a valid BME280 sensor, check wiring!”);
while (1);
}

}

void loop() {

bme.readSensor();

pressure = bme.getPressure_MB();
humidity = bme.getHumidity();
temp = bme.getTemperature_F();
tempc = bme.getTemperature_C();

delay(500);

vw_send(temp,uint8_t);
delay(500);
vw_send(tempc,uint8_t);
delay(500);
vw_send(humidity,uint8_t);
delay(500);
vw_send(pressure,uint8_t);
delay(500);

}

P.S. If someone could roughly sketch a receiver code that would write the information to variables as well, I would appreciate it, Thanks.

 vw_send(pressure,uint8_t)

uint8_t is a variable type. It's not a variable name. You need to either give it the number of bytes or an actual variable holding the number of bytes there.

Delta_G:
You need to either give it the number of bytes or an actual variable holding the number of bytes there.

What exactly is the number of bytes, and where do you get that number?

wburns:
What exactly is the number of bytes, and where do you get that number?

The number of bytes you are trying to send. You get that by saying, "Hey, how many bytes am I trying to send with this transmission." Look at the thing you are sending. How many bytes is it?

Or I guess you could also call sizeof on whatever you intend to send before you send it. But for most cases you know how big the thing you're sending is.

Since the transmission is based on a variable, wouldn't that change the number of bytes with a different variable? If so is there an equation to calculate the bytes from the message?

Try something like this, convert the float to a char array and send that. BTW, you should use float for temperature, humidity etc as you would want the decimal places. For example:

float temperature = 22.55;
char toSend[6];
dtostrf(temperature, 5, 2, toSend);
toSend[5] = '\0';
vw_send((uint8_t *)toSend, strlen(toSend)+1); //+1 for null character

wburns:
Since the transmission is based on a variable, wouldn't that change the number of bytes with a different variable? If so is there an equation to calculate the bytes from the message?

No, because every variable has a defined type and therefore a defined size. The only time they're going to change is if you are using arrays that might have different numbers of elements. In that case sizeof can get how many bytes large they are.

Byork:
BTW, you should use float for temperature, humidity etc as you would want the decimal places.

The need for a decimal does not mean you want a float. Using a float is only necessary when you have large ranges of data to deal with. If you just want a decimal, you actually get better resolution and precision if you use a long or unsigned long and think in terms of fixed point math. A long has 9 digits of precision. A float can only do 6.

Delta_G:

 vw_send(pressure,uint8_t)

You need to either give it the number of bytes or an actual variable holding the number of bytes there.

could I just place a placeholder number like, say 100 bytes? would that cover everything or does it have to be a precise number?

No, you need to tell it actually how many bytes.

In your code pressure is an int. So it will always be 2 bytes.

Delta_G:
In your code pressure is an int. So it will always be 2 bytes.

So ints are always 2 bytes? If not then whenever the temp changes to triple digits or the humidity goes into single digits wouldn't the number of bytes change? I'm probably just being stupid at this point and have missed something someone said.

No an int is a 16bit (aka 2 bytes) variable that can hold any number between -32768 and 32767 inclusive. The number of digits when written in decimal doesn't matter unless you are trying to send it as a string which you aren't.

Or unsigned int for 0 to 65535. Useful when a number larger than 0 to 255 (byte) is needed.

Can you have negative pressure? 29.92 is standard pressure, lower for a storm (really low for a hurricane), higher for nice weather. Multiply by 100 and send as 2992.

Ok, so I’ve gotten to this point in my program:

#include"Arduino.h"
#include <VirtualWire.h>    // Library for radio transmitting
#include "cactus_io_BME280_I2C.h" // Library for BME280 Weather Sensor
#include <Wire.h> 
int pressure = 0;
int humidity = 0;
int tempc = 0;
int temp = 0;
int pressurevalue = 0;
int humidityvalue = 0;
int tempvalue = 0; // Variables for the sensor values

uint8_t bytes = 2;



BME280_I2C bme;

void setup() {
  Serial.begin(9600); 
  
  
   pinMode(13,OUTPUT);          // Testing Indicator setup
   pinMode(12,OUTPUT);          // Default transmitter pin for headsup
   
    vw_setup(4000);         // Radio Setup
    
    if (!bme.begin()) { 
Serial.println("Could not find a valid BME280 sensor, check wiring!"); 
while (1); 
} 

  Serial.println("Pressure\tHumdity\t\tTempC\tTempF"); 

}

void loop() {

  bme.readSensor();

  pressure = bme.getPressure_MB();
  humidity = bme.getHumidity();
  temp = bme.getTemperature_F();
  tempc = bme.getTemperature_C();

  

  delay(500);

  digitalWrite(12,HIGH);
  delay(10);
  digitalWrite(12,LOW);             // Gives Receiver "headsup"
                                    // so that it can be ready
                                    // to receive data 
  vw_send(temp,bytes);
  delay(500);
  vw_send(tempc,bytes);
  delay(500);
  vw_send(humidity,bytes);
  delay(500);
  vw_send(pressure,bytes);
  delay(500); 
 

 
}

I get that the number of bytes is two and it needs to be in that place, but now it is giving me the error code:

invalid conversion from ‘int’ to ‘uint8_t* {aka unsigned char*}’ [-fpermissive]

The question now is what is this applying to? I have changed the bytes to an uint8_t and have tried using the number 2 in the variables place, but that doesn’t seem to work. could this error code be talking about the pressure variable? I truly have no clue what I’m getting myself into.

Well, if you look at the reference for VirtualWire is says this for send()

vw_send(message, length)
Transmit a message. "message" is an array of the bytes to send, and "length" is the number of bytes stored in the array. This function returns immediately and the message is sent slowly by an interrupt-based background process.

So the function expects you to give it an array of bytes to send and the number of bytes, not an int and a number. So we have to make an array of two bytes that holds the two bytes in the int. OR we can lie to the compiler and pretend our int is in a byte array.

vw_send((uint8_t*)&pressure,bytes);

I believe that will work. It's something like it.

Or you can extract the bytes yourself.

uint8_t bytesArray[2];
bytesArray[0] = pressure >> 8;
bytesArray[1] = pressure & 0xFF;
vw_send(bytesArray,bytes);

Go to the Learning tab at the top of the screen and look at the reference section at the bitwise operators to see what I did there extracting two bytes from an int.

Thanks so much. The program is now compiling correctly, and I just have to wait and see if I can receive the variables I have sent. I have just one more question for now: Where did you find the reference for VirtualWire? I have heard it is well documented, but have not found any information about it. If I knew where it was that would definitely help in the future.

I just googled “Arduino Virtualwire” and one of the top few links had a full ref to the library.