GithubHelp home page GithubHelp logo

daschr / pico-ssd1306 Goto Github PK

View Code? Open in Web Editor NEW
113.0 6.0 24.0 29.61 MB

Simple library for using ssd1306 displays with the Raspberry Pi Pico and the pico-sdk.

License: MIT License

C 93.13% CMake 6.76% Makefile 0.11%
raspberry-pi-pico ssd1306 ssd1306-oled pico-sdk c raspberry-pico pico-c-library

pico-ssd1306's Introduction

example vid

pico-ssd1306

Simple library for using ssd1306 displays with the Raspberry Pi Pico and the pico-sdk.

Usage

  • copy font.h, ssd1306.c and ssd1306.h to your project
  • see example

Documentation

Example

  • set PICO_SDK_PATH
  • goto example
  • mkdir build && cd build && cmake .. && make
  • copy the ssd1306-example.uf2 to your Pico

Draw Images

The library can draw monochrome bitmaps using the functions ssd1306_bmp_show_image and ssd1306_bmp_show_image_with_offset.

For converting an image to the supported format, you can do the following:

  • install ImageMagick
  • use convert you_image.png -monochrome your_image.bmp

For embedding your image, you can use tools like bin2c (included in the hxtools package on Debian).

Alternatively, you can you the version included in this repo:

  • go in the tools/ directory
  • make
  • usage: ./bin2c your_image.bmp your_image.h

You may also take a look at the example in the example/ directory.

Fonts

You can also use or own fonts when drawing with ssd1306_draw_char_with_font or ssd1306_draw_string_with_font. The format is:

  1. a 1-D uint8_t array
  2. structure of the array:
    1. the first element of the array is the height
    2. the second element of the array is the width
    3. the third element of the array is the additional spacing between chars
    4. the fourth element of the array is the the first ascii character, this array stores
    5. the fifth element of the array is the the last ascii character, this array stores
    6. the following elements encode the pixels of the characters vertically line by line (see); a line can be encoded as more than one uint8_t values, when the height is greater than 8; please look at font.h and the fonts in the example/ directory

pico-ssd1306's People

Contributors

daschr avatar jajcus avatar lockbox avatar lukaspirkl avatar maro159 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pico-ssd1306's Issues

Conversion from BMP to image.h format

What tool did you use to convert the BMP image to image.h format? What would be the steps to convert ones own image? In addition does your image function allow for only a partial image to be painted or must it be the entire screen? It would be nice to allow say a 20x20 image to be painted at x=25, y=30 for example.

fix sign-compare and maybe-unitialized issues

there's currently some compiler warnings, should be an easy fix to remove them

[build] /home/lockbox/p/hardwarehacking-wg/badge-sdk/lib/pico-ssd1306/ssd1306.c: In function 'ssd1306_bmp_show_image_with_offset':
[build] /home/lockbox/p/hardwarehacking-wg/badge-sdk/lib/pico-ssd1306/ssd1306.c:274:46: error: comparison of integer expressions of different signedness: 'uint32_t' {aka 'long unsigned int'} and 'int' [-Werror=sign-compare]
[build]   274 |     for(uint32_t y=biHeight>0?biHeight-1:0; y!=border; y+=step) {
[build]       |                                              ^~
[build] /home/lockbox/p/hardwarehacking-wg/badge-sdk/lib/pico-ssd1306/ssd1306.c:275:28: error: comparison of integer expressions of different signedness: 'uint32_t' {aka 'long unsigned int'} and 'int32_t' {aka 'const long int'} [-Werror=sign-compare]
[build]   275 |         for(uint32_t x=0; x<biWidth; ++x) {
[build]       |                            ^
[build] /home/lockbox/p/hardwarehacking-wg/badge-sdk/lib/pico-ssd1306/ssd1306.c:276:47: error: 'color_val' may be used uninitialized in this function [-Werror=maybe-uninitialized]
[build]   276 |             if(((img_data[x>>3]>>(7-(x&7)))&1)==color_val)
[build]       |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
[build] cc1: all warnings being treated as errors

Display shows static

Sometimes when i init display, clear it and want to print something, there is just static
Any solution?

Initialisation sometimes ends up with everything on top line

Great library -thank you!!!

About 50% of the time I get everything written to the top line on my SSD1306 and Pico Pi.
I re-ordered your code to match the initialisation sequence in the datasheet and the problem went away.
Perhaps update the repo to reflect my changes - if you agree with them?
Thanks

    // from https://github.com/makerportal/rpi-pico-ssd1306
    uint8_t cmds[]= {
        SET_DISP,
        // timing and driving scheme
        SET_DISP_CLK_DIV,
        0x80,
        SET_MUX_RATIO,
        height - 1,
        SET_DISP_OFFSET,
        0x00,
        // resolution and layout
        SET_DISP_START_LINE,
        // charge pump
        SET_CHARGE_PUMP,
        p->external_vcc?0x10:0x14,
        SET_SEG_REMAP | 0x01,           // column addr 127 mapped to SEG0
        SET_COM_OUT_DIR | 0x08,         // scan from COM[N] to COM0
        SET_COM_PIN_CFG,
        width>2*height?0x02:0x12,
        // display
        SET_CONTRAST,
        0xcf,
        SET_PRECHARGE,
        p->external_vcc?0x22:0xF1,
        SET_VCOM_DESEL,
        0x30,                           // or 0x40?
        SET_ENTIRE_ON,                  // output follows RAM contents
        SET_NORM_INV,                   // not inverted
        SET_DISP | 0x01,
        // address setting
        SET_MEM_ADDR,
        0x00,  // horizontal
    };

How do I access the display buffer?

Hey,
is there a way to directly access the data stored in the framebuffer that is created in the ssd1306_init()?
I tried printf("%d", *oled.buffer);, but it prints zeros for me.

add alternative orientation options

It would be helpful to have the option to rotate the display by 90, 180 or 270 degrees. This way, it can easily be used in different orientations

SSD1306 dimensions

Can you please specify the dimensions of your tested SSD1306 display?
I seem to own a SSD1306 1.3" display and it does not work well with this library. It shows only 5-10% of the display area and the rest is just white noise

Character spacing uses height rather than width

When drawing a string with the ssd1306_draw_string_with_font() function the 'stride' is taken from font[0], i.e. x_n+=font[0]*scale, which is the character height rather than the width. The 'fix' should be to use font[1] but the 8x5 font doesn't have any whitespace in the glyphs so they butt against each other (nice and compact though). A font spacing constant of one pixel can be used, e.g. x_n+=font[1]*scale+1 to work-around this. This is still two pixels per char closer together. If the current spacing was intentional it would be clearer / more reliable if it was explicit, e.g. x_n+=font[1]*scale+3

BTW: I found this while converting an 8x8 bitmap font, however this had the spacing built-in (i.e. designed to be laid next to each other) so looked quite spaced out... and a 16x8 font more so (once I had updated ssd1306_draw_char_with_font() to handle larger chars). I am inclined to add a 'tracking' parameter to the front of the font array. The character set I am converting has the full 256 entries, so I am also inclined to add 'first char' and 'glyph count' parameters to the font array. I'd follow a standard, if I could find one :-)

Displaying bitmap

Hi there amazing work on this library. I was just wondering dose it support displaying custom bit arrays to display images

Question: ssd1306_deinit not included in header file

Is there are reason why the ssd1306_deinit function was not included in the header file? Some use cases don't require the display to be uses all the time. I was wondering if there was any reason why it was not included

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.