Hi all,
I am working on a AWS (Automatic Weather Station). Data is collected on site and then transmitted via a nRF24L01 to home base about 200 meters away.
I spent a fair bit of time setting up both nRF24L01 transmitter and receiver and got it nicely working.
However, so far I have only sent fixed values in a struct array and it works great.
Now I'm coming to the point that I want to read a sensor; put the reading in a variable and then transmit that variable to the receiver and this got me stumped.
The code compiles nicely but on the receiver end I can only see "0" as a value. all the other static values arrive in good order.
Here is my transmitter code (I have simplified the code to make it more readable):
/* nRF24L01 Transmitter code*/
#include <SPI.h>
#include <RF24.h>
int LDRvalue;
RF24 radio(9, 10); // CE, CSN
byte addresses[][6] = {"0"}; //Identify the transmitting and receiving bit
struct package
{int LDR = LDRvalue; float hum = 99.9; float DP2 = 99.9;};
typedef struct package Package;
Package data;
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void setup() {
Serial.begin(9600);
radio.begin(); // Initiate the radio object
radio.setChannel(124); // 0 to 124, frequencies between 2.4 and 2.5 Ghz in chunks of 100 MHz. Use a channel unlikely to be used by Wifi, Microwave ovens etc
radio.setPALevel(RF24_PA_MIN); // Set the transmit power to lowest available to prevent power supply related issues, can also be set to MAX
radio.setDataRate(RF24_2MBPS); // Set the speed of the transmission to the quickest available, can be set to 250KB or 1MBPS to increase range
radio.openWritingPipe(addresses[0]); // Open a writing and reading pipe on each radio, with opposite addresses
}
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void loop() {
LDRvalue = analogRead(A0);
Serial.println(LDRvalue);
radio.write( &data, sizeof(data));
delay(1000);
}
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
So basically I'm reading the value of an LDR sensor at pin A0. This is then stored as an integer variable and then I want to include the variable in the struct so that it can be transmitted to the receiver.
But no matter how hard I try I cannot have it working.
Any tips/ideas will be much appreciated. Also, does anybody know a good reference where I can familiarize myself with the struct command? (Sorry but the reference at arduino.cc is pretty much useless).
I am aware about the maximum size of 32 bytes that can be transmitted at once. So, the program is set up so that I can create multiple packages and send them individually.
Cheers!
Luc