Waveshare E-ink not able to show BME280 sensor readings

Hi there, I need some help.
I'm trying to get the readings of the BME280 to show on the Waveshare 1.54inch v2 b/w display.
So far I was able to connect both display and BME280 sensor to my Arduino nano 33 iot with ISP communication and I'm getting text on the display and the sensor readings in my serial monitor, but I'm not able to get the code for floating numbers running.

attached is the code so far...

#include <SPI.h>
#include "epd1in54_V2.h"
#include "imagedata.h"
#include "epdpaint.h"
#include <stdio.h>

#include <Wire.h> //BME280
#include <Adafruit_Sensor.h> //BME280
#include <Adafruit_BME280.h> //BME280

#define BME_SCK 13 //BME280
#define BME_MISO 12 //BME280
#define BME_MOSI 11 //BME280
#define BME_CS 6 //BME280

#define SEALEVELPRESSURE_HPA (1013.25) //BME280

Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

Epd epd;
unsigned char image[1024];
Paint paint(image, 0, 0);

unsigned long time_start_ms;
unsigned long time_now_s;
#define COLORED     0
#define UNCOLORED   1


unsigned long delayTime;

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("e-Paper init and clear");
  epd.LDirInit();
  epd.Clear();

  
  paint.SetWidth(200);
  paint.SetHeight(24);

  Serial.println("e-Paper paint");
  paint.Clear(UNCOLORED);

  
  epd.SetFrameMemory(paint.GetImage(), 0, 40, paint.GetWidth(), paint.GetHeight());
  paint.Clear(UNCOLORED);
  paint.DrawStringAt(8, 4, "TEMPERATURE", &Font16, COLORED);
  epd.SetFrameMemory(paint.GetImage(), 0, 60, paint.GetWidth(), paint.GetHeight());
  paint.Clear(UNCOLORED);
  paint.DrawStringAt(8, 4, "HUMIDITY", &Font16, COLORED);
  epd.SetFrameMemory(paint.GetImage(), 0, 80, paint.GetWidth(), paint.GetHeight());
  paint.Clear(UNCOLORED);
  paint.DrawStringAt(8, 4, "PRESSURE", &Font16, COLORED);
  epd.SetFrameMemory(paint.GetImage(), 0, 100, paint.GetWidth(), paint.GetHeight());
  paint.Clear(UNCOLORED);
  paint.DrawStringAt(8, 4, "HEIGHT", &Font16, COLORED);
  epd.SetFrameMemory(paint.GetImage(), 0, 120, paint.GetWidth(), paint.GetHeight());
  paint.Clear(UNCOLORED);

  epd.DisplayFrame();
  delay(2000);




  //Serial.println("e-Paper clear and goto sleep");
  //epd.HDirInit();
  //epd.Clear();
  //epd.Sleep();
  while(!Serial);    // time to get serial running
  Serial.println(F("BME280 test"));  //BME280

  unsigned status; //BME280

  status = bme.begin(); 

 
    
    Serial.println("-- Default Test --");
    delayTime = 1000;

    Serial.println();

    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" °C");

    Serial.print("Pressure = ");

    Serial.print(bme.readPressure() / 100.0F);
    Serial.println(" hPa");

    Serial.print("Approx. Altitude = ");
    Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
    Serial.println(" m");

    Serial.print("Humidity = ");
    Serial.print(bme.readHumidity());
    Serial.println(" %");

    Serial.println();
    
}

void loop(){
}


void printValues(){
}

It would be nice if someone knows the correct lines to add to the code so i can display the temperature, humidity, pressure and approximate height.
I also tried to use the Adafruit_GFX.h and Adafruit_SSD1306.h library, but without succes.

Welcome to the forum

Are you able to display fixed text ?

Yes, I am able to see the text as stated in the code. The BME280 is also working fine at the same moment, but I do not know how to add the BME reading on the display.

So, i'm one step further and used the dtostrf to get the floating number on my display. This worked so i thought i can now add the float temp = bme.readTemperature(); in the code to acctually read and write the temperature. It is only printing 0.0 on the display while it is printing the correct teperature in the serial monitor.
Can someone tell me what i'm missing?`

#include <SPI.h>
#include "epd1in54_V2.h"
#include "imagedata.h"
#include "epdpaint.h"
#include <stdio.h>
#include <stdlib.h>
#include <avr/dtostrf.h>

//#include <Wire.h> //BME280 not necessary!
#include <Adafruit_Sensor.h> //BME280
#include <Adafruit_BME280.h> //BME280

#define BME_SCK 13 //BME280
#define BME_MISO 12 //BME280
#define BME_MOSI 11 //BME280
#define BME_CS 6 //BME280

#define SEALEVELPRESSURE_HPA (1013.25) //BME280

Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

Epd epd;
unsigned char image[1024];
Paint paint(image, 0, 0);

//nsigned long time_start_ms;
//unsigned long time_now_s;
#define COLORED     0
#define UNCOLORED   1

unsigned long delayTime;


char buff[10];
float temp = bme.readTemperature();


void setup()
{
  dtostrf(temp,8,1,buff); 
  // put your setup code here, to run once:
  Serial.begin(115200);
  //Serial.println("e-Paper init and clear");
  
 
 
  epd.LDirInit();
  epd.Clear();
 
  
  paint.SetWidth(200);
  paint.SetHeight(24);

  //Serial.println("e-Paper paint");

  paint.Clear(UNCOLORED);
  
  paint.DrawStringAt(8,4,buff,&Font20,COLORED);
  epd.SetFrameMemory(paint.GetImage(), 0, 140, paint.GetWidth(), paint.GetHeight());
  paint.Clear(UNCOLORED);

  epd.SetFrameMemory(paint.GetImage(), 0, 40, paint.GetWidth(), paint.GetHeight());
  paint.Clear(UNCOLORED);
  paint.DrawStringAt(8, 4, "TEMP", &Font20, COLORED);
  epd.SetFrameMemory(paint.GetImage(), 0, 60, paint.GetWidth(), paint.GetHeight());
  paint.Clear(UNCOLORED);
  paint.DrawStringAt(8, 4, "HUMI", &Font20, COLORED);
  epd.SetFrameMemory(paint.GetImage(), 0, 80, paint.GetWidth(), paint.GetHeight());
  paint.Clear(UNCOLORED);
  paint.DrawStringAt(8, 4, "PRES", &Font20, COLORED);
  epd.SetFrameMemory(paint.GetImage(), 0, 100, paint.GetWidth(), paint.GetHeight());
  paint.Clear(UNCOLORED);
  paint.DrawStringAt(8, 4, "ALTI", &Font20, COLORED);
  epd.SetFrameMemory(paint.GetImage(), 0, 120, paint.GetWidth(), paint.GetHeight());
  paint.Clear(UNCOLORED);

  
  epd.DisplayFrame();
  delay(2000);

  //Serial.println("e-Paper clear and goto sleep");
  //epd.HDirInit();
  //epd.Clear();
  //epd.Sleep();
  while(!Serial);    // time to get serial running
  //Serial.println(F("BME280 test"));  //BME280

  unsigned status; //BME280

  status = bme.begin(); //BMW280

 
    
    //Serial.println("-- Default Test --");
    delayTime = 1000;

    //Serial.println();

    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" °C");

    Serial.print("Pressure = ");

    Serial.print(bme.readPressure() / 100.0F);
    Serial.println(" hPa");

    Serial.print("Approx. Altitude = ");
    Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
    Serial.println(" m");

    Serial.print("Humidity = ");
    Serial.print(bme.readHumidity());
    Serial.println(" %");

    //Serial.println();
    
}

void loop(){
}

I finally got the code to read and write the correct values from the BME280 and if the reading and writing is in the void setup, so only runs one time. But this seems to work.
If I place the reading and writing code lines in the void loop, unfortunately only the first reading and writing is correct whereafter the data is errored. So the temperature drops to -144,02C, the humidity is 0,0% and the pressure is also rubbish.
I will attache the two different codes, so if anyone has an idea?

