For my home project i would like to transmit temperature and humidity values.
I had some issues sending these values right after the other (where the 2nd value is lost most of the times). Both modules work properly, the "hello world" message is send and received.
Now to solve this issue i had an idea to combine the values in a String and send them but i failed doing that too. Only some weird symbols are transmitted.
Is it possible to send a String across this transmitter? or is there a way i can transmit the 2 values sequential consistently? If both are possible what would be the best solution.
U5ED:
Now to solve this issue i had an idea to combine the values in a String and send them but i failed doing that too. Only some weird symbols are transmitted.
just put the float in a structure and send the structure in binary form.
Don't try to send an instance that way (would need to serialize it). For example just for your information, check what sizeof returns on your String when you dosizeof(b)
By the way DO NOT use single character variable names other than as the index in a FOR loop because it would be impossible to find (for example) all the instances of a variable called 't' in a program. Use meaningful variable names such as "temperatureValue" and "humidityValue"
Thank you Robin2 for your help,
With your comment and tutorial i have gained more insight in these transmitters.
Although i have to admit it does not work as i hoped.
For some reason when i put the NRF in place the Serial.print stops updating on the transmitter side.
And on the receiver side it only displays 0.00 over and over.
But i have a hard time finding my mistake, and i hope you're or someone is able to help me.
void getData(){
if (radio.available()){
float dataToReceive[2];
dataToReceive[0] = temperatureValue; // <<==== where does this value come from?
dataToReceive[1] = humidityValue; // <<==== where does this value come from?
radio.write(&dataToReceive, sizeof(dataToReceive)); // <<==== ????
newData = true;
}
remember in the first code you were doing something like this when data was available: radio.read(&text, sizeof(text));what has changed? what should you be receiving?
J-M-L:
remember in the first code you were doing something like this when data was available:
radio.read(&text, sizeof(text));
what has changed? what should you be receiving?
I want to receive 2 values one temperature value (for example 15.45) and one humidity value (for example 50.64).
The text was partly for the text that i wanted to send, but i figured i could add that later on the receiver side.
My apologies, hereby the updated code.
When i test the transmitter (without the NRF) the serial.print returns the values but once i connect the NRF (reconnect usb as well) the serial.print does not return anything.
void getData(){
if (radio.available()){
float dataToReceive[2]; //declare a new variable that contains random data
dataToReceive[0] = temperatureValue; //put two variables set to zero when declared in the array
dataToReceive[1] = humidityValue;
radio.read(&dataToReceive, sizeof(dataToReceive)); //now get the real data
newData = true;
}
}
void showData(){
if (newData == true){
Serial.print(temperatureValue); //print the unchanged zero value of 2 variables
Serial.print("\t");
Serial.println(humidityValue);
newData = false;
}
}
Note my added comments
What you need to do is to receive the array then copy its 0 and 1 levels into the 2 variables before printing them, or don't bother copying them and just print them from the array
You can't just blindly cut & paste. Think about what you are writing, line by line. Otherwise you are just a parrot, repeating what you hear with no understanding.
Read that and imagine in your head what each line is doing, one line at a time. Then go back and read your code from before and imagine what that does, line by line. Explain to us why the former code was wrong, so we know you understand.
Thank you both for your help, it is working now. obviously :o ...
I don't know why but i was overthinking it .
In order to write something on the receiver side you first have to receive something. Only after this it can transfer the received array into the float variables.
UKHeliBob:
What you need to do is to receive the array then copy its 0 and 1 levels into the 2 variables before printing them, or don't bother copying them and just print them from the array