Hello together.
I have a strange problem at the moment and hope you can help me.
I just build a little weather station (actually just a project to play around with all the stuff). Therefore I solder a breadboard arduino to a board.
Here is what I have:
- Atmega 328p-PU (16MHz crystal)
- NRF24L01 (with an AMS1117 5V to 3.3V regulator)
- DHT22 to measure the temp and humidity
- Photocell to measure the light
- 6x AA battery holder
The NRF24L01 is sending the sensor data to an RPi. This part works very well now. But the DHT22 is giving most of the time a NAN. I thought already that I damaged the sensor while soldering. But then values came... and after NAN again. So it came out that sometimes the sensor is giving values and sometimes not (always either no value for temp and humidity or it gives both values).
And there is another strange thing. I also want to add a 'flame sensor' (this dark LED). It's not soldered yet in the circuit, but already in the code. And this A1 Pin gives me a value. And not just a constant value... its changing. (The photocell is on A0) How can this be? Where is this value coming from?
My current code:
#include <JeeLib.h>
#include <DHT.h>
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#define DHTPIN 7
#define DHTTYPE DHT22 //DHT11, DHT21, DHT22
DHT dht(DHTPIN, DHTTYPE);
String writestring;
int led = 8;
int flameled = A1;
int lightsensor = A0;
//for nrf24 debug
int serial_putc( char c, FILE * )
{
Serial.write( c );
return c;
}
//for nrf24 debug
void printf_begin(void)
{
fdevopen( &serial_putc, 0 );
}
//nRF24 set the pin 9 to CE and 10 to CSN/SS
// Cables are:
// SS -> 10
// MOSI -> 11
// MISO -> 12
// SCK -> 13
RF24 radio(9, 10);
//we only need a write pipe, but am planning to use it later
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
// here we can send up to 30 chars
char SendPayload[31] = "";
ISR(WDT_vect) { Sleepy::watchdogEvent(); } // Setup the watchdog
void setup(void) {
Serial.begin(9600); //Debug
printf_begin();
//nRF24 configurations
radio.begin();
radio.setChannel(0x4c);
radio.setAutoAck(1);
radio.setRetries(15, 15);
radio.setDataRate(RF24_250KBPS);
radio.setPayloadSize(32);
radio.openReadingPipe(1, pipes[0]);
radio.openWritingPipe(pipes[1]);
radio.startListening();
radio.printDetails(); //for Debugging
//pinMode(led, OUTPUT);
dht.begin(); //DHT22 start
}
void loop() {
writestring = "1;"; //Kennung des Arduino
//digitalWrite(led, HIGH); // LED an
//TEMP SENSOR
float h = dht.readHumidity(); //Luftfeuchte auslesen
float t = dht.readTemperature(); //Temperatur auslesen
writestring += t;
writestring += ";";
writestring += h;
writestring += ";";
//Fame sensor
int IRvalue = analogRead(flameled);
writestring += IRvalue;
writestring += ";";
//Light sensor
unsigned int Lightvalue = analogRead(lightsensor);
writestring += Lightvalue;
writestring += ";";
//HERE WE SEND THE DATA TO THE PI
//Serial.println(writestring);
writestring.toCharArray(SendPayload,31);
Serial.println(SendPayload);
// Assign distance to payload, here am sending it as string
//dtostrf(distance, 2, 2, SendPayload);
//add a tag
//strcat(SendPayload, "X"); // add first string
//send a heartbeat
radio.stopListening();
bool ok = radio.write(&SendPayload, strlen(SendPayload));
if (ok)
printf("ok...");
else
printf("failed.\n\r");
radio.startListening();
//Serial.println(SendPayload);
//Sleepy::loseSomeTime(1000);
//digitalWrite(led, LOW); // LED aus
Sleepy::loseSomeTime(30000);
}
Hope you can help me. Thanks.
Cheers
Gordon