Skip to content

Library Basics: How to use (from a blank sketch...)

max mc costa edited this page Jul 16, 2015 · 11 revisions

Minimal setup

The RA8875 library it's extremely configurable so it can be difficult understand how to use, this is why I included a lot of examples! Every MCU has it's features, DUE has Extended SPI, Teensy 3.1 can use alternative SPI pins, Teensy LC can use a second SPI bus, this library let you use all those features so you can easily introduce RA8875 in your project.

1) Include libraries:

We first need to include libraries:

#include <SPI.h>
#include <RA8875.h>

If you are using the capacitive touch screen and you have enabled in the user settings you will need to inlude wire as well.

#include <Wire.h>

2) define the pin you want to use (not necessary but good practice)

#define RA8875_CS 2 // see below
#define RA8875_RST 23//any pin or don't use

On Teensy 3.0, 3.1 and LC you cannot use any pin for CS! use 2,6,9,10,15,20,21,22,23.
On Arduino UNO and 8 bit Arduino's you can use ANY pin for CS.
On Arduino DUE you better look the Arduino Specifications (I don't have one).

3) Create an instance

RA8875 tft = RA8875(RA8875_CS);

or (if you are using the RST pin)

RA8875 tft = RA8875(RA8875_CS,RA8875_RST);

Teensy 3.1 let you choose alternative MISO,MOSI and SCLK pin (see Teensy 3.1 docs)

RA8875 tft = RA8875(RA8875_CS,RA8875_RST,alt_mosi,alt_sclk,alt_miso);

4) Setup

void setup() {
    tft.begin(RA8875_480x272);
}

You have different choices here!

  • RA8875_480x272
  • RA8875_800x480
  • Adafruit_800x480

The adafruit use one pin of the RA8875 for backlight so the library has the support for that! The begin command have one hidden parameter that if not specified set display at 65K colors.

tft.begin(RA8875_480x272,8);//set display to 8 bit color depth
tft.begin(RA8875_480x272,16);//(default) set display for 65K color depth

The color depth can be changed on the fly in your code, this allow you to use the layers on screen bigger than 480*272! The begin function do several stuff in one time, init the SPI, init Screen, clear screen memory and set it BLACK, so you do not need any other command, from this point you can use any command you want.

note:
Set the color depth in begin it's really an optional, only needed if you are using only 8bit color data.