Thursday, August 7, 2014

Arduino - TFT LCD display refresh rate part 2

Since January I have been thinking about how to reduce the flashing effect of redrawing characters on the Adafruit 2.2" TFT display running off of an Arduino. Initially I thought I was doing something wrong but then I saw that other projects experience the same slow screen redraw performance. This post isn't about rewriting/optimizing the ILI9340 library that talks to the display. I'm not a good enough programmer to even think about digging into that code. Also I don't think it really is a problem with the library or the display itself. I've seen videos with this display hooked up to a Raspberry Pi smoothly playing video files. I suspect the limitation is the CPU and/or RAM of the Arduino. For my speedometer project I wanted to use an Arduino because it starts up almost instantly and I don't have to worry about shutting it down which is not the case with a Raspberry Pi.

So my goal was to optimize the refresh rate by reducing the amount of screen redraw to the smallest amount possible. To do this I first draw the static elements on the screen (the red box and the mph text). These are never redrawn. Redrawing static items causes a flashing effect. Then the speed value is only updated if it changes. When it does change only digits that have changed are redrawn. For example say the speed is 35 mph and then on the next loop the speed is 36 mph. The 5 would be drawn over with black and then the 6 is drawn in white. This performs the least amount of screen drawing possible.

Here is a video of the progress so far. The code is below the video.



Here is the code


5 comments:

  1. Hello,

    In case you are still interested, I "re-mixed" (re-wrote) the Adafruit GFX library and some drivers (including IL9341 & IL9342) to squeeze out any wasted cycles (there were a lot). My "PDQ" version is sketch compatible with Adafruit GFX (with a tiny change to init), so you might give it a try (should be "drop in"). All the code and an example sketch/benchmark is at https://github.com/XarkLabs/PDQ_GFX_Libs. You can see a speedup of about 3.5x to 13x (depending on the primitive). Smaller code size too.

    Enjoy,
    Xark

    ReplyDelete
  2. why i got this im new in arduino Documents\Arduino\sketch_apr05b\sketch_apr05b.ino:2:26: fatal error: Adafruit_GFX.h: No such file or directory

    #include "Adafruit_GFX.h"

    ^

    compilation terminated.

    exit status 1
    Error de compilaciĆ³n

    ReplyDelete
    Replies
    1. I think you just need to add the Adafruit-GFX library to your Aduino IDE. https://github.com/adafruit/Adafruit-GFX-Library

      Delete
  3. it does not work i am also having the same issues

    ReplyDelete
  4. Thanks for posting this. Your example saved me tons of time. I'm putting together a display for my car that will show metrics that are available on the OBDII bus. (I'm using a Freematics OBDII Arduino interface). Thanks again!

    ReplyDelete

Please note all comments are moderated by me before they appear on the site. It may take a day or so for me to get to them. Thanks for your feedback.