Display image w/ OLED from Sparkfun

I'm trying to display images on an OLED from sparkfun:

using the latest library:Google Code Archive - Long-term storage for Google Code Project Hosting.
I followed a tutorial: 4D OLEDS with Arduino
Instead of using printByte I used uoled.sdWriteByte from the new library without success.

Here is my code:
#include <uOLED.h>
#include <colors.h>

uOLED uoled; // create an instance of the uOLED class with the

void setup() {
Serial.begin(9600);
uoled.begin(8,9600, &Serial);
uoled.SetContrast(5); // set the contrast of the display to 5 (0 to 15 default (not always) is 8)
uoled.DeviceInfo(); // display some hardware/software info of the screen
delay(2000); // info will be on screen for 2 seconds
uoled.Cls(); // clears the screen of everything on it. It uses the background color (at this moment it's at default black)
}

void loop(){

//Display first image
uoled.sdWriteByte(0x40); //extcmd in hex
uoled.sdWriteByte(0x49); //cmd in hex
uoled.sdWriteByte(0); //x
uoled.sdWriteByte(0); //y
uoled.sdWriteByte(128); //width 128
uoled.sdWriteByte(128); //height 128
uoled.sdWriteByte(16); //colour mode 16
//sector address of photo
uoled.sdWriteByte(0); //0
uoled.sdWriteByte(10); //16
uoled.sdWriteByte(0); //0

// uoled.sdDisplayImage(0, 0, 128, 128, 1, 4096L);
//uoled.sdDisplayVideo(0, 0, 160, 128, 1, 0x0, 0x10, 0xFA);
//Serial.print("sdDisplayVideo = ");
//Serial.println(uoled.res, HEX);
//uoled.Cls();
}

I also tried the sdDisplayImage command but that didn't work because I'm not sure how to include the address of the image into the command.

Has anyone else worked with the new library of this OLED? Any help would be appreciated.

p.s. the oled does display with the example codes included in the library.

Hi calidude,

sdWriteByte tries to write a byte to the sd memory card if it's connected.

Do you have the picture on the sd-card? Or do you want to send picture data serially to the screen to display?

regards,

Yot

ps.

