温度モニター改良(1.54インチe-Paper導入)

経緯

前回(2月25日)、温度表示をOLEDからe-Paperへ刷新しました。

その後、画面設計を見直しましたが、レイアウトが不格好になってしまったため、解像度200×200(dot)の画面へ変更しました。


部品

1. WeAct Studio 1.54インチ電子ペーパーモジュール(AliExpressで購入)


2. マイコン

OLEDディスプレイが焼き付いており、廃棄予定だった開発ボードを再利用しました。

  • ESP32-C3
  • 0.42インチOLED搭載
  • Wi-Fi / Bluetooth対応

試作

1. GitHubからサンプルプログラムを入手

https://github.com/WeActStudio/WeActStudio.EpaperModule

2. サンプルソースをArduino IDEへコピー

3. サンプルを改修

内外気温および大気圧を表示する関数を作成。
(フォントサイズを切り替え、数値は右寄せ表示)

※コードは以下の通り

     /*
  base class GxEPD2_GFX can be used to pass references or pointers to the display instance as parameter, uses ~1.2k more code
  enable or disable GxEPD2_GFX base class

  Board Manager   :esp32 by Espressif Systems
  Library Manager :GxEPD2 by jean-Marc Zingg
*/

#define ENABLE_GxEPD2_GFX 0

#include <GxEPD2_BW.h>
#include <GxEPD2_3C.h>
#include <Fonts/FreeMonoBold12pt7b.h>
#include <Fonts/FreeMonoBold18pt7b.h>

// ESP32-C3 CS(SS)=7,SCL(SCK)=4,SDA(MOSI)=6,BUSY=3,RES(RST)=2,DC=1
#define CS_PIN (SS)
#define BUSY_PIN (3)
#define RES_PIN (2)
#define DC_PIN (1)

// 1.54'' EPD Module
GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display(GxEPD2_154_D67(/*CS=5*/ CS_PIN, /*DC=*/ DC_PIN, /*RES=*/ RES_PIN, /*BUSY=*/ BUSY_PIN)); // GDEH0154D67 200x200, SSD1681

void setup()  
{
  //初期化
  display.init(115200,true,50,false);

  //e-Paperに表示
  Gxprint(/*loat 外気温*/ 9.2, /*float 内温度*/ 15.2, /*float 大気圧*/ 1012.5 );

}

void loop() {

}

void Gxprint(float outFloat, float inFloat, float preFloat )
{
  int16_t tbx, tby; uint16_t tbw, tbh;          //文字列の表示領域で使用
  char inString[8], outString[8], preString[8]; //受け取ったfloatの受け皿

  //floatで受けた値を文字列に変換
  sprintf( inString,  "%+4.1f", inFloat);
  sprintf( outString, "%+4.1f", outFloat);
  sprintf( preString, "%4.0f", preFloat);

  //初期値設定
  display.setRotation(1);
  display.setTextColor(GxEPD_BLACK);
  display.setFullWindow();

  display.firstPage();
  do
  {
    display.fillScreen(GxEPD_WHITE);
    //外気温
    display.setFont(&FreeMonoBold12pt7b);
    display.setCursor(2, 30);
    display.print("Outside\ntemp.");
    display.setFont(&FreeMonoBold18pt7b);
    display.getTextBounds( outString, 0, 0, &tbx, &tby, &tbw, &tbh);
    display.setCursor(display.width() - tbw -3, 55);
    display.print( outString );
    display.fillRect(0, 65, 199, 2, GxEPD_BLACK);
    //内気温
    display.setFont(&FreeMonoBold12pt7b);
    display.setCursor(2, 90);
    display.print("Indoor\ntemp.");
    display.setFont(&FreeMonoBold18pt7b);
    display.getTextBounds( inString, 0, 0, &tbx, &tby, &tbw, &tbh);
    display.setCursor(display.width() - tbw -3, 115);
    display.print(inString);
    display.fillRect(0, 125, 199, 2, GxEPD_BLACK);
    //大気圧
    display.setFont(&FreeMonoBold12pt7b);
    display.setCursor(2, 150);
    display.print("Atmospheric\npressure");
    display.setFont(&FreeMonoBold18pt7b);
    display.getTextBounds(preString , 0, 0, &tbx, &tby, &tbw, &tbh);
    display.setCursor(display.width() - tbw -3 , 175);
    display.print(preString);
  }
  while (display.nextPage());
}

4. 取付け例

ここまで読んでいただき、ありがとうございます。

プライバシーポリシー |ページトップへ

`