Lucky Resistor
Menu
  • Home
  • Learn
    • Learn C++
    • Product Photography for Electronics
      • Required Equipment and Software
    • Soldering for Show
  • Projects
  • Libraries
  • Applications
  • Shop
  • About
    • About Me
    • Contact
    • Stay Informed
  •  
Menu

Sharp Display Driver 8×8 Timer 2

This is a compact display driver for the LS013B4DN04 display from Sharp. It is text based and writes 8×8 pixel characters on the screen, which allows 12×12 characters. It uses timer 2 to automatically refresh the display if anything changes on it.

There is a library with manual refresh here: Sharp Display Driver 8×8

DEMO

This demo is an example of the Arduino library. The demo is showing the library with manual refresh.

Requirements

  • Library for Arduino IDE 1.6 or newer
  • Assuming a ATmega328P microcontroller running at 16MHz
    You can use it with other microcontroller, but probably have to adjust the timing manually.

Usage

After creating a global instance of the driver class and pass the used pins for the SPI communication to the driver, you have to initialise the driver with begin() and setFont().

This minimal example is showing all required steps. You find the complete example, including the font, in the example folder of the library.

// Include the header file of the driver.
#include <LRSharpDisplayT2.h>

// Include the header file of the font.
#include "Fonts.h"

// Create a global instance of the display driver.
//
// Add the chip select, clock and data pins which are connected to the
// display as arguments to the constructor in this order. In this
// example, we use pin 11 for chip select, pin 9 for the clock and
// pin 10 for the data in.
//
lr::SharpDisplay sharpDisplay(11, 9, 10);

void setup() {
// In the setup method, you have to call begin() to initialize the
// library and setup communication. It will also start the timer
// to refresh the display.
sharpDisplay.begin();

// A font is required, you can use the example font for your own
// project. Just add the "Fonts.h" and "Fonts.cpp" to your project.
sharpDisplay.setFont(Fonts::a);

// The display is automatically cleared at the start, so you can
// start writing text to the display:
sharpDisplay.writeText(F("Hello World!"));
}

void loop() {
}

Method Documentation

SharpDisplay(uint8_t chipSelectPin, uint8_t clockPin, uint8_t dataPin)

The constructor. Specify the pins for the SPI communication with the display.

void begin()

This method initialises the display. Call this as first method in your setup() method. It will setup the communication and clear the display.

void setFont(const uint8_t *fontData)

This method sets the current used font for the display. You have to set an initial font before you can use the display driver. It is possible to call this method later again to change the font.

void setRefreshInterval(RefreshInterval refreshInterval)

This sets the refresh interval. There are two speeds: normal (0.2s) and slow (1s).

uint8_t getScreenWidth()

Use this method to get the screen width in characters.

uint8_t getScreenHeight()

Use this method to get the screen height in characters.

void clear()

This method clears the display. It will also clear the text buffer and fill the buffer with space (0x20) and sets the cursor at position 0, 0.

void setTextInverse(bool enable)

Enable/Disable inverse future text. If you enable inverse text, any subsequent call of text writing methods will write inverse text or characters.

void setCharacter(uint8_t row, uint8_t column, uint8_t character)

This will set a single character on the screen at the specified location.

char getCharacter(uint8_t row, uint8_t column)

Get the character at the specified location.

void setLineText(uint8_t row, const String &text)

This will replace a line on the screen with the given text. If the text is longer than the screen it will cut off and if the text is smaller than the screen, the rest of the line is filled with space characters.

void setLineInverted(uint8_t row, bool inverted)

This will make a line inverse or not inverse. E.g. you can use this method for the selected item in a menu.

void setCursorPosition(uint8_t row, uint8_t column)

This sets the position of the virtual cursor. It will change the location where the writeCharacter() and writeText() methods will start writing text.

void getCursorPosition(uint8_t &row, uint8_t &column)

Use this method to get the location of the virtual cursor.

void writeCharacter(uint8_t c)

This writes a single character on the screen at the current cursor position. You can also send a newline character ‘\n’ to start a new line.

void writeText(const String &text)

This writes test on the screen at the current cursor position. You can use the newline ‘\n’ character to begin a new line. If the text reaches the bottom of the screen, the contents of the screen is scrolled up to make space for the new text.

void scrollScreen(ScrollDirection direction)

You can use this method to scroll the contents of the screen into all four directions.

Font Format

The font is a simple array of bytes. There are eight bytes per character, each byte is a row in the character from top to down. Each 0-bit in the byte is a black pixel, the font have to be inverted.

Use the Font to Byte application to convert bitmaps into byte arrays for this display driver.

The font can cover 128 characters maximum, but you can provide a shorter font with e.g. only 64 characters without problems.

Download

Download the driver using the following link. Extract the directory and move it into the “library” directory.

Lucky Resistor’s Sharp Display 8×8 Library Timer 2

Visit the GITHub page for older versions.

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Stay Updated

Join me on Mastodon!

Top Posts & Pages

  • How and Why to use Namespaces
  • Storage Boxes System for 3D Print
  • Use Enum with More Class!
  • Circle Pattern Generator
  • Real Time Counter and Integer Overflow
  • Circle Pattern Generator
  • Logic Gates Puzzles
  • C++ Templates for Embedded Code
  • C++ Templates for Embedded Code (Part 2)
  • Logic Gates Puzzle 101

Latest Posts

  • The Importance of Wall Profiles in 3D Printing2023-02-12
  • The Hinges and its Secrets for Perfect PETG Print2023-02-07
  • Better Bridging with Slicer Guides2023-02-04
  • Stronger 3D Printed Parts with Vertical Perimeter Linking2023-02-02
  • Logic Gates Puzzle 1012023-02-02
  • Candlelight Emulation – Complexity with Layering2023-02-01
  • Three Ways to Integrate LED Light Into the Modular Lantern2023-01-29
  • The 3D Printed Modular Lantern2023-01-17

Categories

  • 3D Printing
  • Build
  • Common
  • Fail
  • Fun
  • Learn
  • Projects
  • Puzzle
  • Recommendations
  • Request for Comments
  • Review
  • Software
Copyright (c)2022 by Lucky Resistor. All rights reserved.