Jump to content

SH1106 128x64 (SSD1306) I2C oled display library


Recommended Posts

Simple library for 128x64. Works fine with SH1106 1.3" OLED and OrangePi Zero (4.9 kernel). You just need to activate I2C interface by replacing "disabled" with "okay" in device tree file (or in the fex). Connect display and test with "sudo i2cdetect -y 0" (or 1). If your display has 3d address instead 3c, change OLED_I2C_ADDR parameter it in the oled.h. Enter "make" to compile and run demo with "sudo ./oled_demo /dev/i2c-0".

 

This library was written by Sonal Pinto for Arduino and ported to Linux by Vladimir Komendantskiy. I just wrote functions for text drawing and add three little fonts. This library only can  draw text at X Y with specified font and draw custom pixel, but it is easy to write line, circle, rectangle drawing functions.

 

ssd1306-i2c-opiz.zip

Link to comment
Share on other sites

it works on mipsel (WRTNode2P board MT7628) openwrt, thank you.

I hv modified send buffer to send at 32 bytes chunk instead of 128, it is MT7628 i2c bug

 

// send buffer to oled (show)
int oled_send_buffer(struct display_info *disp) {
        struct sized_array payload;
        uint8_t packet[129];
        int i;

        packet[0] = OLED_CTRL_BYTE_DATA_STREAM;
        payload.size = 33;
        payload.array = packet;

        for (int index = 0; index < 8; index++) {       
                for(i=0;i<4;i++)
                {
                        memcpy(packet+1, disp->buffer[index]+i*32, 32);
                        oled_send(disp, &payload);
                }
        }
        return 0;
}
 

Link to comment
Share on other sites

Working on my pcduino3 nano, I'm definitely gonna be playing with this more :)

 

Edit:
Oddly enough I was already writing an app for a different project but you can use it to convert an image into a flat binary file you can use to send to the display.

https://github.com/TaraHoleInIt/anim1b

 

(Note: I forgot to enable dithering for this image)

MOFmVmz.jpg

 

It's still very much WIP and is part of another project I'm working on but it can convert an image to be displayed on an oled screen using this library.

 

Example ./anim1b -n -d input_image.png output_flat.bin

 

This would convert the input image to a 1bpp image that you can upload directly to the display.

-n Specifies that no header would be added (It's for my other project)

-d Tells it to use dithering

 

It can also combine multiple images and over the SPI bus on an ESP8266 it manages to play back at 30fps, but that's for playing with another time ;)

 

Link to comment
Share on other sites

This wiring seems Ok !

But what did you do after ?

Did you have loaded the sun8i-h3-i2c0.dtbo overlay ?

Did you wrote some software, either in python or other language, to initialize the OLED properly and write some pixels into it ?

Because, unless doing so, don't expect the kernel itself to display anything there ...

 

Link to comment
Share on other sites

On 1/7/2018 at 1:53 AM, martinayotte said:

This wiring seems Ok !

But what did you do after ?

Did you have loaded the sun8i-h3-i2c0.dtbo overlay ?

Did you wrote some software, either in python or other language, to initialize the OLED properly and write some pixels into it ?

Because, unless doing so, don't expect the kernel itself to display anything there ...

 

Yes i have load the overlay via /boot/armbianEnv.txt as below

 

verbosity=1
console=serial
overlay_prefix=sun8i-h3
rootdev=UUID=bd0ded76-1188-4b52-a20a-64f326c1f193
rootfstype=ext4
overlays=w1-gpio uart1 i2c0 spi-spidev
param_w1_pin=PA20
param_w1_pin_int_pullup=1
param_uart1_rtscts=1
param_spidev_spi_bus=0

then i tried to run a program in Pythod test the oled but nothing happends

Link to comment
Share on other sites

Did you tried "i2cdetect" to see if the LCD is properly detected ?

BTW, as you've mentioned earlier, there are also some LCD that have SPI wires, make sure you are using the I2C instead, mode selection is probably determined by another pin.

 

Link to comment
Share on other sites

2 hours ago, martinayotte said:

Did you tried "i2cdetect" to see if the LCD is properly detected ?

BTW, as you've mentioned earlier, there are also some LCD that have SPI wires, make sure you are using the I2C instead, mode selection is probably determined by another pin.

 

If that wiring list is correct, then it indicates that the display is connected via SPI, not I2C. They sometimes label the MOSI line as SDA, but the presence of CS, DC and RST indicate that it's an SPI device.

Link to comment
Share on other sites

17 hours ago, Larry Bank said:

but the presence of CS, DC and RST indicate that it's an SPI device.

Yes, that is why I've mentioned "mode selection is probably determined by another pin".

According to this datasheet :

https://www.elecrow.com/download/SH1106 datasheet.pdf

some other pins IM0/IM1/IM2 determine what kind of interface is active.

 

 

Link to comment
Share on other sites

On 8/14/2017 at 2:11 AM, Nathanan Srisaard said:

it works on mipsel (WRTNode2P board MT7628) openwrt, thank you.

I hv modified send buffer to send at 32 bytes chunk instead of 128, it is MT7628 i2c bug

 

// send buffer to oled (show)
int oled_send_buffer(struct display_info *disp) {
        struct sized_array payload;
        uint8_t packet[129];
        int i;

        packet[0] = OLED_CTRL_BYTE_DATA_STREAM;
        payload.size = 33;
        payload.array = packet;

        for (int index = 0; index < 8; index++) {       
                for(i=0;i<4;i++)
                {
                        memcpy(packet+1, disp->buffer[index]+i*32, 32);
                        oled_send(disp, &payload);
                }
        }
        return 0;
}
 

I had tried the code on my MT7688. But it gave me a surprise!!! The sh1106 could not be displayed normal,but the ssd1306 could be fine. But in the oled.h from the attachement, "#define OLED_SET_PAGE_ADDRESS 0xB0"  is there ,and i dont know what happen ,it seems that the "#define OLED_SET_PAGE_ADDRESS 0xB0" did not be useful.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines