A simple NodeMCU / BME280 Weatherstation with WaveShare E-Paper 1.54 inch Display

  Uncategorized

Using the WaveShare display with the Adafruit GFX library

Contents

Using the WaveShare display with the Adafruit GFX library

Lets take a look at some code. Whats worth mentioning is that the following code initializes a WaveShare 1.54 specific display class to use in conjunction with the generic Adafruit GFX library. Many thanks to the guy ZinggJM for writing this display class. You can download the whole package (with support for many different display modules) here: https://github.com/ZinggJM/GxEPD Use the Arduino IDE menu Sketch -> Include Library -> >Add .ZIP Library function to import it, so the include statements in the following code work properly.

#include <GxEPD.h>
#include <GxGDEP015OC1/GxGDEP015OC1.cpp> // for the 1.54 inch display module
// For the 4.2 inch b&w display use the following class instead
// #include <GxGDEW042T2>/GxGDEW042T2.cpp>
#include <GxIO/GxIO_SPI/GxIO_SPI.cpp>
#include <GxIO/GxIO.cpp>

// ESP8266 generic/common.h
//static const uint8_t SS    = 15;
//static const uint8_t MOSI  = 13;
//static const uint8_t MISO  = 12;
//static const uint8_t SCK   = 14;

GxIO_Class io(SPI, SS/* CS */,  D3/* DC */,  D4/* RST */);
//GxEPD_Class display(io, D4 /* RST */, D2 /* BUSY */);
GxEPD_Class display(io);

// FreeFonts from Adafruit_GFX

#include <Fonts/FreeSansBold12pt7b.h>
#include <Fonts/FreeSansBold18pt7b.h>
#include <Fonts/FreeSansBold24pt7b.h>

void setup()
{
  Serial.begin(115200);
  while (!Serial) { }
  Serial.println();
  Serial.println("setup");
  SPI.setFrequency(8000000L)
  display.init();
}

The above code instantiates two classes of which one is a subclass of the Adafruit_GFX library. The other one is a separate IO class for Arduino. This io class takes the NodeMCU pins as parameters to which the display module is connected.

GxIO_Class io(SPI, SS/* CS */,  D3/* DC */,  D4/* RST */);

The static constants SS, D3 and D4 are defined in generic/commons.h, as you would expect if you are familiar with the Arduino IDE and different hardware platforms. That said, don’t forget to make sure the selected board in the Arduino IDE is correct. Otherwise, compilation errors might occur.

What’s still missing is the loop function of our program. For the time being, we mock the BME280 sensor data, so we can concentrate on the Waveshare display output. Here it is:

void loop()
{
  sendUpdateBME280();
  delay(10000);
}

void sendUpdateBME280()
{
  float humidity = 23.78f;
  float temperature = 33.21f;
  float dewpoint = 6.70f;
  char dC[3] = {'°', 'C', 0};
  Serial.print("Current humdity = ");
  Serial.print(humidity);
  Serial.print("% ");
  Serial.print("temperature = ");
  Serial.print(temperature);
  Serial.print(dC);
  Serial.print(" dewpoint = ");
  Serial.print(dewpoint);
  Serial.println(dC);

  uint16_t middleY = display.height() / 2;
  display.setRotation(3);
  display.fillScreen(GxEPD_WHITE);
  display.setTextColor(GxEPD_BLACK);
  display.setFont(&FreeSansBold24pt7b);
  display.setTextSize(2);
  display.setCursor(8, 72);
  display.print(temperature, 1);
  display.setFont(&FreeSansBold18pt7b);
  display.setTextSize(2);
  display.setCursor(16, 146);
  display.print(humidity, 1);
  display.setTextSize(1);
  display.print("%");
  display.setCursor(16, 198);
  display.print(dewpoint, 1);

  display.update();
}

You might notice a strong screen flickering after each display update. It is possible to do partial screen updates. But there is more to it, and in the final code revision I use a display.updateWindow() method which seems to fix it. The link to this article’s GitHub code repository is: https://github.com/sgoemans/NodeMCU-BME280-Weatherstation-with-WaveShare-1.54-inch-Display

2 thoughts on - A simple NodeMCU / BME280 Weatherstation with WaveShare E-Paper 1.54 inch Display

  • First of all, thank you for all the information you have provided so far, I want to give you a quick update about connecting to NodeMCU, some new boards are coming with ESP8266EX which is much power friendly but for some reason a little bit more picky, Since I have both normal NodeMCU and that (Robodyn NodeM is a goos example) we must about using RESET on D4, instead I moved it DC BUSY and RST pins to D1, D2 and D3 respectively and it is working for both versions, I guess it would be good to have this reflected on your blog since It will discourage folks for using it. With this set I could, also, use originals WaveShare example successfully.

    Here is the set of pins I am using, tested against GxEPD and EPDiF (WaveShare, smaller, less memory hanger and full featured)

    // Pin definition
    #define RST_PIN D0
    #define DC_PIN D2
    #define CS_PIN SS
    #define BUSY_PIN D1

LEAVE A COMMENT