Skip to content

nopnop2002/Raspberry-ssd1306

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Raspberry-ssd1306

ssd1306 Command Line Tool for RaspberryPi.
This may works with other boards like OrangePi/NanoPi.

You can operate from command line.
You can choose Hardware-SPI/Software-SPI/I2C Interface.

Software requirement

  • WiringPi Library
    This project uses the wiringPiSetup() function to initialize GPIOs.
    If you use it on a board other than the RPI board, you may need to change the WiringPi number.
    As far as I know, there are these libraries.
    • WiringPi for OrangePi
    • WiringPi for BananaPi
    • WiringPi for NanoPi
    • WiringPi for Pine-64

Command line parameters

+1 String : String for #1 line(Use External Font)
+2 String : String for #2 line(Use External Font)
+3 String : String for #3 line(Use External Font)
+4 String : String for #4 line(Use External Font)
+a String : String for #1 line(Use Internal Font)
+b String : String for #2 line(Use Internal Font)
+c String : String for #3 line(Use Internal Font)
+d String : String for #4 line(Use Internal Font)
-1 : delete #1 line
-2 : delete #2 line
-3 : delete #3 line
-4 : delete #4 line
+R n : Set inverse mode #n Line
-R n : Unset inverse mode #n Line
+U n : Set underline mode #n Line
-U n : Unset underline mode #n Line
+L : Scroll Up 1Line
-L : Scroll Down 1Line
P1 n : Set start colum n to line#1
P2 n : Set start colum n to line#2
P3 n : Set start colum n to line#3
P4 n : Set start colum n to line#4
r : remove all string
s : show display

You can use within script.
#!/bin/bash
./oled r
./oled +1 "ABCDEFG"
./oled +2 "abcdefg"
./oled +3 "1234567"
./oled +4 "Hello World!!"
sudo ./oled s


Wire connection for Hardware SPI

OLED RPi Pin# WiringPi#
Gnd -- Gnd
VCC -- 3.3V
D0 -- SCLK #23
D1 -- MOSI #19
RES -- GPIO18 #12 1(*)
DC -- GPIO17 #11 0(*)
CS -- CS0 #24

(*)You can change to another pin.
#define RST 1 // You can change
#define DC 0 // You can change


Wire connection for Software SPI

OLED RPi Pin# WiringPi#
Gnd -- Gnd
VCC -- 3.3V
D0 -- SCLK #23 14(*)
D1 -- MOSI #19 12(*)
RES -- GPIO18 #12 1(*)
DC -- GPIO17 #11 0(*)
CS -- CS0 #24 10(*)

(*)You can change to another pin.
#define MOSI 12 // You can change
#define SCLK 14 // You can change
#define RST 1 // You can change
#define DC 0 // You can change
#define CS 10 // You can change


Wire connection for I2C

OLED RPi Pin#
Gnd -- Gnd
VCC -- 3.3V
SCK -- SCL #5
SDA -- SDA #3

Install SSD1306 for Hardware SPI (128x64)

git clone https://github.com/nopnop2002/Raspberry-ssd1306
cd Raspberry-ssd1306
cc -o oled oled.c fontx.c -lwiringPi -lpthread -DSPI
bash ./test.sh

OLED-128x64


Install SSD1306 for Hardware SPI (128x32)

git clone https://github.com/nopnop2002/Raspberry-ssd1306
cd Raspberry-ssd1306
cc -o oled oled.c fontx.c -lwiringPi -lpthread -DSPI -DX32

The number of lines which can be indicated is only 2 lines.
OLED-128x32


Install SH1106 for Hardware SPI (128x64)

git clone https://github.com/nopnop2002/Raspberry-ssd1306
cd Raspberry-ssd1306
cc -o oled oled.c fontx.c -lwiringPi -lpthread -DSPI -DOFFSET=2
bash ./test.sh

Left:1.3 inch SH1106
Right:0.96 inch SSD1306
OLED-SH1106


Install SSD1306 for Software SPI (128x64)

git clone https://github.com/nopnop2002/Raspberry-ssd1306
cd Raspberry-ssd1306
cc -o oled oled.c fontx.c -lwiringPi -lpthread -DSOFT_SPI
bash ./test.sh

