Go Down

Topic: A fast PCD8544 library (Nokia 5110) (Read 37821 times) previous topic - next topic


I am using Arduino Mega 2560 and MotorShield what renders using the default pins impossible kinda so I have a question.

Could i use pins 51 and 52 as SDIN and CLK instead, there is no definition for them, but looking trough pin mapping
http://arduino.cc/en/Hacking/PinMapping2560 I see that these pins are MOSI and SCK, also pin 47 is capable of PWM so i would use it for SCE.

Thanks in advance.

The library will use the hardware SPI pins on any Arduino, so you have to use the MOSI and SCK pins of your Arduino.
To configure the DC, SCE and RST pins, open PCD8544_SPI.h and read the comments about pin out changing, everything is explained there in detail.
Please let me know if you have any other questions.


As I mentioned, I cant use the default pins, so i would like to use pins 51 and 52, but there is no definition for them.
On Arduino Mega 2560 51 and 52 are marked as MOSI and SCK.

The SPI pins on the mega are exactly what you mentioned. You actually HAVE to use those pins with this library.
You have to modify the header file to change the mapping for the SCE, DC and RST pins.


There are 3 different MOSI pins actually, tyvm for the information, I thought that maybe i have to define them.
Will give it a shot later.

Right, I've never used a Mega chip, but this library uses the Arduino SPI library, so you have to use the SPI pins you usually use with that lib.



after the changings the display works fine. Now Iam already a step further in my projekt and I added an SD card.
The SD card workes fine. it loggs my data correctly. The display also shows the right text. The only thing is, that printed charakters on the display are disturbed. Looks like the SD card is causing that problem.
In my Loop() the part of my SD card looks like this:
Code: [Select]
digitalWrite(10, HIGH);

  time_t timeStamp = now(); 
  if( timeStamp >= nextTrigger)
    printTemp(actualTemp, coolTemp);
    // write the data to the card at the end of every line
    if (!LogFile.sync())

    nextTrigger = timeStamp + logInterval;// schedule the next log time       

  digitalWrite(7, HIGH);

So, do I have to  disable somthing else that my display doesn't get influenced by the SD card?

Thanks in advance!

Is digitalWrite(10, HIGH); and digitalWrite(10, LOW); meant for the LCD? If it is, you don't need that as the library already sets the appropriate pins automatically.
What do you mean by "disturbed"?
Also leaving SCE low without sending the text right after it (right after it = next command) is not a very good idea, any kind of interference on the SPI bus could potentially cause the display to go a bit haywire.
One more suggestion is to put decoupling capacitors across vcc/gnd pins of the lcd and the sd card, as close to the devices as you can. Something like a 0.1uf on each can help with decreasing interference.


for the fast reply. Pin 10 is the LCD cs and Pin 7 is the SD cs.
so this means I dont have to manipulate the cs pin of the lcd?
With disturbed I mean, the printed words/numbers or part of the words/numbers jumping left/right or beeing deletet for
couple of ms.

Oct 04, 2013, 12:55 pm Last Edit: Oct 04, 2013, 01:01 pm by TheCoolest Reason: 1
That's right, you don't have to manipulate Pin 10. I'm not sure what library you are using for the SD card, but as far as I can remember the default SD library in Arduino doesn't need you to manipulate its pin either.

Regarding the character problems, that sounds to me like a biasing problem, or perhaps contrast.
I sort of adjusted the code to run well on my LCD, but different displays could be different and require other configuration to work properly.
This library allows you to supply your own configuration values to the display, this is 'low level' stuff, but as there are different kinds of displays, I felt that this more advanced option should be available to the user in cases like this.
There are two begin() functions, one which takes no parameters and it initializes the LCD with default values, and another which takes the configuration values from the users. This is how it's declared.
Code: [Select]
void begin(bool invert, uint8_t vop, uint8_t tempCoef, uint8_t bias);
* Invert is a boolean value which lets you choose whether the display will show dark characters on light background (false, no-invert) or light characters on dark background (true, inverted). The default configuration is no-invert.
* vop mainly controls the contrast of the display, usually the value range for this should be between 0xB0 and 0xBF (hexadecimal values). You can go a bit over that, but it isn't recommended and usually isn't needed. I found that my display works best with 0xB6 or 0xB7.
*tempCoef stands for temperature coefficient. You probably shouldn't change it and leave it at the default value of 0x04.
*bias (together with vop) controls the voltage level which powers the LCD itself (glass part, with the crystals). I found that on my display a value of 0x12 works the best, but from looking online I saw recommended values of 0x13 and 0x14.
So what you have to do is "play" around with vop and bias to find a combination which works best for your display.
What I'd suggest you to do is the following:
1. Replace your "lcd.begin();" call with "lcd.begin(false, 0xB7, 0x04, 0x12);" and see if there's an improvement.
2. If there is not try changing bias to 0x13 and/or to 0x14 and see if there is an improvement.
I recommend you not to go over the values I mentioned to make sure you don't damage the LCD.
VOP --> 0xB0 to 0xBF should be fine.
BIAS --> 0x12 to 0x14 should be fine.
Try a few combinations, and you will probably find the one which works best with your display.

Sorry for the long post, but I hope it helps you understand why this problem occurs and how sort it out.


Hey TheCoolest,

thanks a lot for the explanaition. I played around with the values. Now I have better contrast and the letters are darker.
Thanks, looks way better ;) But still the problem occures. What I found out. If I remove the SD card this disturbances disappering. If I enter the SD card again it starts again. Is it possible that the display get values during the spi comunicates with the SD card? But on the other Hand if I increase logInterval to lets say 10 sec. It still disturbes.
Or could it be a hardware problem?
The supply for both devices comes from the 3,3V pin of the UNO. SCLK und MOSI of SD and lcd use the same input of the 4050 level shifter. Should I seperate them?

I think it's possible that the SD introduces interference. If the text itself on the LCD isn't affected (as in no new text added) then it probably has to do with interference on the power lines rather than the data lines, so the 4050 has nothing to do with it.
You should remember that the Arduino's 3.3v line can only supply about 50mA max, and SD cards can chew up much more than that, causing voltage to sag and cause all sorts of disruptions.
Now that I think about it I had a "flickering" issue when I ran an SD card and a 5V HD44780 display. When the card was reading or writing the display would go dim and sort of flicker.
In my next project which will involve using an SD card, I will be using a dedicated 3.3v voltage regulator just for that reason.


Hello again,

after my last post I had change my hardware and now I#m using an seperate voltage regulator for the SD card. After the Hardware change it run just nice. But yesterday the Problem started again. I tried every Idea I have. I used decoupling C of 100nF but it seems to be worse after adding them. I also tried another SD Card which definitive makes the problem a lot worse. The display than flickers really bad and even shows weired things on the display and finaly shows nothing. I really don't know were to find the problem.
Does someone have another idea to fix that problem. Its really a pain in the ass since it was working for the last couple of days without any issues.

Thanks in advance!

I'm not certain what the problem can be, any chance that you could post a schematic of how everything is wired up in your project (including capacitors/resistors/whatnot)?


Hey TheCoolest,

thanks so much for your help. I hope we are going to fix that problem :)
Here are the schematics I have got so far. The LCD is the Nokia5110, the red one.
The SD Shield is from LC Studio a blue one. Maybe you can find something.


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131