System

begin()

Function:

Initialize the touch screen, TF Card, serial port, battery ADC reading, I2C

Syntax:

void begin(bool touchEnable = true, bool SDEnable = true, bool SerialEnable = true, bool BatteryADCEnable = true, bool I2CEnable = false)

Definition:

void M5EPD::begin(bool touchEnable, bool SDEnable, bool SerialEnable,
                  bool BatteryADCEnable, bool I2CEnable) {
    if (_isInited) {
        return;
    }
    _isInited = true;

    pinMode(M5EPD_MAIN_PWR_PIN, OUTPUT);
    enableMainPower();

    if (SerialEnable == true) {
        Serial.begin(115200);
        Serial.flush();
        delay(50);
        Serial.print("M5EPD initializing...");
    }

    pinMode(M5EPD_EXT_PWR_EN_PIN, OUTPUT);
    pinMode(M5EPD_EPD_PWR_EN_PIN, OUTPUT);
    pinMode(M5EPD_KEY_RIGHT_PIN, INPUT);
    pinMode(M5EPD_KEY_PUSH_PIN, INPUT);
    pinMode(M5EPD_KEY_LEFT_PIN, INPUT);
    delay(100);

    enableEXTPower();
    enableEPDPower();
    delay(1000);

    EPD.begin(M5EPD_SCK_PIN, M5EPD_MOSI_PIN, M5EPD_MISO_PIN, M5EPD_CS_PIN,
              M5EPD_BUSY_PIN);

    if (SDEnable == true) {
        SPI.begin(14, 13, 12, 4);
        SD.begin(4, SPI, 20000000);
    }

    if (touchEnable == true) {
        if (TP.begin(21, 22, 36) != ESP_OK) {
            log_e("Touch pad initialization failed.");
        }
    } else if (I2CEnable == true) {
        Wire.begin(21, 22, (uint32_t)400000U);
    }

    if (BatteryADCEnable == true) {
        BatteryADCBegin();
    }

    if (SerialEnable == true) {
        Serial.println("OK");
    }
}

Example:

#include <M5EPD.h>

void setup() {
  M5.begin(true,true,true,true,true);
}

update()

Function:

Check whether the button is pressed

Syntax:

void update()

Example:

#include <M5EPD.h>
void setup() {
  M5.begin(false,false,true,false,false);
}

void loop() {
  M5.update();
  if( M5.BtnL.wasPressed()) {
    Serial.println("Left button pressed");
  }
  delay(100);
}

Button

Define Pins Description
M5EPD_KEY_LEFT_PIN 37 Paddle wheel rolls up
M5EPD_KEY_PUSH_PIN 38 Dial pressed
M5EPD_KEY_RIGHT_PIN 39 Paddle wheel rolls down
M5EPD_PORTA_W_PIN 32 PORT-A
M5EPD_PORTA_Y_PIN 25 PORT-A
M5EPD_PORTA_W_PIN 32 PORT-A
M5EPD_PORTA_Y_PIN 25 PORT-A
M5EPD_PORTB_W_PIN 33 PORT-B
M5EPD_PORTB_Y_PIN 26 PORT-B
M5EPD_PORTC_W_PIN 19 PORT-C
M5EPD_PORTC_Y_PIN 18 PORT-C
M5EPD_PORTC_Y_PIN 18 PORT-C
M5EPD_MISO_PIN 13 IT8951E/TF-card MISO
M5EPD_MOSI_PIN 12 IT8951E/TF-card MOSI
M5EPD_SCK_PIN 14 IT8951E/TF-card SCK
M5EPD_CS_PIN 15 IT8951E CS
M5EPD_MAIN_PWR_PIN 2 PWR
M5EPD_SCK_PIN 14 IT8951E/TF-card SCK
M5EPD_SCK_PIN 14 IT8951E/TF-card SCK
M5EPD_BUSY_PIN 27 /
M5EPD_EXT_PWR_EN_PIN 5 /
M5EPD_EPD_PWR_EN_PIN 23 /
M5EPD_BAT_VOL_PIN 35 /

lastChange()

Function:

Returns the time of the last state change

Syntax:

uint32_t lastChange()

Pay attention:
1.The returned time is from the moment when M5Paper is initialized, in milliseconds

Example:

#include <M5EPD.h>

void setup() {
  M5.begin();
  Serial.println("Please pressed Button L.");
}

