Go Down

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

sierramike

Hello !

I've made an improvement to your library, because sometimes you just want the highest speed, sometimes you accept a little speed loss but waste less space on the screen to print more text.

That's the reason why I just inherited from SPD8544_SPI to SPD8544_SPI_XT (XT for Xtended), to introduce new features :
- Support for multiple fonts (by extending the ASCII array, each 96 char page is a font
- Support for inverting display per-character (to provide a highlight feature)
- Support for variable width chars (by using the last row that's always empty to put a bit only on the columns that should be displayed)

Here is the result :


I also created a simple utility using C# to allow editing Fonts / characters in the format needed by the library, with easy "click left" to have a black pixel and "click right" to have a white pixel. You can see on the screenshot below the last row being blacked only on the useful columns :


I will just add an improvement to avoid characters to be split on two lines when there is not enough room on the line to print them, and then I'll post my code.

Anyone interrested?

(P.S. : the only modification I had to do on your lib was to move the "advanceXY" from the private to a protected section of the class in the header file).

TheCoolest

First of all I apologize for not replying earlier, and missing new posts. For whatever reason the email notification didn't work, so I didn't know there were new replies.

@ sierramike

I like what you did, nice work.

I did stop working on the library, since it does exactly what I need it to very quickly. And I posted it online so people can work with it and improve it further. By the way, if you look through threads started by me, I also posted a slightly modified library which works with the 128x64 OLED displays.

Regarding inheriting from it adds a little bit of memory overhead, and most likely a small delay, but I'm not sure how significant it is.

There are many ways to add support for large fonts, it will require some more modification to the original code.

The app for creating custom fonts is a pretty neat idea, I like it!


@ Steeve

Hi,

I would like to test your library with my PCD8544, but i don't understand how to put the good value for pin in "pins_arduino.h"

I have an arduino 1284p and i test to connect the on
Code: [Select]
#define PCD8544_PORT PORTC
#define PCD8544_DDR DDRC // Should be DDRx, x = port name (B, C, D, etc.)

#define PIN_DC 0x02 // PC2
#define PIN_RESET 0x03 // PC3
#define PIN_CE 0x07 // PC7


An nothing, can you help me ?
I have some pin free on the PA4,PA5,PA6,PA7

Thanks
PA* pins are located on PORTA. Therefore what you need to do is change PORTC to PORTA and DDRC to DDRA.
The PIN defines are up to you.
PA4 is 0x10, PA5 is 0x20, PA6 is 0x40, etc. You first decide how you want to wire the display to the pins, and then you define the DC, RESET and CE pins.

sierramike

First of all I apologize for not replying earlier, and missing new posts. For whatever reason the email notification didn't work, so I didn't know there were new replies.
I have the same issue, no notification is sent at all, don't know what's happening on this forum ...

@ sierramike

I like what you did, nice work.

I did stop working on the library, since it does exactly what I need it to very quickly. And I posted it online so people can work with it and improve it further. By the way, if you look through threads started by me, I also posted a slightly modified library which works with the 128x64 OLED displays.

Regarding inheriting from it adds a little bit of memory overhead, and most likely a small delay, but I'm not sure how significant it is.

There are many ways to add support for large fonts, it will require some more modification to the original code.

The app for creating custom fonts is a pretty neat idea, I like it!
Thanks for your remarks, for what I observed on benchmark, using my library with variable font width took 35xxµs to print the screen with 84 chars, whereas using yours it took 30xxµs, so the overhead is acceptable. Also, using my library it uses 286 bytes in SRAM, whereas yours uses 273 bytes, so the SRAM footprint is still limited.

But, mine uses 1900 more program memory bytes, including the new FONT table that takes 2x 480 bytes.

That's what we have to deal with for using the variable width font ...

It suits my personal needs, the same way you created your version, so I like to keep the same spirit!


On another side, could you explain a little how your library uses the SPI bus? Or point to a good tutorial?

I cannot explain how the PORT and DDR are used, I only see some binary operations on it in the writeLcd methods, but nowhere it is passed as argument to SPI library ...

TheCoolest

I'm bypassing the Arduino libraries, and accessing the Atmel chip's pins directly.
You can read the relevant sections in the 328P datasheet, of how the SPI bus and chip's pin ports actually work from the hardware perspective.
In short, each pin is represented by a single bit on a port register (ie. PORTC, PORTD, etc). So binary operations will change the state of a single or multiple pins on a port. The DDRx register controls whether the direction of the port's pins (Output or Input).

lukas12p

@ sierramike

Where can we find Your library for testing?
I'm looking for fast library that could draw also big fonts.

Glentved

Is there an easy way to invert all the signals in the library? To test the library without the hex inverter.
I would like to try it.

robtillaart

overrule the default param of the begin function void begin(bool invert = false);

so try in your code

   void begin(true);
iso
   void begin();


Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Glentved

Thank you robtillaart, it works now. I just had to change the SPI divider also. I guess my wires are too long.

NicRoche

Just a heads up when sourcing screens on ebay. Avoid linxiaosellor. Ship broken goods and drag out dispute period past money back date.

Dr_Ugi

Hi Guys
Just a quick "Thank you" for this great library!

I hacked it about a little and used it for a Pong/Invaders game project that I did with my kids and some of their friends and it worked great:


If you're interested it's all now written up in This Instructable.  Obviously I have credited you as the source of the library.

Thanks again!

Ugi

CidiRome

Hi.

I confess that I've not read all the info in this thread, I'm hoping that some can point me in the right direction.


I'm trying to use this library in conjunction with the jeelib so I can Use a 3310 display with na RFM12b radio transmitter/receiver sharing the SPI bus.

By default the jeelib uses pin D10 for SS and I changed (at least I'm trying to) it to D7 because I'm using D8, D9 and D10 for the display control pins that have to be in the same port.

I would change the ports or even use soft SPI on the 3310 display but I need the spare pins for other things.

Has anyone been able to accomplish this?

Cheers.

TeLarC

Hi,

This library has been exactly what I was after to make my project viable, just didn't have the ram for the other libraries, I'm grateful you posted your code TheCoolest and to robtillaart for your suggestions.

My question is regarding row formatting, what changes would I need to make to sacrifice a row in order to use that pixel space in between certain other rows?

It doesn't matter if the new spacing affects everything, I won't need to go back to normal spacing.

Cheers 

jacekPlacek666

This lib is worth bumping.
Is there any way to make characters smaller? @sierramike could you post your code?

viulian

Thank you for the library! I was able to shave a lot of space from the binary sketch by using it.

Few observations:
a) the 'flicker' when clearing the screen is because in nonFB mode the screen is 'cleared' by drawing empty string that covers the screen and this which takes a while. I had to switch to FB mode, then it acts normal by using clear(0).
b) even if there was a lot of discussion about what are the correct values for vop / bias, I actually had to use 0x98 for vop and 0x12 to get the Nokia 5110 screen I have to look nice.
c) the screen was also acting funny (characters would sometimes jump around, random pixels would turn on/off, shearing effects) and the board would lock up after hours of running. Even if initially I thought it might be a power related issue, I found the culprit to be the SdFat library.

