Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
CC=gcc
CFLAGS=-I ./ -Wall -Werror
LDFLAGS=-static
OBJS=main.o ssd1306.o linux_i2c.o
BIN=ssd1306_bin
CC = gcc
CFLAGS = -I ./ -Wall -Werror -fPIC
LDFLAGS = -L. -lssd1306
SO_FLAGS = -shared
BIN = ssd1306_cli
LIB = libssd1306.so

SRC_LIB = ssd1306.c linux_i2c.c
OBJ_LIB = $(SRC_LIB:.c=.o)

SRC_BIN = main.c
OBJ_BIN = $(SRC_BIN:.c=.o)

default: $(BIN)
.PHONY: default clean

# Adapted from scottmcpeak.com/autodepend/autodepend.html
-include $(OBJS:.o=.d)
.PHONY: default clean install

# Autodependency generation
-include $(OBJ_LIB:.o=.d)
-include $(OBJ_BIN:.o=.d)

%.o: %.c
$(CC) -c $(CFLAGS) $< -o $*.o
$(CC) -MM $(CFLAGS) $< > $*.d
Expand All @@ -17,9 +27,21 @@ default: $(BIN)
sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
@rm -f $*.d.tmp

$(BIN):$(OBJS)
$(CC) $(CFLAGS) -o $@ $(OBJS) $(LDFLAGS)
# Build the shared library
$(LIB): $(OBJ_LIB)
$(CC) $(SO_FLAGS) -o $@ $(OBJ_LIB)

clean:
rm -f *.o *.d $(BIN)
# Build the CLI tool, linking to the shared lib
$(BIN): $(OBJ_BIN) $(LIB)
$(CC) $(CFLAGS) -o $@ $(OBJ_BIN) $(LDFLAGS)

# Install CLI and shared library
install: $(BIN) $(LIB)
install -Dm755 $(BIN) /usr/local/bin/$(BIN)
install -Dm755 $(LIB) /usr/local/lib/$(LIB)
install -Dm644 ssd1306.h /usr/local/include/ssd1306.h
install -Dm644 linux_i2c.h /usr/local/include/linux_i2c.h
ldconfig

clean:
rm -f *.o *.d $(BIN) $(LIB)
63 changes: 35 additions & 28 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Please make sure the linux has run "modprobe i2c-dev".
**Readme.md** this readme file.
## How to compile
Require make and gcc. If you use cross compile, please self define $(CC).
Type "make" to build binary "ssd1306_bin".
Type "make" to build the library and example binaries.
Type "sudo make install" to install the library to your system.
Type "make clean" to clean the project.
## How to use
- always init oled module ONCE when power up.
Expand All @@ -26,93 +27,99 @@ Type "make clean" to clean the project.
- make sure the XY cursor setting in correct location before printing text
### Params
```sh
-I init oled (128x32 or 128x64 or 64x48)
-c clear (line number or all)
-d 0/display off 1/display on
-I init oled (128x32 or 128x64 or 64x48)
-c clear (line number or all)
-d 0/display off 1/display on
-f 0/small font 5x7 1/normal font 8x8 (default small font)
-h help message
-i 0/normal oled 1/invert oled
-l put your line to display
-m put your strings to oled
-h help message
-i 0/normal oled 1/invert oled
-b read and display a bmp file (128x64 or 128x32 @ 1bpp)
-l put your line to display
-m put your strings to oled
-n I2C device node address (0,1,2..., default 0)
-r 0/normal 180/rotate
-x x position
-y y position
-r 0/normal 180/rotate
-x x position
-y y position
```
## Example
### init the OLED once
- resolution 128x64
```sh
$ ./ssd1306_bin -I 128x64
$ sudo ssd1306_cli -I 128x64
```
- resolution 128x32
```sh
$ ./ssd1306_bin -I 128x32
$ sudo ssd1306_cli -I 128x32
```
- resolution 64x48
```sh
$ ./ssd1306_bin -I 64x48
$ sudo ssd1306_cli -I 64x48
```
### clear display
- clear 1st line
```sh
./ssd1306_bin -c0
$ sudo ssd1306_cli -c0
```
- clear 2nd line
```sh
$ ./ssd1306_bin -c1
$ sudo ssd1306_cli -c1
```
- clear 4th line
```sh
$ ./ssd1306_bin -c3
$ sudo ssd1306_cli -c3
```
- clear whole screen
```sh
$ ./ssd1306_bin -c
$ sudo ssd1306_cli -c
```
### display on/off
- turn off display
```sh
$ ./ssd1306_bin -d 0
$ sudo ssd1306_cli -d 0
```
- turn on display
```sh
$ ./ssd1306_bin -d 1
$ sudo ssd1306_cli -d 1
```
### inverting display
- normal oled (0 is off, 1 is on)
```sh
$ ./ssd1306_bin -i 0
$ sudo ssd1306_cli -i 0
```
- invert oled (0 is on, 1 is off)
```sh
$ ./ssd1306_bin -i 1
$ sudo ssd1306_cli -i 1
```
### displaying a bitmap
- display a 128x64 or 128x32 1bpp bitmap file on the oled
```sh
$ sudo ssd1306_cli -b <file.bmp>
```
### print words
- write line "Hello World"
```sh
$ ./ssd1306_bin -l "Hello World"
$ sudo ssd1306_cli -l "Hello World"
```
- write message "alpha\nbravo\ncharlie\ndelta" (please place \n for next line)
```sh
$ ./ssd1306_bin -m "alpha\nbravo\ncharlie\ndelta"
$ sudo ssd1306_cli -m "alpha\nbravo\ncharlie\ndelta"
```
### I2C device address (default is /dev/i2c-0)
- using /dev/i2c-1
```sh
$ ./ssd1306_bin -n 1
$ sudo ssd1306_cli -n 1
```
### rotate display
- normal orientation
```sh
$ ./ssd1306_bin -r 0
$ sudo ssd1306_cli -r 0
```
- turn 180 orientation
```sh
$ ./ssd1306_bin -r 180
$ sudo ssd1306_cli -r 180
```
### set cursor location
- set XY cursor 8,1(x is column, 8 columns skipping, y is row, 2nd line)
```sh
$ ./ssd1306_bin -x 8 -y 1
$ sudo ssd1306_cli -x 8 -y 1
```
13 changes: 13 additions & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CC = gcc
CFLAGS = -Wall -O2
LDFLAGS = -lssd1306
TARGET = ssd1306_fmv
SRC = ssd1306_fmv.c

all: fmv

fmv: $(SRC)
$(CC) $(CFLAGS) -o $(TARGET) $(SRC) $(LDFLAGS)

clean:
rm -f $(TARGET)
21 changes: 21 additions & 0 deletions examples/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Examples

### FMV Player
Plays a full motion video (bad apple is included for testing) on the OLED, uses an animated bitmap file.

Bitmap file was generated using
```
$ mkdir frames && cd frames
$ ffmpeg -i /path/to/input.mp4 -vf "scale=128:64,format=gray" -pix_fmt monow -vsync 0 frame_%04d.bmp
$ cat frame_* >> ../output.abmp
```

Usage:
```
$ sudo ./ssd1306_fmv [-I 128x64] -n <device> -r <0/128> -a <animation file> -d <frame delay in ms>
```

Example:
```
$ sudo ./ssd1306_fmv -I 128x64 -n 1 -r 0 -a bad_apple.abmp -d 33
```
Binary file added examples/bad_apple.abmp
Binary file not shown.
Loading