Install SSD1306 for Software SPI (128x32)

git clone https://github.com/nopnop2002/Raspberry-ssd1306
cd Raspberry-ssd1306
cc -o oled oled.c fontx.c -lwiringPi -lpthread -DSOFT_SPI -DX32

Install SH1106 for Software SPI (128x64)

git clone https://github.com/nopnop2002/Raspberry-ssd1306
cd Raspberry-ssd1306
cc -o oled oled.c fontx.c -lwiringPi -lpthread -DSOFT_SPI -DOFFSET=2
bash ./test.sh

Install SSD1306 for I2C (128x64)

git clone https://github.com/nopnop2002/Raspberry-ssd1306
cd Raspberry-ssd1306
cc -o oled oled.c fontx.c -lwiringPi -lpthread -DI2C
bash ./test.sh

OLED-1


Install SSD1306 for I2C (128x32)

git clone https://github.com/nopnop2002/Raspberry-ssd1306
cd Raspberry-ssd1306
cc -o oled oled.c fontx.c -lwiringPi -lpthread -DI2C -DX32

The number of lines which can be indicated is only 2 lines.
oled-3


Install SH1106 for I2C (128x64)

git clone https://github.com/nopnop2002/Raspberry-ssd1306
cd Raspberry-ssd1306
cc -o oled oled.c fontx.c -lwiringPi -lpthread -DI2C -DOFFSET=2
bash ./test.sh

Left:1.3 inch SH1106
Right:0.96 inch SSD1306
OLED-SH1106

Font File

This tool uses the following as default fonts:

  • fontx/ILGH16XB.FNT // 8x16Dot Gothic
  • fontx/ILMH16XB.FNT // 8x16Dot Mincyo

Changing this file will change the font.

  // You can change font file
  Fontx_init(fx,"./fontx/ILGH16XB.FNT","./fontx/ILGZ16XB.FNT"); // 16Dot Gothic
  //Fontx_init(fx,"./fontx/ILMH16XB.FNT","./fontx/ILMZ16XB.FNT"); // 16Dot Mincyo

You can add your original fonts.
The format of the font file is the FONTX format.
Your font file is put in fontx directory.

Please refer this page about FONTX format.

Font File Editor(FONTX Editor)

There is a font file editor.
This can be done on Windows 10.
Developer page is here.

fontx-editor-1

Convert from TTF font to FONTX font

step1)
Download WFONTX64.exe from here. Developer page is here.

step2)
Select ttf font.
Please note that if you select a proportional font, some fonts may not convert correctly.
If you select a proportional font, some fonts will need to be modified using fontxedit.exe.
Monospaced fonts can be converted correctly.
Algerian16-1

step3)
Enter Height, Width, FontX2 name.
Specify half of Height for Width.
Specify your favorite font name in the FontX2 name field using up to 8 characters.
Algerian16-2

step4)
Specify the file name to save.
Algerian16-3

step5)
Specify the font style as required.
Algerian16-4

step6)
Press the RUN button to convert TTF fonts to FONTX format.
Algerian16-5

step7)
upload your font file to $HOME/Raspberry-ssd1306/fontx directory.

step8)
add font to use

  // You can change font file
  //Fontx_init(fx,"./fontx/ILGH16XB.FNT","./fontx/ILGZ16XB.FNT"); // 16Dot Gothic
  //Fontx_init(fx,"./fontx/ILMH16XB.FNT","./fontx/ILMZ16XB.FNT"); // 16Dot Mincyo
  Fontx_init(fx,"./fontx/Algerian16.FNT",""); // 16Dot Algerian

Algerian16-6


Left : OrangePi + SPI Module
Right : RaspberryPi + I2C Module
oled-2


OLED-1

OLED-2

Line1-2 : External Font
Line3-4 : Internal Font
OLED-4

Underline and Invert
OLED-5

Set start colum
OLED-6

OLED-7


RaspberryPi ZERO HAT + OLED
RaspberryPi-ZERO

OrangePi ZERO HAT + OLED
zero-hat-7

Releases

No releases published

Packages

No packages published