Sorry, you need to enable JavaScript to visit this website.

Zedboard OLED

Let me start with this took me way longer than it should have.  Like, 4 hours long.

When you boot your ramdisk image on the Zedboard (or at least at the time of this post this is the case) you will find a logo.bin file within your /root directory.  This file is 512bytes large and is used with the script that is found in the /usr/bin directory called load_oled.

Digilent has written a driver that get's insmod'ed into the kernel that talks to the OLED display that is on the Zedboard.  This driver maps to /dev/zed_oled and you can just push data to it to load the display with something new.  Here is what the script has in it:

#!/bin/sh
insmod /lib/modules/`uname -r`/pmodoled-gpio.ko;

if [ -c /dev/zed_oled ]; then
        cat /root/logo.bin > /dev/zed_oled;
fi;

Not exactly anything crazy.  All we are doing is pushing the entire contents of the /root/logo.bin file to the /dev/zed_oled device.  So what took me so long you might ask!?

The .bin file format.  That's what.  How the driver is written is kind of confusing and since I had zero documentation on it, it took a while of poking around and writing random things to the screen to finally figure it out.

The screen is written to right to left, top to bottom with each pixel being represented by a bit within one of the bytes within the .bin file.  Bits are read-in top down 8 pixels then move over 1 pixel and write the next 8 bits and continue until you are at the end of the row.  Then move down 8 pixels and do this again 3 more times.  Not the most intuitive ... but I figure it out, so that's all that matters :D

But ZynqGeek, how am I supposed to do anything with this information you might ask!

Well just download my little utility that converts .png files to .bin files of course!  It is written in C# and has been tested on Windows-7.  You will need Visual Studio to compile it, and the .Net Framework Version 3.5 to run it.  At the moment there is no install utility, it is simply just code in the repo.

https://github.com/zynqgeek/zedboard_oled_util

I have included the /bin/Release/oled_util.exe file in the repo.  If you have Windows-7 and .Net 3.5 installed it *should* run on your machine :D

If you want to make your own files, they need to be 128x32 png files.  Anything that is white (that is R, G, and B all are 0xFF (255 dec)) will be black on the display.  Anything that is not white will show up as illuminated.

Here is the commands I used to create the images below:

zynq> cd /usr/bin
zynq> ./unload_oled
[11950.440000] pmodoled-gpio-spi [zed_oled] spi_remove: Device Removed
zynq> ./load_oled
[11953.490000] pmodoled-gpio-spi [zed_oled] SPI Probing
zynq> cat /root/zynqgeek.bin > /dev/zed_oled

If you don't know how to get files onto your SD Card or ramdisk image checkout this post.

Before:




After:



That's it!  Let me know what other features you would like to see in the oled_util and I will try and add them as I have time. Enjoy!

Comments

The equivalent octave code:
g = imread('32x128_B&W.png');
g1 = round(g(:,:,1)/256);
g2 = double([g1(1:8,end:-1:1) g1(9:16,end:-1:1) g1(17:24,end:-1:1) g1(25:32,end:-1:1)]);
g3 = uint8(2.^([0:7])*g2);
fid = fopen('logo.bin','w');
fwrite(fid, g3);
fclose(fid);

Pretty cool, thanks for the hacking ;-)

Sweeeeeet. Nice code farmboy! Thanks for taking the time to write it up!

Yeah put my daughters names on the oled... they thought it was sooo cool.

Check this repository out: https://github.com/Digilent/linux-3.3-digilent
It looks like it's Digilents Linux Source. In /drivers/pmods is the OLED Driver.

Hi,

Spent a little time playing around with this on linux and i would like to thank zynqgeek for the format.

Ok, so in summary this is how to use gimp to create the image you want on the OLED display.

1) Open GIMP: Can download here: http://www.gimp.org/downloads/

2) Create a new image:
Width = 128
Height = 32

3) Then go to:
Image => Mode => Indexed => Generate Optimum Pallate
and Set Max Colours to 2

4) Save as:
X BitMap Image
X10 format Bitmap

5) Close and reopen the Image (I cant draw on it until i do - if you can draw then you don't need this step)

6) Use Gimp tools to draw the image you want (Pencil and Eraser are useful :p )

7) Save it again

8) At the bottom of this post there is some C code, copy it to a file.

9) in a terminal display the contents of your image:
cat my_file.xbm
There is a definition of your image as
static unsigned short ...
copy this into the c file, replacing line_bits.

10) Change the NAME and FILENAME definitions

11) compile and run the C code:
gcc -Wall xbm2bin.c -o xbm2bin
./xbm2bin

This should have generated your image as a bin file and printed it out in the terminal. The X's indicate on pixels. To invert it, change INVERT to 1 or 0.

/************************************************
xbm2bin.c
************************************************/
#include <stdio.h>
#include <stdlib.h>

