Jump to content
Rei Vilo

[Energia Library] Nokia 5110 LCD BoosterPack/Breakout PCB

Recommended Posts

Rei Vilo,

Is there a way to set the contrast with this library?

 

 With the Adafruit version of this library, there is a command like:

display.setContrast(50);

Share this post


Link to post
Share on other sites
No, I haven't included a contrast command in my library.

 

Two reasons:

  • setting the contrast isn't used frequently,
  • and taking a wrong value may rise confusion as nothing is seen on the screen.
I prefer setting a contrast that ensures a visible screen.

 

Adding one is easy:

  • on LCD_5110.h, add


void setContrast(uint8_t value);


  • on LCD_5110.cpp, add


void LCD_5110::setContrast(uint8_t value) {
    if (value > 0x7f) value = 0x7f;


    write(_commandLCD, 0x21);
    write(_commandLCD, 0x80 + value);
    write(_commandLCD, 0x20);
}

Share this post


Link to post
Share on other sites

Rei,

Thanks so much for your help - that's exactly what I needed. I've included before and after setContrast commands to show you what a big difference it made. (I've set the contrast to 60 in the photo on the right.)

 

8854862055_5d76b1c9e0.jpg8854862139_07bf5ee614.jpg

 

Also, I did make some minor changes to that code to get it to compile (just in case anyone else is trying to use it). I had to add a comma and a close parenthesis on each line of the .cpp code, so that it looked like:

void LCD_5110::setContrast(uint8_t value) {

if (value > 0x7f) value = 0x7f;

 

 

write(_commandLCD,(0x21));

write(_commandLCD,(0x80 + value));

write(_commandLCD,(0x20));

}

 

 

 

Again, thanks so much for your quick and accurate reply Rei - your contributions to the Energia and 43oh communities are tremendous.

Share this post


Link to post
Share on other sites

Also, I did make some minor changes to that code to get it to compile (just in case anyone else is trying to use it). I had to add a comma and a close parenthesis on each line of the .cpp code, so that it looked like:

 

You're welcome! Thank you for fixing my typo! I've updated my code accordingly.

 

Now, once you have the right value for the contrast, you can modify the LCD_5110::begin() function with another value instead of 0x48, which is the value that provides the best contrast on my specific screen:

void LCD_5110::begin() {...write(_commandLCD, 0x80 + 0x48); // write VOP to register: 0xC8 for 3V 

Share this post


Link to post
Share on other sites

Sounds like a plan.  Or even use a small potentiometer to make the value adjustable by the user.  I've got 5 of these displays and have found them all to need slightly different contrast values.  Thanks again again Rei.

Share this post


Link to post
Share on other sites

I have this working great but now I'm try send bitmaps stored as arrays of hex bytes to the 5110 LCD.

 

Has anyone done this?

 

I thought I could just use the write method of this library but it's private.

Share this post


Link to post
Share on other sites

I'm having trouble reading hex bitmaps from a file on a SD card and getting them to display properly.

 

I'm currently able to successfully:

 

1. Read text files from my SD Card.

 

2. Display bitmap images stored in the code as arrays of hex chars using a modified version of the 5110 LCD library where I made the 'write' function public.

 

What I'm NOT able to do is successfully get a file of hex chars to display correctly after reading the chars in.

I'm taking bitmaps from my program that are stored like this:

 

uint8_t face_pic[]={
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // 0x0010 (16) pixels
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // 0x0020 (32) pixels
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xF0, 0x98, 0x88, 0x84, 0x04,   // 0x0030 (48) pixels
0x04, 0x02, 0x72, 0xD2, 0x5A, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // 0x0040 (64) pixels
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // 0x0050 (80) pixels
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // 0x0060 (96) pixels
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0,   // 0x0070 (112) pixels
0x60, 0x10, 0x08, 0x08, 0x04, 0x82, 0x42, 0x41, 0x81, 0x01, 0x00, 0x00, 0x00, 0x00, 0x07, 0x04,   // 0x0080 (128) pixels
0x84, 0x40, 0x40, 0x81, 0x01, 0x01, 0x02, 0x02, 0x04, 0x08, 0x08, 0x10, 0x60, 0xC0, 0x80, 0x80,   // 0x0090 (144) pixels
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // 0x00A0 (160) pixels
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // 0x00B0 (176) pixels
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // 0x00C0 (192) pixels
0x00, 0xF8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x02, 0x01, 0x60, 0x70, 0x4C,   // 0x00D0 (208) pixels
0xC0, 0x80, 0x00, 0x00, 0x01, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // 0x00E0 (224) pixels
0x00, 0x0F, 0x07, 0xF9, 0x07, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // 0x00F0 (240) pixels
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // 0x0100 (256) pixels
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // 0x0110 (272) pixels
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0E, 0x30, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70,   // 0x0120 (288) pixels
0x88, 0x44, 0x24, 0x14, 0x14, 0x14, 0x88, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // 0x0130 (304) pixels
0x00, 0x00, 0x00, 0x80, 0x60, 0x31, 0x0F, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // 0x0140 (320) pixels
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // 0x0150 (336) pixels
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // 0x0160 (352) pixels
0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x40, 0x40, 0x40, 0x40, 0xC0, 0x40, 0x60, 0x20, 0x21, 0x21,   // 0x0170 (368) pixels
0x22, 0x24, 0x24, 0x38, 0x08, 0x09, 0x11, 0x11, 0x11, 0x11, 0x10, 0x10, 0x10, 0x10, 0x10, 0x08,   // 0x0180 (384) pixels
0x18, 0x28, 0x24, 0x24, 0x22, 0x41, 0xC1, 0x40, 0x40, 0x40, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00,   // 0x0190 (400) pixels
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // 0x01A0 (416) pixels
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0,   // 0x01B0 (432) pixels
0x30, 0x18, 0x04, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0xC0, 0x70, 0x0C, 0x07, 0x01, 0x00,   // 0x01C0 (448) pixels
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // 0x01D0 (464) pixels
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x7E, 0x00, 0x00, 0x00,   // 0x01E0 (480) pixels
0x00, 0x00, 0x01, 0x01, 0x02, 0x06, 0x04, 0x08, 0x10, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,   // 0x01F0 (496) pixels
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
};

and turn them into a text file on an SD card that looks like this:

 

00000000000000000000000000000000
00000000000000000000000000000000
0000000000008080808080F098888404
040272D25A7C00000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
000000000000000000000000000000C0
60100808048242418101000000000704
84404081010102020408081060C08080
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00F8070000000000000102020160704C
C0800000010202010000000000000000
000F07F907FC00000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
0000000000010E306080000000000070
88442414141488700000000000000000
0000008060310F030301000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000080804040404040C04060202121
22242438080911111111101010101008
182824242241C1404040808080800000
00000000000000000000000000000000
000000000000000000000000000080C0
30180402020101000000C0700C070100
00000000000000000000000000000000
0000000000000000000000037E000000
00000101020604081060800000000000

When I try to read the file and display it I'm clearly not giving the proper characters across to the write function and I'm getting a garble image (see attachment).

 

Any suggestions on either how to do this properly... or an easier method to deal with bitmaps like this?

 

 

post-33751-0-64893600-1379903181_thumb.png

Share this post


Link to post
Share on other sites

I'm having trouble reading hex bitmaps from a file on a SD card and getting them to display properly.

 

I'm currently able to successfully:

 

1. Read text files from my SD Card.

 

2. Display bitmap images stored in the code as arrays of hex chars using a modified version of the 5110 LCD library where I made the 'write' function public.

 

What I'm NOT able to do is successfully get a file of hex chars to display correctly after reading the chars in.

I'm taking bitmaps from my program that are stored like this:

 

uint8_t face_pic[]={
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // 0x0010 (16) pixels
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
*snip*

and turn them into a text file on an SD card that looks like this:

 

00000000000000000000000000000000
00000000000000000000000000000000
0000000000008080808080F098888404
040272D25A7C00000000000000000000
*SNIP*

When I try to read the file and display it I'm clearly not giving the proper characters across to the write function and I'm getting a garble image (see attachment).

 

Any suggestions on either how to do this properly... or an easier method to deal with bitmaps like this?

 

ASCII 0 is Hex 0x30, ASCII F is 0x46. Without seeing the code you are using, I expect that's might be the issue. If you are not converting the ascii character to the proper value (subtract 0x30 for 0-9, subtract 0x31 for A-F [cap sensitive]) and anding them properly before sending them (you could be adding them backwards, i.e. you expect 0x01 but you are sending 0x10).

Share this post


Link to post
Share on other sites

@@cde thanx for the help!

I spent a little time and got it working with a quick hex2int function that I then converted back to the resulting character and could send it back to the write function:

// grab 2 hex chars from file stream
code[0]=buffer[i];
code[1]=buffer[i+1];

//convert 2 hex chars to single int value between 0-255 and then to single char before sending to LCD
myScreen.write(0x0c, char(hex2int(code,2))); 

Thanx again!

Share this post


Link to post
Share on other sites

I have it working nicely with one, but Is it possible to control two Nokia LCD 5110's using this library?

 

I would like to use them simultaneously and sometimes alternating.

Share this post


Link to post
Share on other sites

I have it working nicely with one, but Is it possible to control two Nokia LCD 5110's using this library?

 

I would like to use them simultaneously and sometimes alternating.

I'm no c++ expert (or user or fan) but the library is built using constructors. You can use the default values, or you can use your own values. The only unique pin would be the Chip-Select.

 

Instead of just initializing it as "LCD_5110 myScreen;" you would need

LCD_5110 screenOne;
LCD_5110 screenTwo(Another Free Pin,    // Chip Select
             P2_4,    // Serial Clock
             P2_0,    // Serial Data
             P2_3,    // Data/Command
             P1_0,    // Reset
             P2_1,    // Backlight
             PUSH2);   // Push Button 2 Or Different)

That's for the software SPI with default pins for the g2553. Each screen would be individually controlled with screenOne.write or screenTwo.write, etc.

 

See the library here: https://github.com/energia/Energia/blob/master/examples/7.Display/LCD_5110/LCD_5110.cpp or https://github.com/energia/Energia/blob/master/examples/7.Display/LCD_5110_SPI/LCD_5110_SPI.cpp for the hardware SPI version.

Share this post


Link to post
Share on other sites

Hi guys so i've been trying to get this to work with the new TM4129 launchpad. I was feeling lazy so i decided to use this and maybe later create some coding to use the SSI hardware.

 

So instantly i tried to use multiple screens.

Well i didn't work. It seemed that the second screen was writing over the first screen.

So i went and see the pin variables in the library.

Well, the variables are in the LCD_5110.cpp istead of being in the LCD_5110.h. This makes as if you had a global variable.

The library needs to put the pins variables in the "private" of the class

Share this post


Link to post
Share on other sites

Well, the variables are in the LCD_5110.cpp istead of being in the LCD_5110.h. This makes as if you had a global variable.

 

No, the variables declared in the C++ file aren't global as the main sketch don't have access to them.

 

Global variables need to be declared on the C++ file and also on the header with the extern keyword.

 

Feel free to improve and share the library  :smile:

Share this post


Link to post
Share on other sites

No, the variables declared in the C++ file aren't global as the main sketch don't have access to them.

 

Global variables need to be declared on the C++ file and also on the header with the extern keyword.

 

Feel free to improve and share the library  :smile:

Well, still it makes it impossible to have multiple screens

 

Right now i'm trying to use the I2C in the new launchpad. The idea is to use the MSP430 as a slave i2c controler for the nokia5110

 

when i have a little more time in the weekend i'll try t

Share this post


Link to post
Share on other sites

I'm now working with the sample Nokia LCD code on the SparkFun site and it's working very well.

 

https://learn.sparkfun.com/tutorials/graphic-lcd-hookup-guide/example-code-1-lcd-demo

 

I'm now trying to figure out a way to get the included example bitmap image (an XKCD cartoon) to scroll across the screen (from off-screen-right to off-screen-left) but struggling with how to adjust the image in the "displayMap" array.

 

Anyone use this code or do something similar?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...