MSPM0_ValvanoWare  1.0
ECE445L starter code
Macros | Functions
SSD1306.h File Reference

Provide simple I/O functions for the SSD 1306 OLED. More...

#include <stdint.h>

Go to the source code of this file.

Macros

#define SSD1306_BLACK   0
 Black is 0 or off.
 
#define SSD1306_WHITE   1
 White is 1 or on.
 
#define SSD1306_INVERSE   2
 Inverse will flip bits.
 
#define SSD1306_EXTERNALVCC   0x01
 SSD1306_EXTERNALVCC specifies External display voltage source.
 
#define SSD1306_SWITCHCAPVCC   0x02
 SSD1306_SWITCHCAPVCC specifies display voltage from 3.3V.
 
#define true   1
 true means success
 
#define false   0
 false means failure
 

Functions

int SSD1306_Init (int vccst)
 II2 driver for SSD1306 OLED display. More...
 
void SSD1306_OutBuffer (void)
 
void SSD1306_InvertDisplay (int i)
 Enable or disable display invert mode (white-on-black vs black-on-white). More...
 
void SSD1306_Dim (int dim)
 Dim the display. More...
 
void SSD1306_DrawPixel (int16_t x, int16_t y, uint16_t color)
 Set/clear/invert a single pixel. This is also invoked by the Adafruit_GFX library in generating many higher-level graphics primitives. More...
 
void SSD1306_DrawFastHLine (int16_t x, int16_t y, int16_t w, uint16_t color)
 Draw a horizontal line. This is also invoked by the Adafruit_GFX library in generating many higher-level graphics primitives. More...
 
void SSD1306_DrawFastVLine (int16_t x, int16_t y, int16_t h, uint16_t color)
 Draw a vertical line. This is also invoked by the Adafruit_GFX library in generating many higher-level graphics primitives. More...
 
void SSD1306_startscrollright (uint8_t start, uint8_t stop)
 Activate a right-handed scroll for all or part of the display. More...
 
void SSD1306_startscrollleft (uint8_t start, uint8_t stop)
 Activate a left-handed scroll for all or part of the display. More...
 
void SSD1306_startscrolldiagright (uint8_t start, uint8_t stop)
 Activate a diagonal scroll for all or part of the display. More...
 
void SSD1306_startscrolldiagleft (uint8_t start, uint8_t stop)
 Activate alternate diagonal scroll for all or part of the display. More...
 
void SSD1306_stopscroll (void)
 Cease a previously-begun scrolling action. More...
 
int SSD1306_GetPixel (int16_t x, int16_t y)
 Return color of a single pixel in display buffer. More...
 
uint8_t * SSD1306_getBuffer (void)
 Get base address of display buffer for direct reading or writing. More...
 
void SSD1306_DrawChar (int16_t x, int16_t y, char letter, uint16_t color)
 Draw a character. More...
 
void SSD1306_DrawString (int16_t x, int16_t y, char *pt, uint16_t color)
 Draw a string. More...
 
void SSD1306_DrawUDec (int16_t x, int16_t y, uint16_t n, uint16_t color)
 Draw a 3 digit integer. More...
 
void SSD1306_ClearBuffer (void)
 Clear contents of display buffer (set all pixels to off). More...
 
void SSD1306_OutClear (void)
 Clear the LCD by writing zeros to the entire screen and reset the cursor to (0,0) (top left corner of screen). More...
 
void SSD1306_DrawFullImage (const uint8_t *ptr)
 Fill the whole screen by drawing a 128x64 bitmap image. More...
 
void SSD1306_DrawBMP (uint8_t xpos, uint8_t ypos, const uint8_t *ptr, uint8_t threshold, uint16_t color)
 Draw a raw bitmap to the RAM buffer. More...
 
void SSD1306_SetCursor (uint16_t newX, uint16_t newY)
 
void SSD1306_OutChar (char data)
 Print a character to the OLED. More...
 
void SSD1306_OutString (char *ptr)
 Print a string of characters to the OLED. More...
 
void SSD1306_OutUDec (uint16_t n)
 Print a 16-bit unsigned number to the OLED. More...
 
void SSD1306_OutSDec (int16_t n)
 Print a 16-bit signed number to the OLED. More...
 
void SSD1306_OutUFix1 (uint16_t n)
 Print a 16-bit unsigned fixed-point number to the OLED. More...
 
void SSD1306_OutU3Fix1 (uint16_t n)
 Print a 16-bit unsigned fixed-point number to the OLED. More...
 
void SSD1306_OutSFix1 (int32_t n)
 Print a 32-bit signed fixed-point number to the OLED. More...
 
void SSD1306_OutHex7 (uint8_t n)
 Print one hex digit. More...
 
void SSD1306_OutUHex7 (uint8_t n)
 Print two hex digits. More...
 
void SSD1306_OutUHex32 (uint32_t n)
 Print 16 hex digits. More...
 
void SSD1306_OutUDec16 (uint32_t n)
 Print three decimal digits. More...
 
void SSD1306_OutUDec2 (uint32_t n)
 Print two decimal digits. More...
 
void SSD1306_SetPlot (int32_t minX, int32_t maxX, int32_t minY, int32_t maxY, uint16_t color)
 Initialize parameters for plotting. More...
 
void SSD1306_DrawPoint (int32_t x, int32_t y)
 Set/clear/invert a single pixel. SSD1306_SetPlot initializes scaling. More...
 
void SSD1306_InitPrintf (void)
 Initialize the SSD1306 for printf. More...
 

Detailed Description

Provide simple I/O functions for the SSD 1306 OLED.

Use I2C to send an 8-bit code to the 1306 64x128 pixel OLED to display text, images, or other information.

Version
RSLK2
Author
Daniel Valvano and Jonathan Valvano
Warning
AS-IS
Note
For more information see http://users.ece.utexas.edu/~valvano/
Date
June 8, 2024
Remarks
Font table based off of Nokia_5110_Example from Spark Fun: 7-17-2011
Spark Fun Electronics 2011, Nathan Seidle
http://dlnmh9ip6v2uc.cloudfront.net/datasheets/LCD/Monochrome/Nokia_5110_Example.pde

Some displays have a typo on OLED has a 0-ohm resistor selection
that says "IIC ADDRESS SELECT 0x78 0x7A"
should have said "IIC ADDRESS SELECT 0x3C 0x3D"
https://www.amazon.com/gp/product/B0871KW7BD
search for I2C SSD1306 on Amazon.com
rough estimate of execution times
SSD1306_Clear 26.5ms
SSD1306_OutBuffer 25.9ms, sends 128 by 64 pixels to OLED
SSD1306_DrawBMP 75us (10 by 16 size), doesn't print, just fills buffer
SSD1306_OutChar 206us, does print
SSD1306_OutUDec 1032us, outputs 5 characters

SSD1306 pins
Pin FunctionDescription
VCC Power +3.3V
PB2 I2C1-SCLJ1.9 SSD1306 SCL, with 1.5k pullup to 3.3V
PB3 I2C1-SDAJ1.10 SSD1306 SDA
GND GND Ground

This example accompanies the book "Embedded Systems: Introduction to Robotics, Jonathan W. Valvano, ISBN: 9781074544300, copyright (c) 2024 For more information about my classes, my research, and my books, see http://users.ece.utexas.edu/~valvano/

Simplified BSD License (FreeBSD License) Copyright (c) 2024, Jonathan Valvano, All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project.