#define WIDTH 128
#define HEIGHT 32
#define SHORT_LENGTH 16
#define BYTE_LENGTH 8

// Name of defined image
#define NAME line_bits

// Filename to write to
#define FILENAME "line_bits.bin"

// Invert image
#define INVERT 0

static unsigned short line_bits[] = {
0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000,
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff,
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff,
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff,
0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff,
0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000,
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff,
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff,
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff,
0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff,
0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000,
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff,
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff,
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff,
0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff,
0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000,
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff,
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff,
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff,
0xffff, 0xffff, 0xffff, 0xffff };

void printDisplay(unsigned short * display){
int i,j;
for( i=0; i<HEIGHT; i++){
for( j=0; j<WIDTH; j++){
if(display[i*WIDTH+j] != 0)
printf("X");
else
printf(" ");
}
printf("\n");
}
printf("\n");
}

int write_to_file(unsigned short * display, char * filename){
FILE * fp;
fp = fopen(filename,"w");
if (fp < 3)
return -1;

int i,j,k;
unsigned char tmp;
for( i=0; i<HEIGHT; i=i+BYTE_LENGTH){
for( j=(WIDTH-1); j>=0; j--){
tmp = 0;
for( k=0; k<BYTE_LENGTH; k++){
tmp = tmp+(display[(i+k)*WIDTH+j] << k);
}
fwrite(&tmp,1,1,fp);
}
}

fclose(fp);
return 0;
}

unsigned short * expandBitMap(unsigned short * bits, unsigned short * display){
int i,j;
for(i = 0; i<(WIDTH*HEIGHT/SHORT_LENGTH); i++){
for(j=0; j<SHORT_LENGTH; j++){
display[i*SHORT_LENGTH + j] = (bits[i] & (1 << j)) >> j;
if(INVERT == 1){
if( display[i*SHORT_LENGTH + j] == 0)
display[i*SHORT_LENGTH + j] = 1;
else
display[i*SHORT_LENGTH + j] = 0;
}
}
}
return display;
}

int main(){
unsigned short * display = malloc(2*WIDTH*HEIGHT);
display = expandBitMap(NAME,display);
printDisplay(display);
write_to_file(display,FILENAME);
free(display);
return 0;
}

in order to not copy/paste each time,
a small enhancement of procedure and C code:

4) Save as:
X BitMap Image
X10 format Bitmap
Identifier prefix: line

save as "line.xbm" file name

) in "xbm2bin.c"

replace all:

static unsigned short line_bits[] = {
...
}

by the single line:

#include "line.xbm"

The content of "line.xbm" should be included at the compilation time,
i.e. update content from the .XBM file,
after
"
gcc -Wall xbm2bin.c -o xbm2bin
./xbm2bin
"

GIMP output a content of "line.xbm" like the following:

"
#define line_width 128
#define line_height 32
static unsigned short line_bits[] = {
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
...
0x0000, 0x0000, 0x0000, 0x0000 };
"

note: Both line_width and line_height will not be used.

Thanks very much for this post.

I use your program to create a .bin, and I can change the OLED for a moment, but it became like before display: "xillinux" and the activity of CP and SDIO. How can I remove that and put what I want? Is it possible to be dinamic my display, like changing the data in display for in five and five second?

Hi, I was trying about change and copy the file of the new logo to the ramdisk8M.image in the Zedboard, I tried this tutorial http://zedboard.org/sites/default/files/blogger_importer/08/zedboard-mod... but I could end it because I use  Windows in my computer and in the tutorial they use Ubuntu. So I descompress the file ramdisk8M.image.gz with 7zip to edit it with a program named OSFMount and it shows me the contents of the file ramdisk8M.image, (I active the checkbox read-write) but when I tried to copy the newlogo.bin to the directory the computer stays on "Copying" and I must to restart it. So please if someone could say me a effective form to edit it from Windows or make these changes from Zedboard Linux. Thanks a lot

Hi, I was trying about change and copy the file of the new logo to the ramdisk8M.image in the Zedboard, I tried this tutorial http://zedboard.org/sites/default/files/blogger_importer/08/zedboard-mod... but I could end it because I use  Windows in my computer and in the tutorial they use Ubuntu. So I descompress the file ramdisk8M.image.gz with 7zip to edit it with a program named OSFMount and it shows me the contents of the file ramdisk8M.image, (I active the checkbox read-write) but when I tried to copy the newlogo.bin to the directory the computer stays on "Copying" and I must to restart it. So please if someone could say me a effective form to edit it from Windows or make these changes from Zedboard Linux. Thanks a lot

You have really fetched lot of time in writing this code which shows your dedication and passion towards this work. Writing down this code in four hours is not that easy being a https://www.australianessays.org/book-review/ blog programmer I know how much difficult to write down this code and that to in such a less time it is really great from you.