View on GitHub

SmallBasicPIGPIO

Plugin for SmallBASIC to access GPIO pins on a Raspberry PI

back to main page

SSD1306 OLED Display

The SSD1306 OLEDs are graphics displays with usually 128x64 or 128x32 pixels in monochrom. Only these two types are supported. Additionally two-color display exists, but I haven’t tested these yet. SmallBASICPiGPIO is using the I2C-protocol for communication. For setting up the Raspberry Pi for I2C and connecting the display please check the example page.

OLED1_Open

OLED1_Open()
OLED1_Open(address)
OLED1_Open(address, width, height)

Addresse (optional parameter): 0x3C or 0x3D; default is 0x3C
Width (optional parameter): 128
Height (optional parameter): 32 or 64; default is 64

Connects to the OLED display.

OLED1_Open()
OLED1_Open(0x3D, 128, 32)

OLED1_Close

OLED1_Close()

Turns of the display and closes the connection.

OLED1_Display

OLED1_Display()

Displays the current buffer. If you perform a drawing command, only the buffer will be change. The display will not show the changes until OLED1_Display() is called.

OLED1_Cls()

OLED1_Cls()
OLED1_Cls(color)

Color (optional parameter): 0 (black) or >0 (white); default 0

Clears the screen using color and sets the cursor to 0,0

OLED1_Cls() 'Screen will be black
OLED1_Cls(1) 'Screen will be white

OLED1_Pset

OLED1_Pset(x,y)
OLED1_Pset(x,y, color)

x: Position x
y: Position y
color (optional parameter): 0 (black), >0 (white); default 1

Sets the color of the pixel at x,y to black or white.

OLED1_Pset(30,25) 'pixel at 30,25 is set to white
OLED1_Pset(30,25,0) 'pixel at 30,25 is set to black

OLED1_Line

OLED1_Line(x1,y1,x2,y1)
OLED1_Line(x1,y1,x2,y1,color)

x1,y1: Start pixel
x2,y2: End pixel
color (optional parameter): 0 (black), >0 (white); default 1

Draws a line from x1,y1 to x2,y2.

OLED1_Line(10,10,20,20) ' Draws a white line
OLED1_Line(10,10,20,20,0) ' Draws a black line

OLED1_Rect

OLED1_Rect(x1,y1,x2,y2)
OLED1_Rect(x1,y1,x2,y2, color)
OLED1_Rect(x1,y1,x2,y2, color, fill)

x1,y1: Pixel top-left corner
x2,y2: Pixel bottom-right corner
color (optional parameter): 0 (black), >0 (white); default 1
fill (optional parameter): 0 (not filled); 1 (filled); default 1

Draws a rectangle.

OLED1_Rect(10,10,40,40) 'White lined rectangle
OLED1_Rect(10,10,40,40,0) 'Black lined rectangle
OLED1_Rect(10,10,40,40,1,1) 'White filled rectangle

OLED1_RoundRect

OLED1_RoundRect(x1,y1,x2,y2, r)
OLED1_RoundRect(x1,y1,x2,y2, r, color)
OLED1_RoundRect(x1,y1,x2,y2, r, color, fill)

x1,y1: Pixel top-left corner
x2,y2: Pixel bottom-right corner
r (optional parameter): Radius of the corners >0; default 3
color (optional parameter): 0 (black), >0 (white); default 1
fill (optional parameter): 0 (not filled); 1 (filled); default 1

Draws a rectangle with round corners

OLED1_RoundRect(10,10,40,40) 'White lined rectangle with round corner of 3
OLED1_RoundRect(10,10,40,40,3,0) 'Black lined rectangle with round corner of 3
OLED1_RoundRect(10,10,40,40,5,1,1) 'White filled rectangle with round corner of 5

OLED1_Circle

OLED1_Circle(x1,y1, r)
OLED1_Circle(x1,y1, r, color)
OLED1_Circle(x1,y1,x2,y2, r, color, fill)

x1,y1: Pixel of center of the circle
r: Radius of the circle >0
color (optional parameter): 0 (black), >0 (white); default 1
fill (optional parameter): 0 (not filled); 1 (filled); default 1

Draws a circle.

OLED1_Circle(20,20,10) 'White lined circle with radius of 10
OLED1_Circle(20,20,10,0) 'Black lined circle with radius of 10
OLED1_Circle(20,20,10,1,1) 'White filled circle with radius of 10

OLED1_Triangle

OLED1_Triangle(x1,y1,x2,y2,x3,y3)
OLED1_Triangle(x1,y1,x2,y2,x3,y3, color)
OLED1_Triangle(x1,y1,x2,y2,x3,y3, color, fill)

x1,y1: 1. Pixel
x2,y2: 2. Pixel
x3,y3: 3. Pixel
color (optional parameter): 0 (black), >0 (white); default 1
fill (optional parameter): 0 (not filled); 1 (filled); default 1