Initially I was using the Arduino provided library wrapper for SdFat (using a DIY shield based on a sdcard/microsd adapter) - and the card would init, but fail to write the file. Then I have switched to SdFat directly, where writing to the file worked. But screen was acting funny as the time went by ... and was getting worse and worse and it almost became unreadable with patches of pixels everywhere, etc. Convinced it is a power issue and waiting for an LM1117 3.3 to arrive, I decided to optimize the code even more and I ended up using tinyFAT. This one had problems also (meaning the lines appended to the file were changed, for example 20:57 would be written as 08:23; append sometimes started in a middle of the file!) so I switched to the Fat16 library.

Now everything runs smooth. Screen is rock stable, no jumpiness / shearing, no random pixels, and the values are correctly written to the sdcard.


Having a capacitor as recommended on the previous posts helped a bit, and also, not powering the backlight of the Nokia screen also helped a bit. Meaning it would act less funny when the thing was turned on, but as the time went by (hours), the effects were more and more noticeable. This made me think it might be a power issue - however, now after a day with Fat16 and everything is normal ... I guess there were few problems on the SPI line.

I have also modified the library to display characters 2 times the size (The equivalent of setTextSize(2) from the Adafruit library), by using a 10x16 array which I fill iterating through the 5x8 equivalent of the letter that has to be written. Still very fast :)

aehimself

I am using this library for a really long time and I have to say I am extremely satisfied! I only have one question... how to change the contrast during run-time?

Re-initializing with a new lcd.begin() is not working, just pushes the screen to blank :(

Go Up