void loop() {
  M5.update();
  Serial.printf("The last change at %d ms /n",M5.BtnL.lastChange());    //Print the time of the last state change of key L. 打印按键L最后一次状态变化的时间
}

isPressed()

Function:

Return to the key pressed state: If the key is pressed, return true; otherwise, return false

Syntax:

uint8_t isPressed()

Example:

#include <M5EPD.h>

void setup() {
    M5.begin();
    Serial.println("Please pressed Button L.");
}

void loop() {
    M5.update(); // Need to add M5.update() to read the state of the button
     //需添加M5.update()才能读取到按键的状态.
    if (M5.BtnL.isPressed()) {  //If the key is pressed. 如果按键按下
        Serial.println("Button is Pressed.");
    } else {
        Serial.println("Button is Released.");
    }
    delay(20);
}

pressedFor()

Function:

Return to the button pressed state: If the button is pressed for more than the specified time, it returns true; otherwise it returns false

Syntax:

uint8_t pressedFor(uint32_t ms)

parameter type describe
ms uint32_t Button press time (ms)

Example:

#include <M5EPD.h>

void setup() {
    M5.begin();
    Serial.println("Please pressed Button L.");
}

void loop() {
    M5.update();
    if (M5.BtnL.pressedFor(
            2000)) {  // If the button is pushed up for more than 2 seconds.
                      //如果按键被推上超过2秒.
        Serial.println("Button L was pressed for more than 2 seconds.");
        delay(1000);
    }
}

wasPressed()

Function:

Return to the key pressed state: If the key is pressed, it will only return true once, otherwise it will return false

Syntax:

uint8_t wasPressed()

Example:

#include <M5EPD.h>

void setup() {
  M5.begin();
  Serial.println("Please push on Button L.");
}

void loop() {
  M5.update();
  if (M5.BtnL.wasPressed()) {    //If the button is pushed up. 如果按键被推上
    Serial.println("Button is pressed.");
  }
  delay(20);
}

Released

isReleased()

Function:

Return key release status: If the key is released, return true; otherwise return false

Syntax:

uint8_t isPressed()

Example:

#include <M5EPD.h>

void setup() { M5.begin(); }

void loop() {
    M5.update();  // Need to add M5.update() to read the state of the button
                  //需添加M5.update()才能读取到按键的状态.
    if (M5.BtnL.isReleased()) {  //If the key is released. 如果按键释放.
        Serial.println("Button is released.");
    } else {
        Serial.println("Button is Pressed .");
    }
    delay(20);
}

releasedFor()

Function:

Return to the key release state: If the key is released for more than the specified time, return true; otherwise, return false

Syntax:

uint8_t pressedFor(uint32_t ms)

Parameter type describe
ms uint32_t Button release time (ms)

Example:

#include <M5EPD.h>

void setup() { M5.begin(); }

void loop() {
    M5.update();  // Need to add M5.update() to read the state of the button
                  //需添加M5.update()才能读取到按键的状态.
    if (M5.BtnL.isReleased()) {  //If the key is released. 如果按键释放
        Serial.println("Button is released.");
    } else {
        Serial.println("Button is pressed.");
    }
    delay(20);
}

wasReleased()

Function:

Return to the key release state: If the key is released, it will only return true once, otherwise it will return false

Syntax:

uint8_t wasReleased()

Example:

#include <M5EPD.h>

void setup() {
    M5.begin();
    Serial.println("Please pressed Button L.");
}

void loop() {
    M5.update();
    if (M5.BtnL.wasReleased()) {  //If the key is released. 如果按键释放
        Serial.println("Button is Released.");
    }
    delay(20);
}

wasReleasefor()

Function:

Return to the key release state: If the key is pressed and released after the specified time, it will only return true once, otherwise it will return false

Syntax:

uint8_t wasReleasefor(uint32_t ms)

Parameters Type Description
ms uint32_t Button press time (ms)

Example:

#include <M5EPD.h>

void setup() {
    M5.begin();
    Serial.println("Please pressed Button L.");
}

void loop() {
    M5.update();
    if (M5.BtnL.wasReleasefor(
            3000)) {  // If button A is pressed for 3s and then released
                      //如果按键A按下3s之后释放.
        Serial.println("OK");
    }
}

Power

enableEXTPower()

Function:

Enable expansion port power

Syntax:

void enableEXTPower()

使用示例:

#include <M5EPD.h>

