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.
- 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
+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
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
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
OLED | RPi | Pin# | |
---|---|---|---|
Gnd | -- | Gnd | |
VCC | -- | 3.3V | |
SCK | -- | SCL | #5 |
SDA | -- | SDA | #3 |
git clone https://github.com/nopnop2002/Raspberry-ssd1306
cd Raspberry-ssd1306
cc -o oled oled.c fontx.c -lwiringPi -lpthread -DSPI
bash ./test.sh
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.
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
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
git clone https://github.com/nopnop2002/Raspberry-ssd1306
cd Raspberry-ssd1306
cc -o oled oled.c fontx.c -lwiringPi -lpthread -DSOFT_SPI -DX32
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
git clone https://github.com/nopnop2002/Raspberry-ssd1306
cd Raspberry-ssd1306
cc -o oled oled.c fontx.c -lwiringPi -lpthread -DI2C
bash ./test.sh
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.
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
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.
There is a font file editor.
This can be done on Windows 10.
Developer page is here.
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.
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.
step4)
Specify the file name to save.
step5)
Specify the font style as required.
step6)
Press the RUN button to convert TTF fonts to FONTX format.
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
Left : OrangePi + SPI Module
Right : RaspberryPi + I2C Module
Line1-2 : External Font
Line3-4 : Internal Font