Displaying Graphics on ST7920

I am trying to display a 54x54 bitmap (its a qrcode) on my LCD Display.

I am following the directions from this page
http://arduino.cc/playground/Code/LCD12864

Here is my code which is relatively simple

#include <LCD12864.h>

void setup() {
LCDA.Initialise(); // INIT SCREEN
delay(500); // Some delay
LCDA.Render(); // Start the Rendering process
LCDA.DrawSprite(5,0); // 5 is the xPOS, 0 is the yPOS 
delay(500); // you may or may not need the delay 
LCDA.RenderScreenBuffer(1); 
}

void loop() { 

}

Here is the LCDsprite.h

static int swidth = 54; // change these
static int sheight = 54; // change these


static const prog_char header_data[] PROGMEM = { // add data here
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,
	1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	1,1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,
	1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,1,1,
	1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	1,1,1,1,0,0,0,0,0,0,1,1,1,1,0,0,
	1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,1,1,
	1,1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,
	1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,
	1,1,0,0,1,1,0,0,1,1,1,1,1,1,1,1,
	1,1,0,0,1,1,
	1,1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,
	1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,
	1,1,0,0,1,1,0,0,1,1,1,1,1,1,1,1,
	1,1,0,0,1,1,
	1,1,0,0,1,1,0,0,0,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1,1,0,0,1,1,1,1,1,1,1,1,0,0,1,1,
	1,1,0,0,0,0,1,1,1,1,1,1,0,0,1,1,
	1,1,0,0,1,1,
	1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
	1,1,0,0,1,1,1,1,1,1,1,1,0,0,1,1,
	1,1,0,0,0,0,1,1,1,1,1,1,0,0,1,1,
	1,1,0,0,1,1,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
	1,1,1,1,1,1
	};

It looks like the command
LCDA.RenderScreenBuffer(1);

Draws to the top part of the LCD display and
LCDA.RenderScreenBuffer(2);

Draws to the bottom

But I dont know how to specify two different images (one for the top and one for the bottom)

This is an arduino uno, arduino 1.0 and an LCD 128x64 display

So my questions are:

  • How do I specify 1 sprite for the top line and 1 for the bottom?
  • Is there any updated code or different lib that would work with an ST7920?
  • How can I save on memory? prog_char seems to be a waste

End goal is to display multiple images (not concurrently) and it being fed through the USB cable.

Thanks,
Larry Apolonio

I figured it out, also learned that displaying images takes a nice chunk of SRAM.

Anyway, I had to split the image into two and display half at a time.

Learned a lot about the sprite, found easier way to do it and save RAM (Program Memory)

I guess the bigger lesson for me is to look at the code. Thank goodness this is open source, also some programming I did on BMP files 13 years ago helped.

Here is the dirty:

Found this code

void LCD12864::DrawSprite(uint8_t xPos, uint8_t yPos) {
int count = 0;
for (int j = 0; j < sheight; j++) {
for (int i = 0; i < swidth; i++) {
if (pgm_read_byte_near(header_data + count) == 1)
this->DrawScreenBuffer(xPos+i,yPos+128+j);
count++;
}
}
}

Not know much about OOP, inheritance, and kind of want to see if this worked, I copied and made the following functions

void DrawSprite1(uint8_t xPos, uint8_t yPos) {
int count = 0;

// Zero out screen buffer
for (int j = 0; j < 31; j++) {
for (int i = 0; i < 15; i++) {
LCDA.ScreenBuffer[i][j] = 0;
}
}

for (int j = 0; j < 32; j++) {
for (int i = 0; i < swidth; i++) {
if (pgm_read_byte_near(header_data + count) == 1)
LCDA.DrawScreenBuffer(xPos+i,yPos+128+j);
count++;
}
}
}

void DrawSprite2(uint8_t xPos, uint8_t yPos) {
// Zero out screen buffer
for (int j = 0; j < 31; j++) {
for (int i = 0; i < 15; i++) {
LCDA.ScreenBuffer[i][j] = 0;
}
}

int count = 1728;
for (int j = 0; j < 22; j++) {
for (int i = 0; i < swidth; i++) {
if (pgm_read_byte_near(header_data + count) == 1)
LCDA.DrawScreenBuffer(xPos+i,yPos+128+j);
count++;
}
}
}

Here is how I called it

DrawSprite2(5,0); // 5 is the xPOS, 0 is the yPOS 
delay(500); // you may or may not need the delay 
LCDA.RenderScreenBuffer(2); 
DrawSprite1(5,0); // 5 is the xPOS, 0 is the yPOS 
delay(500); // you may or may not need the delay 
LCDA.RenderScreenBuffer(1);

I agree this is ugly code, just figured it out and wanted to post it, I will do a write up of something cleaner, but this gives the gist of it.

arduinoqrcode.jpg

Thank you for sharing your problem and your success. We frequently learn more from our problems than we do from our successes. Would you mind sharing your wiring interface?

I looked at the Playground page you referenced and it was listing wiring to pin D16, D17, etc. Therefore, I assumed you need a Mega to use the interface. However, you have an Uno and that is very similar in capabilities to the Nano I use. I use the Nano because it is a little cheaper and VERY easy to breadboard.

Also, what type of display do you have? It seems there are several. The one I have allows for SPI serial interface so I can connect it to my Nano with only 3 wires (SS, MOSI, and SCK). This is great in that it gives me more pins to work with. However, the trade-off is probably speed.

Actually I started on a nano for this project and it broke. Apparently there is an issue with the batch I had from gravitech.

So I ordered a nano, in the interim I am using my spare uno.

On the Uno, the Analog pins can be used as Digital pins, so in this particular project D2 to D13 is used as is and A0=D14, A1=D15, A2=D16, A3=D17, A4=D18, A5=D19

http://arduino.cc/en/Tutorial/AnalogInputPins

Here is a link to the one I purchased

http://www.ebay.com/itm/12864-128x64-Dots-Graphic-Blue-Color-Backlight-LCD-Display-Module-/270921242802

There was no datasheet, maybe someone can find one, but this was just an experiment, get my feet wet experience.

I primarily purchased it for text, but now that I can display a scannable QR code, my imagination has expanded.

I have attached a photo of my breadboard.

As you can see there are not many lines. There are probably a lot of limitation. For example I only connected MOSI but not MISO so it may not be possible to read information from the display.

Apparently the key is pulling pin 15 (PSB) to ground. This puts it in serial mode.