'''
#include <SPI.h>
#include "epd1in54_V2.h"
#include "imagedata.h"
#include "epdpaint.h"
#include <stdio.h>
#include <stdlib.h>
#include <avr/dtostrf.h>
#include <Adafruit_Sensor.h> //BME280
#include <Adafruit_BME280.h> //BME280

#define BME_SCK 13 //BME280
#define BME_MISO 12 //BME280
#define BME_MOSI 11 //BME280
#define BME_CS 6 //BME280

#define SEALEVELPRESSURE_HPA (1013.25) //BME280

Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

Epd epd;
unsigned char image[1024];
Paint paint(image, 0, 0);

#define COLORED     0
#define UNCOLORED   1

unsigned long delayTime;

char temp[20];
char humi[20];
char pres[20];
char alti[20];

void setup()
{
  
  // put your setup code here, to run once:
  Serial.begin(115200);
  //Serial.println("e-Paper init and clear");
  //Serial.println("e-Paper clear and goto sleep");
  //epd.HDirInit();
  //epd.Clear();
  //epd.Sleep();
  while(!Serial);    // time to get serial running
  //Serial.println(F("BME280 test"));  //BME280

  unsigned status; //BME280

  status = bme.begin(); //BMW280

 
    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" °C");

    Serial.print("Pressure = ");
    Serial.print(bme.readPressure() / 100.0F);
    Serial.println(" hPa");

    Serial.print("Approx. Altitude = ");
    Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
    Serial.println(" m");

    Serial.print("Humidity = ");
    Serial.print(bme.readHumidity());
    Serial.println(" %");


  float tempValue = bme.readTemperature();
  dtostrf(tempValue,4,2,temp);
  float humiValue = bme.readHumidity();
  dtostrf(humiValue,4,2,humi);
  float presValue = bme.readPressure() / 100.0F;
  dtostrf(presValue,4,2,pres);
  float altiValue = bme.readAltitude(SEALEVELPRESSURE_HPA);
  dtostrf(altiValue,6,2,alti);

  epd.LDirInit();
  epd.Clear();
 
  
  paint.SetWidth(200);
  paint.SetHeight(24);

  paint.Clear(UNCOLORED);
  paint.DrawStringAt(4, 4, "TEMP", &Font20, COLORED);
  paint.DrawStringAt(100, 4, temp, &Font20, COLORED);
  paint.DrawStringAt(170, 4, "C", &Font20, COLORED);
  epd.SetFrameMemory(paint.GetImage(), 0, 20, paint.GetWidth(), paint.GetHeight());

  paint.Clear(UNCOLORED);
  paint.DrawStringAt(4, 4, "HUMI", &Font20, COLORED);
  paint.DrawStringAt(100, 4, humi, &Font20, COLORED);
  paint.DrawStringAt(170, 4, "%", &Font20, COLORED);
  epd.SetFrameMemory(paint.GetImage(), 0, 60, paint.GetWidth(), paint.GetHeight());

  paint.Clear(UNCOLORED);
  paint.DrawStringAt(4, 4, "PRES", &Font20, COLORED);
  paint.DrawStringAt(70, 4, pres, &Font20, COLORED);
  paint.DrawStringAt(170, 4, "Pa", &Font20, COLORED);
  epd.SetFrameMemory(paint.GetImage(), 0, 100, paint.GetWidth(), paint.GetHeight());

  paint.Clear(UNCOLORED);
  paint.DrawStringAt(4, 4, "ALTI", &Font20, COLORED);
  paint.DrawStringAt(80, 4, alti, &Font20, COLORED);
  paint.DrawStringAt(170, 4, "m", &Font20, COLORED);
  epd.SetFrameMemory(paint.GetImage(), 0, 140, paint.GetWidth(), paint.GetHeight());


  epd.DisplayFrame();
  delay(2000);
 
  
    
}

void loop(){

}


void printValues(){
}

This is the same code except placing the reading and writing of the data in the void loop.

#include <SPI.h>
#include "epd1in54_V2.h"
#include "imagedata.h"
#include "epdpaint.h"
#include <stdio.h>
#include <stdlib.h>
#include <avr/dtostrf.h>
#include <Adafruit_Sensor.h> //BME280
#include <Adafruit_BME280.h> //BME280

#define BME_SCK 13 //BME280
#define BME_MISO 12 //BME280
#define BME_MOSI 11 //BME280
#define BME_CS 6 //BME280

#define SEALEVELPRESSURE_HPA (1013.25) //BME280

Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

Epd epd;
unsigned char image[1024];
Paint paint(image, 0, 0);

#define COLORED     0
#define UNCOLORED   1

unsigned long delayTime;

char temp[100];
char humi[100];
char pres[100];
char alti[100];

void setup()
{
  
  // put your setup code here, to run once:
  Serial.begin(115200);
  //Serial.println("e-Paper init and clear");
  //Serial.println("e-Paper clear and goto sleep");
  //epd.HDirInit();
  //epd.Clear();
  //epd.Sleep();
  while(!Serial);    // time to get serial running
  Serial.println(F("BME280 test"));  //BME280

  unsigned status; //BME280
  status = bme.begin(); //BMW280
  
}

void loop(){

  
  float tempValue = bme.readTemperature();
  dtostrf(tempValue,4,2,temp);
  float humiValue = bme.readHumidity();
  dtostrf(humiValue,4,2,humi);
  float presValue = bme.readPressure() / 100.0F;
  dtostrf(presValue,4,2,pres);
  float altiValue = bme.readAltitude(SEALEVELPRESSURE_HPA);
  dtostrf(altiValue,6,2,alti);

 
    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" °C");

    Serial.print("Pressure = ");
    Serial.print(bme.readPressure() / 100.0F);
    Serial.println(" hPa");

    Serial.print("Approx. Altitude = ");
    Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
    Serial.println(" m");

    Serial.print("Humidity = ");
    Serial.print(bme.readHumidity());
    Serial.println(" %");


  
  epd.LDirInit();
  epd.Clear();
 
  
  paint.SetWidth(200);
  paint.SetHeight(24);

  paint.Clear(UNCOLORED);
  paint.DrawStringAt(4, 4, "TEMP", &Font20, COLORED);
  paint.DrawStringAt(100, 4, temp, &Font20, COLORED);
  paint.DrawStringAt(170, 4, "C", &Font20, COLORED);
  epd.SetFrameMemory(paint.GetImage(), 0, 20, paint.GetWidth(), paint.GetHeight());

  paint.Clear(UNCOLORED);
  paint.DrawStringAt(4, 4, "HUMI", &Font20, COLORED);
  paint.DrawStringAt(100, 4, humi, &Font20, COLORED);
  paint.DrawStringAt(170, 4, "%", &Font20, COLORED);
  epd.SetFrameMemory(paint.GetImage(), 0, 60, paint.GetWidth(), paint.GetHeight());

  paint.Clear(UNCOLORED);
  paint.DrawStringAt(4, 4, "PRES", &Font20, COLORED);
  paint.DrawStringAt(70, 4, pres, &Font20, COLORED);
  paint.DrawStringAt(170, 4, "Pa", &Font20, COLORED);
  epd.SetFrameMemory(paint.GetImage(), 0, 100, paint.GetWidth(), paint.GetHeight());

  paint.Clear(UNCOLORED);
  paint.DrawStringAt(4, 4, "ALTI", &Font20, COLORED);
  paint.DrawStringAt(80, 4, alti, &Font20, COLORED);
  paint.DrawStringAt(170, 4, "m", &Font20, COLORED);
  epd.SetFrameMemory(paint.GetImage(), 0, 140, paint.GetWidth(), paint.GetHeight());


  epd.DisplayFrame();
  delay(5000);
 
  
    

}


void printValues(){
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.