Draws a triangle.

OLED1_Triangle(20,20, 10,30, 30,30) 'White lined traingle
OLED1_Triangle(20,20, 10,30, 30,30,0) 'black lined traingle
OLED1_Triangle(20,20, 10,30, 30,30,0,1) 'White filled triangle

OLED1_Print

OLED1_Print(string)
OLED1_Print(string, color)

string: some text
color (optional parameter): 0 (black), >0 (white); default 1

Prints text at the position of the cursor. The cursor can be set with OLED1_At. The size of the text can be set with OLED1_SetTextSize.

print("SmallBASIC")
print("SmallBASIC", 0) 'Prints "SmallBASIC" in black

OLED1_SetTextSize

OLED1_SetTextSize(size)

size: Size of the text in pixel. Allowed values are 8,16,24,32,40,48,56,64

Sets the size of the text.

OLED1_SetTextSize(16)

OLED1_At

OLED1_At(x,y)

x,y: Position of the cursor in pixel

Sets the cursor.

OLED1_At(10,20)

OLED1_CopyToDisplay

OLED1_CopyToDisplay(A)
OLED1_CopyToDisplay(A,x,y,mode)

A: 2D Array
x,y (optional parameter): Position in pixel; default 0,0
mode (optional parameter): Transparency mode; default 0

Copies a 2D-array to the display buffer. Every element of the array corresponds to a pixel. How an array element is rendered depends on the mode.

'Create an image array with 16x16 Pixels
dim SmilyGuyArray(15,15)

for yy = 0 to 15
  for xx = 0 to 15
    read d
    SmilyGuyArray(xx,yy) = d
  next
next

gpio.OLED1_CopyToDisplay(SmilyGuyArray, 10, 25, 3)

'Smiley Guy
'0=Black; 255=White; Every other number is transparent
DATA   1,  1,  1,255,255,255,255,255,255,255,255,255,255,  1,  1,  1
DATA   1,  1,255,255,255,255,255,255,255,255,255,255,255,255,  1,  1
DATA   1,  1,255,255,255,255,255,255,255,255,255,255,255,255,  1,  1
DATA   1,  1,255,255,  0,  0,  0,  0,  0,  0,  0,  0,255,255,  1,  1
DATA   1,  1,255,  0,255,255,255,  0,  0,255,255,255,  0,255,  1,  1
DATA   1,255,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0  ,0  ,255,1
DATA 255,255,  0,  0,255,255,  0,  0,  0,  0,255,255,  0,  0,255,255
DATA 255,255,  0,  0,255,255,  0,255,  0,  0,255,255,  0,  0,255,255
DATA 255,255,  0,  0,  0,  0,  0,255,255,  0,  0,  0,  0,  0,255,255
DATA   1,255,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,255,  1
DATA   1,255,  0,  0,255,  0,  0,  0,  0,  0,  0,255,  0,  0,255,  1
DATA   1,  1,255,  0,  0,255,  0,  0,  0,  0,255,  0,  0,255,  1,  1
DATA   1,  1,255,  0,  0,  0,255,255,255,255,  0,  0,  0,255,  1,  1
DATA   1,  1,  1,255,  0,  0,  0,  0,  0,  0,  0,  0,255,  1,  1,  1
DATA   1,  1,  1,  1,255,255,255,255,255,255,255,255,  1,  1,  1,  1
DATA   1,  1,  1,  1,  1,255,255,255,255,255,255,  1,  1,  1,  1,  1

OLED1_CopyFromDisplay

A = OLED1_CopyFromDisplay()
A = OLED1_CopyFromDisplay(x,y,w,h)

A: 2D Array
x,y (optional parameter): Position in pixel; default 0,0
w,h (optional parameter): Width and height of the area; default width and height of the OLED

Copies a 2D-array from the display buffer into a 2D-array. Every element of the array corresponds to a pixel. The value is either 0 (black) or 255 (white)

A = gpio.OLED1_CopyFromDisplay() 'Copies full display
A = gpio.OLED1_CopyFromDisplay(10, 10, 16, 16)
gpio.OLED1_CopyToDisplay(A, 50, 10)

OLED1_SetBrightness

OLED1_SetBrightness()
OLED1_SetBrightness(Brightness)

Brightness (optional parameter) 0..255; default 250

Sets the brightness of the display. Higher value for brighter display.

gpio.OLED1_SetBrightness() 'Set brightness to 250
gpio.OLED1_SetBrightness(100) 'Set brightness to 100

OLED1_InvertDisplay

OLED1_InvertDisplay()

Inverts the display. Initialy a value of 0 is black and a value >0 is white. After first call of the function a value of 0 is drawn as white and a value >0 is drawn as black. After second call of the function settings are equal to the initial settings.

gpio.OLED1_InvertDisplay() 'black on white

back to main page