void setup() {
 [glow]Serial.begin(9600);[/glow] <---- redundant. Get's called from uoled.begin
 uoled.begin(8,9600, &Serial);

Yot,

I have a picture on the sd card formated using their program.I also thought it was weird to use the sdWriteByte but in the example tutorial she uses printByte and sdWriteByte was the closest thing I could find in the new library.

-cali

The routine you are looking for is

sdDisplayImage(byte x, byte y, byte width, byte height, boolean twoBytesPP, long sector);

from the library. This is the routine to display a picture from the sd card.

The printByte and sdWriteByte are not comparable. The first is something like serial.print(value, BYTE) from the arduino libraries and the second writes a byte to the sd card.

Hope this helps,

Jeroen

I've also tried this, but I've had no success with it. The program that formats the pictures creates a text file. Here's an excerpt from the text file:

===========================
SERIAL-PLATFORM OUTPUT FILE
===========================
---------------------------------------------------------------------------------------
File "cabinet.jpg"
Sector Address 0x001000
Width = 128 Height = 128 Bits = 16 (Location and size may be adjusted depending on image size

  • and Size Mode selected)*
    Display Image from Memory Card (Serial Command):
    Syntax:
    @, I, x, y, width, height, colourMode, SectorAdd(hi), SectorAdd(mid), SectorAdd(lo)
    Data:
    0x40, 0x49, 0x00, 0x03, 0x80, 0x7A, 0x10, 0x00, 0x16, 0x00

From Jenny's tutorial she said that the last three hex is the address of the picture and in her program she writes:
//Display first image
printByte(0x40); //extcmd in hex
printByte(0x49); //cmd in hex
printByte(0); //x
printByte(0); //y
printByte(128); //width 128
printByte(128); //height 128
printByte(16); //colour mode 16
//sector address of photo
printByte(0); //0
printByte(16); //16
printByte(0); //0

NOTE: this is using the old library.

I think you're right in that the sdDisplayImage is new way to display the image but I can't figure out how to put the location of the image into that command. I've tried to use the sector address "Sector Address 0x001000" in place of the sector param in sdDisplayImage. I even tried converting the hex.

BTW, thank you for you efforts in helping me! ;D

You did try sdDisplayImage(0, 0, 128, 128, 1, 1600 or 1000); ?

Another option would be that you write your own routine. Change printByte(value) to Serial.print(value, BYTE) or Serial.write(value).

No problem. When i have time i will check that part of the lib.

The library that is on the google code page is a snapshot when i was working on it. There were a few peeps that asked for a copy and from you opening post i realized someone put it on googlecode.

Jeroen

I did, and just to double check I tried it again with and without the L. I will do some research on how to write a routine. I'm still new to this stuff.

If you open the uOLED.cpp file and scroll to void sdDisplayImage(... you will find an example. obviously not a good one as it doesn't work as intended. :slight_smile:

Jeroen

oh gosh. "//TODO!! is this the correct way?" I take it that this method isn't finished or tested then.. no wonder!!! I'm not sure how libraries are written but I assume that if I can directly modify this .cpp file to fix the problem. I'll update if I get anywhere.

Okay so I changed the .cpp file to

void uOLED::sdDisplayImage(byte x, byte y, byte width, byte height, boolean twoBytesPP, byte high, byte mid, byte low)
{
write(0x40);
write(0x49);
write(x);
write(y);
write(width);
write(height);
if (twoBytesPP == true) {
write(0x10);
} else {
write(0x08);
}
write(high);
write(mid);
write(low);
res=RBack();
}

still no luck but I think that's the correct way. I just read somewhere that this oLED doesnt take any sd card above 1gb and I have a 16gb card in it. I will try it again once I get a 1gb sd card.

Cool. Let me (us) know if it works or not.

I thought that the limit was 2 GB for the sd card. Is partitioning the card an option?
I don't know if that would work.

To be sure you that you realize the "quality"of the lib.

The library that is on the google code page is a snapshot when i was working on it. There were a few peeps that asked for a copy and from you opening post i realized someone put it on googlecode.

Jeroen

tip: If you select code in a forum post and hit the # button, code will be better readable. You could modify previous posts.

i finally got it to work on the 1gb cards! I learned that I wasn't supposed to format the card because it wont let the graphics composer write the files correctly to the uSD. Also I changed the .cpp and H files for the image and video sections.

void uOLED::sdDisplayImage(byte x, byte y, byte width, byte height, boolean twoBytesPP, byte high, byte mid, byte low)
{
   write(0x40);
   write(0x49);
   write(x);
   write(y);
   write(width);
   write(height);
   if (twoBytesPP == true) {
        write(0x10);
   } else {
      write(0x08);
   }
   write(high);        
   write(mid);
   write(low);
   res=RBack();
}

void uOLED::sdDisplayVideo(byte x, byte y, byte width, byte height, boolean twoBytesPP, byte fdelay, int frames, byte high, byte mid, byte low)
{
   write(0x40);
   write(0x56);
   write(x);
   write(y);
   write(width);
   write(height);
   if (twoBytesPP == true) {
        write(0x10);
   } else {
      write(0x08);
   }
   write(fdelay);
   write(frames >> 8);
   write(frames & 0xFF);
   write(high);         
   write(mid);
   write(low);
   res=RBack();
}

I'm pretty sure the way it was written before would work the same though. Now I just need to get the video to display correctly. Right now it's just rolling the images down the screen O.o any tips?

Cool you got it working.

...just rolling the images down the screen...

That are basically the video capabilities. Have you tried lowering the fdelay argument?

Jeroen

SWEET. It was a resolution problem. I thought the graphics composer resized the video but it doesn't. I used virtualDub to resize to 128x128 and the video is flawless.

Nice to know that video resolution is important before using the 'graphics composer'.
I thought that the composer took care of that. Now we know for sure. Thanks

Jeroen

thanks for posting the solution to all your problems, these oleds seem really useful but theres hardly any beginner friendly material, thanks!