floresta:
Why don't you modify the data when you save it instead of when you display it? Something like this:rawData = bme.readTemperature();
adjustedData = rawData - 1;
Serial.print(adjustedData);
display.print(adjustedData);
And yes, the 'adjustment' should be defined rather than hard coded as I have shown it. Don
Hi Don, I;ve played around with that code in various forms but I must be putting it in the incorrect place. Any chance you could help me place the code in the correct area? I defined it at the start of the code and then put the code in the oled display section.
Should I do something with the current 'getData' code?
// SimpleRx - the slave or the receiver
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeMono9pt7b.h>
#include "DHT.h"
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
//added for cal adjustment
#define rawData = bme.readTemperature();
#define adjustedData = rawData - 1;
//not all #defines used but here for documentation
#define CE_PIN 7
#define CSN_PIN 8
#define MOSI_PIN 11
#define MISO_PIN 12
#define SCK_PIN 13
const byte thisSlaveAddress[5] = {'R', 'x', 'A', 'A', 'A'};
RF24 radio(CE_PIN, CSN_PIN);
struct data
{
float temperature;
float humidity;
} receivedData;
bool newData = false;
void setup()
{
// initialize with the I2C addr 0x3C
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
delay(10);
// Clear the buffer.
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,12);
display.println("Booting");
display.display();
delay(50);
// Clear the buffer.
display.clearDisplay();
Serial.begin(9600);
Serial.println("SimpleRx Starting");
radio.begin();
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate( RF24_250KBPS );
radio.setChannel(124);
radio.openReadingPipe(1, thisSlaveAddress);
radio.startListening();
Wire.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);// initialize with the I2C addr 0x3C
}
void displayTempHumid(){
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
{
}
display.clearDisplay();
display.setTextColor(WHITE);
display.setFont(&FreeMono9pt7b); //added for font test
display.setCursor(4,13);
display.print("Temp:");
// display.print(adjustedData); //added for cali
display.print(receivedData.temperature,1);
//display.println(receivedData.temperature-1); //added for cali
// display.print(temperature -1); //added for cali
display.print(" C");
display.setCursor(4,28);
display.print("Humid:");
display.print(receivedData.humidity,1);
display.print("%");
display.drawRect(1, 1, display.width()-1, display.height()-1, WHITE); // draws the outer rectangular boundary on the screen
display.setTextColor(WHITE); // i have white OLED display, you can use other colors in case you have multicolored display
display.setTextSize(1); // i have used large font to display temperature, it can be varied as per your taste
display.setFont(); //added for font test
display.setCursor(107,2);
display.print("o"); // this prints the "o" symbol to show Degree
}
void loop()
{
getData();
showData();
displayTempHumid();
display.display();
}
void getData()
{
if ( radio.available() )
{
radio.read( &receivedData, sizeof(receivedData) );
newData = true;
}
}
void showData()
{
if (newData == true)
{
Serial.print("Data received\ttemperature : ");
// Serial.print(receivedData.temperature);
Serial.print(receivedData.temperature -1); //added cali THIS WPRKS, NEED OLED TO DISPLAY
Serial.print("\t");
Serial.print("humidity : ");
Serial.println(receivedData.humidity);
newData = false;
}
}[color=red][/color]