TeensyView Hookup Guide
TeensyView Library Reference
Operating the Library
With Teensyduino and the TeensyView library installed, there's a few things to do in order to start drawing on the screen.
- Include the TeensyView header file --
#include <TeensyView.h>
- Create an object in the global space to use the TeensyView, and pass the desired pin numbers to the constructor. --
TeensyView oled(PIN_RESET, PIN_DC, PIN_CS, PIN_SCK, PIN_MOSI);
- Run the
begin()
function
Now you're ready to start controlling the screen. To draw a frame,
- Erase all or part of the screen.
- Draw new objects
- Use
.display()
to send all data to the screen.
This example shows including the library, creating the object, then repeatedly drawing a frame. The drawing commands are kept terse to serve as a good modifiable template. This example is also available from within the Arduino library.
language:c
/******************************************************************************
Template.ino
A useful starting place when adding a TeensyView to an existing project.
Marshall Taylor @ SparkFun Electronics, March 15, 2017
https://github.com/sparkfun/SparkFun_TeensyView_Arduino_Library
This example sets up the TeensyView and draws a test frame repeatedly.
The objects in the frame were selected to give copy-paste examples for various
common operations without a lot of chaff. See TeensyView.h for specifics.
Compatible with:
Teensy LC
Teensy 3.1
Teensy 3.2
Teensy 3.5
Teensy 3.6
Development environment specifics:
Arduino IDE 1.6.12 w/ Teensyduino 1.31
Arduino IDE 1.8.1 w/ Teensyduino 1.35
TeensyView v1.0
This code is released under the [MIT License](http://opensource.org/licenses/MIT).
Please review the LICENSE.md file included with this example. If you have any questions
or concerns with licensing, please contact techsupport@sparkfun.com.
Distributed as-is; no warranty is given.
******************************************************************************/
#include <TeensyView.h> // Include the SFE_TeensyView library
///////////////////////////////////
// TeensyView Object Declaration //
///////////////////////////////////
//Standard
#define PIN_RESET 15
#define PIN_DC 5
#define PIN_CS 10
#define PIN_SCK 13
#define PIN_MOSI 11
//Alternate (Audio)
//#define PIN_RESET 2
//#define PIN_DC 21
//#define PIN_CS 20
//#define PIN_SCK 14
//#define PIN_MOSI 7
TeensyView oled(PIN_RESET, PIN_DC, PIN_CS, PIN_SCK, PIN_MOSI);
void setup()
{
oled.begin(); // Initialize the OLED
oled.clear(ALL); // Clear the display's internal memory
oled.display(); // Display what's in the buffer (splashscreen)
delay(1000); // Delay 1000 ms
oled.clear(PAGE); // Clear the buffer.
}
void loop()
{
oled.clear(PAGE); // Clear the page
oled.rect(5, 5, 20, 20); // Draw a rectangle
oled.rectFill(35, 16, 23, 11); // Draw a filled rectangle
oled.circle(22, 20, 7); // Draw the circle:
oled.pixel(40, 7, WHITE, NORM); // Draw a white pixel
oled.pixel(48, 21, BLACK, NORM); // Draw a black pixel (on the above rectange)
oled.setFontType(1); // Set font to type 1
oled.setCursor(73, 17); // move cursor
oled.print("world!"); // Write a byte out as a character
oled.setFontType(0); // Set font to type 0
oled.setCursor(67, 12); // move cursor
oled.print("Hello"); // Write a byte out as a character
oled.display(); // Send the PAGE to the OLED memory
delay(200);
}
TeensyView Class Reference
Below, you'll find a complete list of available TeensyView classes that can be called in your code.
Initialization
void begin(void)
--- Initialize TeensyView Library.Setup I/O pins for SPI port, then send initialization commands to the SSD1306 controller inside the OLED.void end (void)
--- Power off the OLED display. Reset display control signals and prepare the SSD1306 controller for power off, then power off the 3.3V regulator.
Display Actions, Settings and Orientation
void display(void)
--- Transfer display memory. Bulk move the screen buffer to the SSD1306 controller's memory so that images/graphics drawn on the screen buffer will be displayed on the OLED.void clear(* uint8_t mode)
--- Clear screen buffer or SSD1306's memory. To clear GDRAM inside the LCD controller, pass in the variable mode = ALL and to clear screen page buffer pass in the variable mode = PAGE.void clear(* uint8_t mode, * uint8_t c)
--- Clear or replace screen buffer or SSD1306's memory with a character. To clear GDRAM inside the LCD controller, pass in the variable mode = ALL with c character and to clear screen page buffer, pass in the variable mode = PAGE with c character.void invert(boolean inv)
-- Invert display. The WHITE color of the display will turn to BLACK, and the BLACK will turn to WHITE.void contrast(* uint8_t contrast)
--- Set OLED contrast value from 0 to 255. Note: Contrast level is not very obvious.void setCursor(* uint8_t x, * uint8_t y)
--- Set TeensyView's cursor position to x,y.void flipVertical(boolean flip)
--- Flip the graphics on the OLED vertically.void flipHorizontal(boolean flip)
--- Flip the graphics on the OLED horizontally.uint8_t getLCDWidth(void)
--- The width of the LCD return as byte.uint8_t getLCDHeight(void)
--- The height of the LCD return as byte.
Display Scrolling
void scrollRight(* uint8_t start, * uint8_t stop)
--- Right scrolling. Set row start to row stop on the OLED to scroll right.void scrollLeft(* uint8_t start, * uint8_t stop)
--- Left scrolling. Set row start to row stop on the OLED to scroll left.void scrollVertRight(* uint8_t start, * uint8_t stop)
--- Right vertical scrolling. Set column start to row stop on the OLED to scroll right.void scrollVertLeft(* uint8_t start, * uint8_t stop)
--- Left vertical scrolling. Set column start to row stop on the OLED to scroll left.void scrollStop(void)
--- Stop the scrolling of graphics on the OLED.
Font Functions
uint8_t getFontWidth(void)
--- Get font width. The current font's width return as byte.uint8_t getFontHeight(void)
--- Get font height. The current font's height return as byte.uint8_t getTotalFonts(void)
--- Get total fonts. Return the total number of fonts loaded into the TeensyView's flash memory.uint8_t getFontType(void)
--- Get font type. Return the font type number of the current font.uint8_t setFontType(* uint8_t type)
--- Set font type. Set the current font type number (i.e., changing to different fonts based on the type provided).uint8_t getFontStartChar(void)
--- Get font starting character. Return the starting ASCII character of the current font; not all fonts start with ASCII character 0. Custom fonts can start from any ASCII character.uint8_t getFontTotalChar(void)
--- Get font total characters. Return the total characters of the current font.
Drawing Pixels
void pixel(* uint8_t x, * uint8_t y)
--- Draw pixel using the current fore color and current draw mode in the screen buffer's x,y position.void pixel(* uint8_t x, * uint8_t y, * uint8_t color, * uint8_t mode)
--- Draw color pixel in the screen buffer's x,y position with NORM or XOR draw mode.
Drawing Lines
void line(* uint8_t x0, * uint8_t y0, * uint8_t x1, * uint8_t y1)
--- Draw line using current fore color and current draw mode from x0,y0 to x1,y1 of the screen buffer.void line(* uint8_t x0, * uint8_t y0, * uint8_t x1, * uint8_t y1, * uint8_t color, * uint8_t mode)
--- Draw line using color and mode from x0,y0 to x1,y1 of the screen buffer.void lineH(* uint8_t x, * uint8_t y, * uint8_t width)
--- Draw horizontal line using current fore color and current draw mode from x,y to x+width,y of the screen buffer.void lineH(* uint8_t x, * uint8_t y, * uint8_t width, * uint8_t color, * uint8_t mode)
--- Draw horizontal line using color and mode from x,y to x+width,y of the screen buffer.void lineV(* uint8_t x, * uint8_t y, * uint8_t height)
--- Draw vertical line using current fore color and current draw mode from x,y to x,y+height of the screen buffer.void lineV(* uint8_t x, * uint8_t y, * uint8_t height, * uint8_t color, * uint8_t mode)
--- Draw vertical line using color and mode from x,y to x,y+height of the screen buffer.
Drawing Rectangles
void rect(* uint8_t x, * uint8_t y, * uint8_t width, * uint8_t height)
--- Draw rectangle using current fore color and current draw mode from x,y to x+width,y+height of the screen buffer.void rect(* uint8_t x, * uint8_t y, * uint8_t width, * uint8_t height, * uint8_t color, * uint8_t mode)
--- Draw rectangle using color and mode from x,y to x+width,y+height of the screen buffer.void rectFill(* uint8_t x, * uint8_t y, * uint8_t width, * uint8_t height)
--- Draw filled rectangle using current fore color and current draw mode from x,y to x+width,y+height of the screen buffer.void rectFill(* uint8_t x, * uint8_t y, * uint8_t width, * uint8_t height, * uint8_t color, * uint8_t mode)
--- Draw filled rectangle using color and mode from x,y to x+width,y+height of the screen buffer.
Drawing Circles
void circle(* uint8_t x, * uint8_t y, * uint8_t radius)
--- Draw circle with radius using current fore color and current draw mode at x,y of the screen buffer.void circle(* uint8_t x, * uint8_t y, * uint8_t radius, * uint8_t color, * uint8_t mode)
--- Draw circle with radius using color and mode at x,y of the screen buffer.void circleFill(* uint8_t x0, * uint8_t y0, * uint8_t radius)
--- Draw filled circle with radius using current fore color and current draw mode at x,y of the screen buffer.void circleFill(* uint8_t x0, * uint8_t y0, * uint8_t radius, * uint8_t color, * uint8_t mode)
--- Draw filled circle with radius using color and mode at x,y of the screen buffer. Uses the Bresenham's circle algorithm with a few modifications to paint the circle without overlapping draw operations.
Misc. Drawing
void drawChar(* uint8_t x, * uint8_t y, * uint8_t c)
--- Draw character c using current color and current draw mode at x,y.void drawChar(* uint8_t x, * uint8_t y, * uint8_t c, * uint8_t color, * uint8_t mode)
--- Draw character c using color and draw mode at x,y.void drawBitmap(void)
--- Draw bitmap image stored elsewhere in the program to the OLED screen.void setColor(* uint8_t color)
--- Set the current draw's color. Only WHITE and BLACK available.void setDrawMode(* uint8_t mode)
--- Set current draw mode with NORM or XOR.
Misc. Under-the-Hood Functions
virtual size_t write(uint8_t)
--- Override Arduino's Print so that we can use uView.print().void data(uint8_t c);
--- SPI data. Send 1 data byte via SPI to SSD1306 controller.void setColumnAddress(uint8_t add)
--- Set SSD1306 column address. Send column address command and address to the SSD1306 OLED controller.void setPageAddress(uint8_t add)
--- Set SSD1306 page address. Send page address command and address to the SSD1306 OLED controller.void command(uint8_t c)
--- Send 1 command byte.uint8_t * getScreenBuffer(void)
--- Get pointer to screen buffer. Return a pointer to the start of the RAM screen buffer for direct access.
System-Level Reference
TeensyView(uint8_t rst, uint8_t dc, uint8_t cs, uint8_t sck, uint8_t mosi)
--- Construct TeensyView object with the pins specified in the arguments.static void begin()
--- SPI Initialization. Set up I/O pins for SPI port, then send initialization commands to the SSD1306 controller inside the OLED. Pins to use have been specified in the constructor.