New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to display bitmap #57
Comments
You can't really implement bit map graphics without lots of RAM buffer. That's the trade off, SSD1306Ascii gives up bitmap graphics to save 1 KB of RAM. |
You can use this library to display graphics it just takes a little preprocessing to get it to work. Example 1: Display a 8x8 custom character You need to convert the image to a hex array by saving the image as a xbm file or using Image2LCD software. What this does is convert the pixels into a byte array in the format shown below. Think of each bit as a pixel that is either 0 for off or 1 for on. The display accepts these values but in hex format. Here is our image converted to this format. To access the image in your sketch you should store it in flash memory like this To display the image you use oled.setCursor and then use oled.ssd1306WriteRam to transfer each value in the array
Example 2: Display a 32x32 image You can use larger images but you need to slightly modify or call them differently as the display writes in 8 pixel high rows. A 32 pixel high image has 4 rows. Using the technique mentioned above we convert the image and for easy of understanding I've added an empty line between each row of data.
Now to write the image to the display we need add some code to write the first row, set the cursor for the second row, write the second row...etc..etc.
Here is a quick and potato quality video of using both of these examples with this library. |
By graphics I mean a typical 2D API to draw points, lines, rectangles, circles, fill... Yes, you can write bitmaps but I don't plan on graphic extensions like Adafruit GFX. |
Agreed, graphics such as that are outside of the scope of this wonderful little library. If you need something like that you might check out this library as it includes these features while trying to maintain minimal size. |
Guys, the name of this library has Ascii suffix -- it should be sufficient to understand its main goal. 2D API is completely different functionality, requiring too much memory and CPU power. There are lots of libraries that provide it -- Adafruit's GFX, u8g, u8g 2, ssd1306, etc. SSD1306Ascii has different purpose and suits best and better than any other lib exactly these Ascii purpose only. |
Indeed, this library is simple and practical in displaying the Ascii, the grammar is simple and clear, which is why I want to improve on it. In any case, this is a learning process, thank you for your reply. |
@DirtyEngineer Would you share you example code?
[I Removed the code I had posted - I was tired, I realised the error!] Side Note: I really want that as a "splashscreen" kind of thing & would love to have it slide into view like your video (from top or bottom in my case though) I'm an idiot - I just twigged you're using byte in you counter which maxes out at 255, which is why my logo wasn't working (1024 length)...
It works now! |
@IAmOrion Glad you picked up on the byte counter problem. Scrolling the image sideways is pretty simple with this library. Just add another for loop for the "c" variable. (Oh and be sure to use oled. instead of display.)
Notice the c variable is decreasing? The image will slide in from the right to left. The library ignores any data written past column 127 and will truncate the image so it slides in smoothly. If you were to go from left to right you would have to display the entire image as you can't have a negative column start point. You don't notice it much with smaller images but yours is half the screen so it doesn't look right. You could probably get fancy with reading the array in progressively larger chunks until the full image is shown and then increment the column position but that's for another day. You'll need to truncate our image for the above code to work. I quick and dirty commented out the unneeded portions.
If you really want it to slide the image from top to bottom smoothly, I suggest using another library with a buffer as this one isn't setup to do something like that. You need to be able to set the row from 0-63 instead of 0-7 as you will only have 8 frames to scroll the image. |
Thanks 👍 I'll give it a go |
I add a contribution to @DirtyEngineer's answers. I used his code to plot a full screen 128x32 image on my OLED. Here is my code, maybe someone can be interested in.
I conclude with this fantastic website that helped me to obtain a bitmap image from a normal one: https://javl.github.io/image2cpp/. Thank you @DirtyEngineer 👍 |
👋
I made this simple function :
And you can even extend lib class to handle some other SSD1306 lib method, to avoid rewriting working code with the Adafruit lib.
|
The text was updated successfully, but these errors were encountered: