Hi all
Hope someone can help as this is doing my nut in.
So I decided on a humidity/temp sensor for my garden along with a pool temperature probe.
That all works great, I can even get it into a very low power mode, which again is great as I wanted to be able to leave this in the garden for months/years on a set of batteries.
The problem comes when I add in the NRF2401 Wireless Transmitter.
Now I have been playing with these before and it all worked grand, I`m loading up a similar sketch and it just does not work, I think I isolated the problem but cant work out why its causing an issue as its actually needed.
I have the code turn on pins 3,4 and 5 and they supply the power to the sensors and RF TX, and switch off again when the readings have been read and sent over the TX.
At least that`s the theory, if you look down near the bottom of the code I have the transmit data
//transmit.write(&data, sizeof(data));
If I un-comment it, nothing is sent obviously but more importantly the sensors stop reading and nothing is updated, its like this line of code is freezing the rest, but I have no idea why.
Any help in identiying the issue greatfully appreciated.
Cheers Alan
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h> // RF Library
#include <RF24_config.h>#include <OneWire.h>
#include <DallasTemperature.h> // Pool Sensor
#include "Seeed_BME280.h" // BME280 Library
#include "LowPower.h"
#include <avr/power.h>
#include <avr/sleep.h>
#define DATA_PIN 2
#define SENSOR_RESOLUTION 12
#define SENSOR_INDEX 0
OneWire oneWire(DATA_PIN);
DallasTemperature sensors(&oneWire);
DeviceAddress sensorDeviceAddress;
BME280 bme280;
RF24 transmit (7, 10); //create RF24 object called transmit
byte address [5] = "00001"; //set address to 00001
struct package
{
float temperature = 0;
float humidity = 0;
float pool = 0;
};
typedef struct package Package;
Package data;
void setup() {
pinMode(3, OUTPUT); // pool sensor
pinMode(4, OUTPUT); // NRF TX
pinMode(5, OUTPUT); // BME280
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
Serial.begin(9600);
bme280.init();
sensors.begin();
sensors.getAddress(sensorDeviceAddress, 0);
sensors.setResolution(sensorDeviceAddress, SENSOR_RESOLUTION);
transmit.begin();
transmit.openWritingPipe(address); //open writing pipe to address 00001
transmit.setPALevel(RF24_PA_MIN); //set RF power output to maximum
transmit.setDataRate(RF24_250KBPS); //set datarate to 250kbps
transmit.setChannel(100); //set frequency to cdata.data.data.humidityumidityumidityannel 100
transmit.stopListening();
}
void loop() {
pinMode(3, OUTPUT); // pool sensor
pinMode(4, OUTPUT); // NRF TX
pinMode(5, OUTPUT); // BME280
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
sensors.requestTemperatures();
float temperatureInCelsius = sensors.getTempCByIndex(SENSOR_INDEX);
data.temperature = bme280.getTemperature();
data.humidity = bme280.getHumidity();
data.pool = sensors.getTempCByIndex(SENSOR_INDEX);
Serial.print("Pool: ");
Serial.print(temperatureInCelsius, 2);
Serial.print("C ");
Serial.println();
Serial.println();
Serial.print("Temp: ");
Serial.print(bme280.getTemperature());
Serial.println("C");
Serial.println();
Serial.print("Humidity: ");
Serial.print(bme280.getHumidity());
Serial.println("%");
Serial.println();
//transmit.write(&data, sizeof(data));
delay(2000);
pinMode(3, INPUT); // pool sensor
pinMode(4, INPUT); // NRF TX
pinMode(5, INPUT); // BME280
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
delay(2000);
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}