Hans-Günther Nusseck
Published © MIT

M5StickC Textbuffer Scrolling Display

A library to display texts on the M5StickC in any orientation. The display scrolls and wraps text lines automatically.

BeginnerProtip1 hour11,562

Things used in this project

Hardware components

M5StickC ESP32-PICO Mini IoT Development Board
M5Stack M5StickC ESP32-PICO Mini IoT Development Board
M5Stack M5StickC CardKB HAT

Software apps and online services

Microsoft Visual Studio Code
PlatformIO IDE
PlatformIO IDE


Read more


Example for the usage of tb_display

A simple example displaying characters that were either received via the serial interface or entered via the Hat keyboard.
The orientation can be changed via the M5 button.
 * Example for tb_display
 * Library for a simple text buffer scrolling display on the M5StickC.
 * Hague Nusseck @ electricidea
 * 01/19/2020
 * https://github.com/electricidea/M5StickC-TB_Display
 * This library makes it easy to display texts on the M5StickC.
 * The display behaves like a terminal: New text is added at the bottom.
 * The text scrolls up with every new line. The lines are automatically wrapped.
 * The display can be used in any orientation. 
 * This example shows characters from the serial port on the M5StickC display.
 * If a Keyboard-Hat is connected, also the characters from the Keyboard
 * are shoen on the display.
 * Distributed as-is; no warranty is given.
#include <Arduino.h>

#include <M5StickC.h>

#include "tb_display.h"

// I2C Adress of the Keyboard Hat
#define CARDKB_ADDR 0x5F

// Display brightness level
// possible values: 7 - 15
uint8_t screen_brightness = 10; 

// scren Rotation values:
// 1 = Button right
// 2 = Button above
// 3 = Button left
// 4 = Button below
int screen_orientation = 1;

void setup() {
  // initialize the M5Stack object
  // initialize I2C for the Keyboard Hat (not required)
  Wire.begin(0, 26);
  // set screen brightness

  // print a welcome message over serial porta
	Serial.println("     M5StickC");
	Serial.println("Textbuffer Display");
	Serial.println(" 19.01.2020 v1.0");

  // init the text buffer display and print welcome text on the display
  tb_display_print_String("        M5StickC\n\n   Textbuffer Display\n\n");

void loop() {

  // change the display orientation if Button A is pressed
  if (M5.BtnA.wasPressed()){
    if(screen_orientation > 4)
      screen_orientation = 1;
    // init the text buffer display with the new orientation
    // different text alignment for landscape or portrait mode
    switch (screen_orientation) {
      case 1: case 3: {
        tb_display_print_String("        M5StickC\n\n   Textbuffer Display\n\n");
      case 2: case 4: {
        tb_display_print_String(" M5StickC\n\nTextbuffer\n  Display\n\n\n\n\n");
      default: {

  // check for serial input and print the received characters
  while(Serial.available() > 0){
    char data = Serial.read();

  // check for input from the Keyboard Hat and print the received characters
  Wire.requestFrom(CARDKB_ADDR, 1);
  while (Wire.available())
    char c = Wire.read(); // receive a byte as characterif
    if (c != 0)
      if (c == 13) { //0x0D = CR = '\r'
        // Map CR to LF (0x0A)
      } else {

Full library code and a the example code

The library consists of a header file and a source code file.


Hans-Günther Nusseck

Hans-Günther Nusseck

17 projects • 51 followers
Just a guy who can't pass by any hardware without wondering how it works. Managing robot based industrial automation projects for living.