I am working on a wireless network using Arduinos connected to NRF24 modules, these are communicating with a esp8266 which is sending the sensor data to the Blynk server.
I can get the data on the Blynk app to work perfectly with only one sensor reading represented by a virtual pin, if I add a second then the signials occasionally get mixed up and I will get values from V0 on the V1 wiget in the app, if I add a third then things get really messed up.
I am wondering the best way to take multiple analog readings on a virtual pin and send them to the app.
The problem may be between the NRF24l01 modules, any input would be great thank you.
Here is the Transmitter code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN
const byte addresses [][6] = {"00001", "00002"}; //Setting the two addresses. One for transmitting and one for receiving
int led = 3;
int moisture = A3;
int gTemp = A0;
int gTempON = 5;
void setup()
{
pinMode(led, OUTPUT);
pinMode(gTempON, OUTPUT);
Serial.begin(9600);
radio.begin(); //Starting the radio communication
radio.openWritingPipe(addresses[0]); //Setting the address at which we will send the data
radio.openReadingPipe(1, addresses[1]); //Setting the address at which we will receive the data
radio.setPALevel(RF24_PA_MAX); //You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
}
void loop()
{
int V = readVcc();
digitalWrite(gTempON, HIGH);
int gTempRAW = analogRead(gTemp);
int gTempC = map(gTempRAW,266 ,591 ,0 ,36);
float gTempF = (gTempC * 1.8) +32;
digitalWrite(gTempON, LOW);
int value = analogRead(moisture);
int val = map(value, 460, 860, 100, 0);
radio.stopListening();
radio.write(&gTempF, sizeof(gTempF));
radio.write(&val, sizeof(val));
radio.write(&V,sizeof(V));
}
long readVcc()
{
long result; // Read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = 1126400L / result; // Back-calculate AVcc in mV
return result;
}
Here is the Reciever:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN
const byte addresses [][6] = {"00001", "00002"}; //Setting the two addresses. One for transmitting and one for receiving
int led = 3;
int moisture = A3;
int gTemp = A0;
int gTempON = 5;
void setup()
{
pinMode(led, OUTPUT);
pinMode(gTempON, OUTPUT);
Serial.begin(9600);
radio.begin(); //Starting the radio communication
radio.openWritingPipe(addresses[0]); //Setting the address at which we will send the data
radio.openReadingPipe(1, addresses[1]); //Setting the address at which we will receive the data
radio.setPALevel(RF24_PA_MAX); //You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
}
void loop()
{
int V = readVcc();
digitalWrite(gTempON, HIGH);
int gTempRAW = analogRead(gTemp);
int gTempC = map(gTempRAW,266 ,591 ,0 ,36);
float gTempF = (gTempC * 1.8) +32;
digitalWrite(gTempON, LOW);
int value = analogRead(moisture);
int val = map(value, 460, 860, 100, 0);
radio.stopListening();
radio.write(&gTempF, sizeof(gTempF));
radio.write(&val, sizeof(val));
radio.write(&V,sizeof(V));
}
long readVcc()
{
long result; // Read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = 1126400L / result; // Back-calculate AVcc in mV
return result;
}