void setup() {
    M5.begin();
    M5.enableEXTPower();  //enable external power. 启用拓展端口电源
    Serial.println("Expansion port power is on");
}

void loop() {}

disableEXTPower()

Function:

Power off the expansion port

Syntax:

void disableEXTPower()

使用示例:

#include <M5EPD.h>

void setup() {
    M5.begin();
    M5.disableEXTPower();  //disable external power. 关闭拓展端口电源
    Serial.println("Expansion port power is off");
}

void loop() {}

enableEPDPower()

Function:

Enable ink screen power

Syntax:

void enableEPDPower()

使用示例:

#include <M5EPD.h>

void setup() {
    M5.begin();
    M5.enableEPDPower();  //enable EPD power. 启用墨水屏电源
    Serial.println("Ink screen power is activated");
}

void loop() {}

disableEPDPower()

Function:

Power off the ink screen

Syntax:

void disableEPDPower()

使用示例:

#include <M5EPD.h>

void setup() {
    M5.begin();
    M5.disableEPDPower();  //disable EPD power. 关闭墨水屏电源
    Serial.println("Ink screen power off");
}

void loop() {}

enableMainPower()

Function:

Enable main power

Syntax:

void enableMainPower()

使用示例:

#include <M5EPD.h>

void setup() {
    M5.begin();
    M5.enableMainPower();  //Start main power. 启动主电源
    Serial.println("Main power is on");
}

void loop() {}

disableMainPower()

Function:

Turn off the main power

Syntax:

void disableMainPower()

使用示例:

#include <M5EPD.h>

void setup() {
    M5.begin();
    M5.disableMainPower();  //Turn off the main power. 关闭主电源
    Serial.println("Main power is off");
}

void loop() {}

BatteryADCBegin()

Function:

Initialize battery ADC detection

Syntax:

void BatteryADCBegin()

使用示例:

#include <M5EPD.h>

void setup() {
    M5.begin();
    M5.BatteryADCBegin();  // Initialize battery ADC detection.
                           // 初始化电池ADC检测
}

void loop() {}

getBatteryRaw()

Function:

Read the battery voltage native ADC value

Syntax:

uint32_t getBatteryRaw()

使用示例:

#include <M5EPD.h>

void setup() {
    M5.begin();
    Serial.printf("ADC RAW:%d",
                  M5.getBatteryRaw());  // Read battery voltage native ADC values
                                        // 读取电池电压原生ADC值
}

void loop() {}

getBatteryVoltage()

Function:

Read battery voltage

Syntax:

uint32_t getBatteryVoltage()

使用示例:

#include <M5EPD.h>

void setup() {
    M5.begin();
    Serial.printf("Battery Voltage:%d",
                  M5.getBatteryVoltage());  // Read battery voltage
                                            // 读取电池电压
}

void loop() {}

shutdown()

function overload-1:

Power off and wake up again via PWR button

void shutdown()

function overload-2:

Turn off the power and wake up the device via RTC at the end of the delay based on the number of seconds of incoming delay.

int shutdown( int seconds )

function overload-3:

Turn off the power, pass in the RTC time structure that specifies a certain point in time, and wake up the device via RTC when the hours, minutes, and seconds of that time are met.

int shutdown( const rtc_time_t &RTC_TimeStruct)

function overload-4:

Turn off the power, pass in the RTC time structure specified for a certain point in time, and wake up the device by RTC when the week number, day number, and time of that point in time match at the same time.

int shutdown( const rtc_date_t &RTC_DateStruct, const rtc_time_t &RTC_TimeStruct)

Example:

#include <M5EPD.h>

M5EPD_Canvas canvas(&M5.EPD);

void setup()
{
    M5.begin();
    M5.EPD.SetRotation(90);
    M5.TP.SetRotation(90);
    M5.EPD.Clear(true);
    M5.RTC.begin();
    canvas.createCanvas(540, 960);
    canvas.setTextSize(3);
    canvas.drawString("Press PWR Btn for sleep!", 45, 350);
    canvas.drawString("after 5 sec wakeup!", 70, 450);
    canvas.pushCanvas(0,0,UPDATE_MODE_DU4);
}

void loop()
{
    if(M5.BtnP.wasPressed()){
        canvas.drawString("I'm going to sleep.zzzZZZ~", 45, 550);
        canvas.pushCanvas(0,0,UPDATE_MODE_DU4);
        delay(1000);
        M5.shutdown(5);
    }
    M5.update();
    delay(100);
}
On This Page