Hello fellow Ardiuniers,
I'am having trouble getting a PCD8544 and a NRF2401 working together.
The idea is to have a sender transmitting temperature values by NRF2401. The receiver will display the received values on a Nokia5110 display.
When i'am using the "PCD8544" (sketch is not included) library the values are received correctly. But whem i'am using the "ADAFruit-PCD8544" library together with the "ADAFruit-GFX" library, then there are no values being received. I want to use the ADAFruit libs so i can plot a histogram of the temperature.
Please be gentle with me, i'am absolutely not a programmer, the code has most of the part been borrowed
I hope you can help me out with this one...
Here is the code for the receiver
(the transmitter follows in a seperate post)
//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
return 1.8 * celsius + 32;
}
// fast integer version with rounding
//int Celcius2Fahrenheit(int celcius)
//{
// return (celsius * 18 + 5)/10 + 32;
//}
//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
return celsius + 273.15;
}
// dewPoint function NOAA
// reference: http://wahiduddin.net/calc/density_algorithms.htm
double dewPoint(double celsius, double humidity)
{
double RATIO = 373.15 / (273.15 + celsius); // RATIO was originally named A0, possibly confusing in Arduino context
double SUM = -7.90298 * (RATIO - 1);
SUM += 5.02808 * log10(RATIO);
SUM += -1.3816e-7 * (pow(10, (11.344 * (1 - 1/RATIO ))) - 1) ;
SUM += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO - 1))) - 1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM - 3) * humidity;
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558 - T);
}
// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
double a = 17.271;
double b = 237.7;
double temp = (a * celsius) / (b + celsius) + log(humidity/100);
double Td = (b * temp) / (a - temp);
return Td;
}
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
#include <OneWire.h>
//#include <DallasTemperature.h>
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 10
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(3, 4, 5, 7, 6);
#define Backlight_Pin 8
int msg[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int lastmsg = 1;
String theMessage = "";
int messageLength = 0; // voor checksum of complete bericht binnen is.
int berichtLengteInt;
int teller;
int dht11_temperatureInteger;
int dht11_humidityInteger;
String berichtLengte, berichtDecoded, berichtDecodedB1, berichtDecodedB2;
String berichtID, berichtValue1, berichtValue2;
void setup()
{
Serial.begin(9600);
// Nokia 5110 display
display.begin();
// you can change the contrast around to adapt the display
// for the best viewing!
display.setContrast(50);
pinMode(Backlight_Pin, OUTPUT);
pinMode(0, INPUT);
//Serial.print("Backlight ");
//Serial.println(analogRead(0));
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println("Ready");
display.display();
// nrf2401
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
}
float dht11_temperature = 0;
float dht11_humidity = 0;
float ds18b20_temperature = 0;
#define TEMP_SIZE LCDWIDTH
//float temp[TEMP_SIZE] = {0.0};
float temp[TEMP_SIZE] = {0};
int temp_pos = 0; // position in circular buffer above
void loop()
{
//Serial.println("\n");
if (radio.available()){
bool done = false;
done = radio.read(msg, 1);
char theChar = msg[0];
berichtLengte = theMessage.substring(0,(theMessage.indexOf(" "))); // get the first character up to the space separator and save it to bericht array
berichtLengteInt = (berichtLengte.toInt());
// bericht tekst "uitlezen", alles vanaf de spatie - "hok 8 44"
berichtDecoded = theMessage.substring(theMessage.indexOf(" ")+1); // get the characters from space separator up the end of the string and save it to berichtDecoded array
// bericht tekst "uitlezen", alles vanaf de spatie gezien vanaf variable "berichtDecoded", dus eigenlijk 2e spatie van het bericht
// "8 44"
berichtDecodedB1 = berichtDecoded.substring(berichtDecoded.indexOf(" ")+1);
berichtDecodedB2 = berichtDecodedB1.substring(berichtDecodedB1.indexOf(" ")+1); // volgende spatie (humidity)
berichtID = berichtDecoded.substring(0,(berichtDecoded.indexOf(" ")));
// eerste getal in de string (temperatuur)
// "8"
berichtValue1 = berichtDecodedB1.substring(0,(berichtDecodedB1.indexOf(" ")));
berichtValue2 = berichtDecodedB2.substring(0,(berichtDecodedB2.indexOf(" ")));
/*
Error checking part
Wanneer de uitgelezen berichtlengte gelijk is aan de lengte van het bericht, dan is het bericht goed
*/
if (msg[0] != 2){
theMessage.concat(theChar);
// gaat niet goed, checksum klopt niet!
}
else {
if (theMessage.length() == berichtLengteInt) {
// lcd.println(theMessage); // gaat goed, checksum klopt!
dht11_humidityInteger = (berichtValue1.toInt()); // convert the string to integer and save it to variable berichtMeting
double dht11_humidity = dht11_humidityInteger; // convert int to float, anders zie je de waarde niet op LCD!!!!
int chk = random(10, 20);
//dht11_humidity = random(50, 70);
//Serial.print("Humidity (%): ");
//Serial.println(dht11_humidity, 2);
// dht11_temperature = random(10, 25); voor testen zonder sensor
dht11_temperatureInteger = (berichtValue1.toInt()); // convert the string to integer and save it to variable berichtMeting
float dht11_temperature = dht11_temperatureInteger; // convert int to float, anders zie je de waarde niet op LCD!!!!
//dht11_temperature = 8;
//Serial.print("Temperature for the device 1 (index 0) is: ");
ds18b20_temperature = random(10, 20);
//Serial.println(ds18b20_temperature);
temp[temp_pos] = ds18b20_temperature;
display.clearDisplay();
display.setCursor(0,0);
display.print(dht11_temperature, 0);
//display.print(10, 0);
display.print("C ");
display.print(dht11_humidity, 0);
display.print("% ");
display.print(ds18b20_temperature, 2);
display.print("C");
float min = temp[0], max = temp[0];
for(int i = 0; i < TEMP_SIZE; i++) {
// Serial.print(temp[i]);
// Serial.print(" ");
if (temp[i] < min && temp[i] > 0) min = temp[i];
if (temp[i] > max) max = temp[i];
}
// draw right to left so most recent value is on the right
for(int x = TEMP_SIZE - 1; x >= 0; x--) {
int pos = ( x + temp_pos + 1 ) % TEMP_SIZE;
if ( temp[pos] > 0 ) {
int y = ( ( temp[pos] - min ) / ( max - min ) ) * ( LCDHEIGHT - 10 );
display.drawLine(x, LCDHEIGHT - y, x, LCDHEIGHT, BLACK);
// display.drawPixel(x,y + 10, BLACK);
// Serial.print(temp[pos],2);
// Serial.print(" ");
}
}
//Serial.println();
// refresh LCD
display.display();
// pulse display backlight
int backlight = 0;
float old_temp = temp[(temp_pos + TEMP_SIZE - 1) % TEMP_SIZE];
if ( ds18b20_temperature < old_temp ) {
backlight = 32;
} else if ( ds18b20_temperature > old_temp ) {
backlight = 255;
}
analogWrite(Backlight_Pin, backlight);
delay(2000);
// move slot in circular bugger
if ( ++temp_pos > TEMP_SIZE ) temp_pos = 0;
}
}
theMessage= "";
}
}
// END OF FILE
//