• Jump To … +
    examples/01-hello-world/01-hello-world.ino examples/01-hello-world/config.h
  • 01-hello-world.ino

  • §

    Loads the config.h file that contains some constants used in the application.

    #include "config.h"
  • §

    This is the string we want to write in the display.

    const char HELLO_WORLD_STRING[] = "HELLO WORLD";
  • §

    BOILERPLATE This is the entrypoint of the application. Think of main in Java or C.

    void setup()
    {
  • §

    BOILERPLATE Sets the data rate in bits per second (baud) for serial data transmission. See docs.

      Serial.begin(115200);
  • §

    Pauses the application for 100 milliseconds. See delay. Most examples have this, although removing it does not change much. So I am not really sure why it is here.

      delay(100);
  • §

    This is how you print strings into stdout. Whatever you write here shows up in the "Serial Monitor" in Arduino. Also, to properly see the logs you must match the baud dropdown to the same value specified in the Serial.begin call above.

      Serial.println("Paperd.Ink hello world test. This shows up only in logs");
  • §

    Most likely initializes the display. Although I haven’t found the actual implementation of this function. If you remove this the program does not work and you will see Busy Timeout! logged to stdout. I do know this message comes from @ZinggJM/GxEPD2

      display.init();
  • §

    Calls the function that writes the hello world

      print_hello_world();
    }
    
    void print_hello_world()
    {
  • §

    Probably not necessary for this example but worth talking about. The function setRotation is part of Adafruit’s GXF library. Valid inputs are 0, 1, 2, and 3 which set the cardinal rotations. Its implementation lives here.

      display.setRotation(0);
  • §

    Sets the color of the text. In this case the screen only has 3 colors. The GxEDP_BLACK constant is defined in @ZinggJM/GxEPD2:src/GxEPD2.h

      display.setTextColor(GxEPD_BLACK);
  • §

    This is just some basic math to get the boundaries and width/height of the text we want to write, in order to write it at the center of the screen. getTextBounds is implemented in @adafruit/Adafruit-GFX-Library:Adafruit_GFX.cpp

      int16_t tbx, tby;
      uint16_t tbw, tbh;
      display.getTextBounds(HELLO_WORLD_STRING, 0, 0, &tbx, &tby, &tbw, &tbh);
  • §

    x and y would be the coordinates (text cursor in this case) where we want to draw the text.

      uint16_t x = ((display.width() - tbw) / 2) - tbx;
      uint16_t y = ((display.height() - tbh) / 2) - tby;
  • §

    Implemented in @ZinggJM/GxEPD2:src/GxEPD2_BW.h. I didn’t find documentation in the code, but based on the implementation it seems like the drawing is done in specific “windows”, and this method just sets some variables so that the window start at 0, 0 (left, top corner I guess), and end at WIDTH and HEIGHT which I am guessing are some constants that have the size of the current screen.

      display.setFullWindow();
  • §

    Not much documentation about this one, but the implementation is fairly short (@ZinggJM/GxEPD2:src/GxEPD2_BW.h). Seems like it just colors the whole screen in white, and sets some internal variables.

      display.firstPage();
  • §

    A loop that executes once and then only if nextPage returns true. In my experiences this is executed only once.

      do
      {
  • §

    We fill the screen with white. I am guessing we have to do this in order to clear any potential prior “ink”.

        display.fillScreen(GxEPD_WHITE);
  • §

    Then we set the cursor to the values calculated above.

        display.setCursor(x, y);
  • §

    And off we go to finally print “Hello World”

        display.print(HELLO_WORLD_STRING);
      } while (display.nextPage());
    }
  • §

    UNUSED

    void loop() {}