RA8875_Demo SPI LCD ER-TFTM070-5 K64F

29 Dec 2015

I am using: Windows 8.1, IDE:Kinetis Design Studio, PLATFORM: K64F: MK64FN1M0VLL12, Display: ER-TFTM070-5, PROGRAM: RA8875_DEMO I have made two changes: CHANGES: main.cpp

    RA8875 lcd(D11, D12, D13, D10, NC, "tft");    // MOSI, MISO, SCK, /ChipSelect, /reset, name


    RetCode_t init(int width = 800, int height = 480, int color_bpp = 16, 
        bool poweron = true, bool keypadon = true, bool touchscreeenon = true);

Two errors in the RA8875_Demo code:

main.o "..\\main.cpp" 
In file included from C:\FreeScale\workspace.kds\RA8875_Demo\RA8875/GraphicsDisplay.h:16:0,
                 from C:\FreeScale\workspace.kds\RA8875_Demo\RA8875/RA8875.h:61,
                 from ..\main.cpp:3:
C:\FreeScale\workspace.kds\RA8875_Demo\RA8875/Bitmap.h:23:0: warning: ignoring #pragma push  [-Wunknown-pragmas]
 #pragma push
C:\FreeScale\workspace.kds\RA8875_Demo\RA8875/Bitmap.h:49:0: warning: ignoring #pragma pop  [-Wunknown-pragmas]
 #pragma pop
C:\FreeScale\workspace.kds\RA8875_Demo\RA8875/Bitmap.h:77:0: warning: ignoring #pragma push  [-Wunknown-pragmas]
 #pragma push
C:\FreeScale\workspace.kds\RA8875_Demo\RA8875/Bitmap.h:98:0: warning: ignoring #pragma pop  [-Wunknown-pragmas]
 #pragma pop
In file included from ..\main.cpp:3:0:
C:\FreeScale\workspace.kds\RA8875_Demo\RA8875/RA8875.h: In member function 'void RA8875::AttachPrintHandler(T*, RetCode_t (T::*)())':
C:\FreeScale\workspace.kds\RA8875_Demo\RA8875/RA8875.h:1930:44: error: 'item' was not declared in this scope
         obj_callback    = (FPointerDummy *)item; 
C:\FreeScale\workspace.kds\RA8875_Demo\RA8875/RA8875.h:1931:66: error: 'method' was not declared in this scope
         method_callback = (uint32_t (FPointerDummy::*)(uint32_t))method;
..\main.cpp: At global scope:
..\main.cpp:11:1: error: 'LocalFileSystem' does not name a type
 LocalFileSystem local("local");     // Because I want <PrintScreen>

I searched on Google and found: https://github.com/ceterumnet/Smoothie/blob/master/src/libs/FPointer.h which provided an example on line 112:

    template<class T> 
     void attach(T* item, uint32_t (T::*method)(uint32_t)) { 
         obj_callback = (FPointerDummy *)item; 
         method_callback = (uint32_t (FPointerDummy::*)(uint32_t))method; 

I changed the RA8875.h code:

    template <class T>
    void AttachPrintHandler(T *item, RetCode_t (T::*method)(void)) {
        obj_callback    = (FPointerDummy *)item;
        method_callback = (uint32_t (FPointerDummy::*)(uint32_t))method;

which compiles ok. The error "main.cpp:11:1: error: 'LocalFileSystem' does not name a type" I used Google on mbed: "LocalFileSystem only works on the two original mbed boards (LPC1768 and LPC11u24)." was one answer. If I comment out:

 LocalFileSystem local("local");     // Because I want <PrintScreen>

what other code should I also comment out? I seem to have memory errors:

Open On-Chip Debugger 0.8.0-dev (2015-01-09-16:22)
Licensed under GNU GPL v2
For bug reports, read
Info : only one transport option; autoselect 'cmsis-dap'
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : add flash_bank kinetis kinetis.flash
cortex_m reset_config sysresetreq
adapter speed: 1000 kHz
Started by GNU ARM Eclipse
Info : CMSIS-DAP: FW Version = 1.0
Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : DAP_SWJ Sequence (reset: 50+ '1' followed by 0)
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : IDCODE 0x2ba01477
Info : kinetis.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : accepting 'gdb' connection from 3333
Info : Probing flash info for bank 0
Warn : acknowledgment received, but no packet pending
undefined debug reason 7 - target needs reset
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00000198 msp: 0x20030000
Warn : Any changes to flash configuration field will not take effect until next reset
Info : Padding image section 0 with 528 bytes
Warn : Requested write to flash configuration field 0xffffffff 0xffffffff 0xffffffff 0xfffffdfe transformed to 0xffffffff 0xffffffff 0xffffffff 0xfffffffe

Also the touchTicker.attach_us function seems to "go into a spin". Please see screen shots attached.

Your help would be much appreciated. Kevin.




29 Dec 2015

hi Kevin.

Lots of detail provided. thanks for that. To help isolate defective code from target libraries from external tools and target hardware, can you use the cloud environment to build the sample?

Then we can isolate the file system issue next, and later the offline toolset.

Your profile says you have the lpc1768. can you build for that to see if that is ok?

30 Dec 2015

Hi David,

Thank you for your reply. I have been into my box of bits and pieces and assembled the LPC1769. Its been a while since I was last in the cloud. Your code compiled immediately and produced the part screen size as in the photo. I next had to enter the 800x480 in two places as shown in the screen shots. Changing RA8875.cpp at #define RA8875_DISPLAY_WIDTH 800 and #define RA8875_DISPLAY_HEIGHT 480 was not enough but changing RA8875.h at RetCode_t init(int width = 800, int height = 480, int color_bpp = 16, bool poweron = true, bool keypadon = true, bool touchscreeenon = true); got the full screen started although it looks a bit reduced in length. Please guide me re a more complete change to 800x480.

Many thanks, Kevin.

/media/uploads/kg1/mbedcompiler1s.png /media/uploads/kg1/mbedcompiler2s.png /media/uploads/kg1/mbedcompiler3s.png /media/uploads/kg1/mbed-img_5855_1.jpg /media/uploads/kg1/mbed-img_5856_1.jpg

30 Dec 2015

Hi Kevin,

The init method defaults to the 480x272 screen, but you can alter that w/o changing the library. In your main( ), simply change:




Then, to start testing the screen size, you can start posting pixels to the screen -

lcd.pixel(100,100, Blue);
lcd.pixel(200,200, Red);
lcd.pixel(799,479, Green);

Oh, and it looks like the #define's in RA8875.cpp were not used anywhere - some fragment of an idea that never materialized.

One other thing that comes to mind - when the RA8875 is in 800x480 mode, I don't know if it has the memory to support 16 bits per pixel. It might be that it can, just that it cannot support multiple layers at that resolution (I don't have the datasheet handy to verify this).

31 Dec 2015

Hi David, Writing is possible to all parts of the screen. The code limits a 800x480 screen to one layer. If I change from 16 bits to 8 bits I get fuzzy shapes on the screen. Thanks for your help. Kevin.

31 Dec 2015

ok, so it sounds like you've got the full screen under control [with the lpc1768]. I haven't tried anything with < 16-bits per pixel, but I'll put it in my backlog to take a look at it.

You also mentioned the issue with the LocalFileSystem, which is supported by only a few of the platforms. But if you have a working copy of the SDFileSystem, or the MSCFileSystem, then you could use that. I've been tracking the SDFileSystem and it went unstable a while back, but there was a lot of work done and I think there is a version that can be used (this is also on my backlog). For that, a SPI port is all that is required - and your display module may have the card adapter?

Then, the more challenging perhaps - getting it all running on your target, and with your offline toolset. I'm afraid I won't be as much help in that effort, except to try to answer questions. But if you find some changes that make it work for your target, and not break the cloud-built version, please let me know and I could merge those in.

03 Jan 2016

Hi David,

In the mbed online compiler tested FT5206 library


which seemed slow to get setup but then quite responsive.

Also in mbed compiler I tried to change platform to k64f and was left with error of LocalFileSystem so I decided to run SDfilesystem by Neil Thiessen:


I then return to the KDS IDE and using the micro mbed example for SDfilesystem (see


A web page of interest re RA8875 is https://github.com/sumotoy/RA8875/tree/0.70b11

Still difficult to plan a path forward.

Any comments? Kevin.

04 Jan 2016

Hi Kevin,

My projects have not yet used the capacitive touch panel, so I can't comment on the FT5206 lib. I'm not sure what you mean by slow to get setup - other than in looking at your first screen shot, two things are apparent:

  1. It is running the code to display user fonts. And user fonts are pure software, so much slower than the built-in fonts.
  2. It will try to save an image to the file system, and reading back from the display is also a pretty slow operation. If your comment relates to the FT5206 lib, I glanced at the code, and it seems reasonable, but w/o one of those displays, I cannot comment more.

For the file system work. I ran some simple performance tests a very long time ago, I would consider those obsolete based on the changes to the file system software, but I did find that different SD cards had some difference in performance. From my small sampling, it wasn't a lot of difference as I recall.

It is now able to compile and run in your offline environment?

To tweak the display performance, you might adjust the .frequency(...) of the SPI interface. If your wiring is very short, you might be able to go a bit faster than I can with a rather long cable.

08 Jan 2016

Hello David,

Thank you for your reply. To clarify:

  • With your RA8875 library I have been successful using LPC1768 on mbed.org online compiler.
  • With the FT5206 library I have been successful using LPC1768 on mbed.org online compiler.
  • With K64F on mbed.org online compiler I have been unsuccessful with your RA8875 library and have not tried the FT5206 library.
  • The NXP IDE https://www.lpcware.com/lpcxpresso/home (the free version for the LPC1768 is limited to 256K) I do not have it installed but have tried it previously. I may later reinstall it to experiment further with the LPC1768.

I have been thinking about running your library on yotta. Are you working on this? Contact me by email if you wish to take this off-line. My email address is gordonkevin117(at)gmail.com and my website is www.rescuerobot.org I am retired and have no technical work experience. I will only run your library on yotta to see if I can obtain a K64F version. At the bottom of this page for mbed os is a list of current boards https://github.com/ARMmbed/mbed-os which does not include the LPC1768.



23 Feb 2016

Kevin, I have published my variant of David's RA8875_Demo but for FRDM-K64F with SDFileSystem here:


23 Feb 2016

Thank you Michael. SDFileSystem on K64F works nicely here.



I note that the bmp file is restricted to the default screen size (480x272) whereas I am using 800x480 on buydisplay ER-TFTM070-5.

Also the dates on the above files are 1/01/2098. These are minor matters.

Regarding the LocalFileSystem I believe that there is a flag in mbed that is set if a platform is not compatible. This enables the K64F to fail instantly upon hitting a LocalFileSystem. Perhaps your code can use this flag to switch between LocalFileSystem and SD?

Are there other changes you have made to the original RA8875 library?

I have helped David make changes to the original library to prevent characters printing over the edge of the screen. His latest version has these changes. I have also have word wrap working in my copy at home.

I am interested in these items below:

If I use lcd.init(); with no parameters I get two copies of your screen.

if I use lcd.init(800, 480); I get one copy of your screen.

if I use lcd.init(800,480,8); hard fonts are ok but user soft fonts are a fussy white unreadable. The default is 8 bit.

If I use lcd.init(800,480,16); fonts are back to normal.

if I use lcd.init(800,480,16,0); reset as normal but the screen displays nothing. The default for poweron is 0? What are the mbed rules if a parameter has no default specified?

if I use lcd.init(800,480,16,1); fonts are back to normal, single display.

If I use lcd.init(800,480,16,1,0,0); Not using keypad or touch: fonts are back to normal, single display.

Most interested to receive your comments. If you wish to take this offline please email me gordonkevin117(at)gmail(dot)com



24 Feb 2016

hi Kevin,

The PrintScreen API accepts an x, y, width, and height parameters. And by design, it was intended to support the full screen, or any fractional portion you specify. Of course, there could be defects yet to be revealed.

RetCode_t PrintScreen(loc_t x, loc_t y, dim_t w, dim_t h, const char *Name_BMP);

so in your code do something like this:

RetCode_t r = lcd.PrintScreen(0,0,800,600,"/sd/file.bmp");

Take a look at the documentation (doxygen is working again), or look directly in the header file.
for the .init() function, you'll see the prototype, which includes the default values when you don't specify them:

RetCode_t init(int width = 480, int height = 272, int color_bpp = 16, 
        bool poweron = true, bool keypadon = true, bool touchscreeenon = true);

The color bits per pixel is one feature I have not done much for verification with - and I see from the discussions that it isn't defect free.

24 Feb 2016

Many thanks David. I now understand the default values are in the header files. Would you expect poweron = false would prevent printing on the display?

I hope Michael will return and respond to my comments about K64F.



24 Feb 2016

poweron = false

The data sheet doesn't go into huge amounts of detail, but register 01h controls power, and sleep-wake modes. Probably internal timing chains are stopped, and the LCD drive is [probably] stopped all to reduce current consumption. The default init gets the various configurations set, but this should all happen w/o the backlight or other garbage on the screen. If you call the drawing (or other) APIs while it is "off", I don't know what it will do. I guess many of the other APIs could have been guarded to return a failure code, but that would have injected a few more instructions in the path of every command, so I did not do that.

25 Feb 2016

Kevin, the RTC is typically not initialized on the FRDM-K64F... you want to look at THIS https://developer.mbed.org/users/Sissors/code/RTC/ link to sort that out...

I've not modified anything else in David's library. It works as is, I just had to initialize it with the correct pins for MOSI/MISO

That said, my particular applications have me strictly positioning text at row/column to display dashboard values for various sensors and motors... I don't have much need at the moment for text wrapping, but may find it useful in the future.

I think I might actually find it more useful to have it wrap within a box... hmmm... I'll need to sort THAT out... as in text wrapping within a positional box on the screen. Anyway... I've been able to get away with the default lcd.init() as I have the exact same 4.3" display as David.

I can be reached out of band at unix_guru at hotmail dot com


25 Feb 2016

Hi Michael,

Thank you for the info. I will put the initialisation of RTC on my to do list (correction of file dates and time). It does not seem to be possible to switch between LocalFileSystem and SD using:


A pop-up Textbox is a possibility but restoring the original screen will require more planning.

Many thanks,


25 Feb 2016

Hi David,


Thank you for your comments on poweron. I had presume keypadon and touchscreenon would default to false. Perhaps for capacitive touch I should set them to false everytime?



06 Mar 2016


I have bought a 4.3" panel and I've succeeded to get it work with Davids software. I'm making a clock with the 2 layer option. I just want to jump over to a 7" panel. I was reading that its easy to change the panel size with the instruction: lcd.init(800,480,16). I have checked the layer option with Buy-display and they confirmed that the 2 layer option is working but only for 16 colors. For me this is no problem. I use the render function with a SD card and put bitmaps on the screen ( number 0 to 9). That takes a few second to render 4 numbers but with 2 layers you can present the next minute already on the hidden layer.

I was reading that you also bought a 7" panel and before I do the same ( expensive) I would like to know some things from you. Is it possible to render files to the 7" panel on a bigger size than on a 4.3"? Is the 2 layer option working o, a 7" panel?

Thanks in advance.

Peter Belgium

14 Mar 2016

hi Peter,

I spent some time over the last days to improve the support for 8-bit mode, and while I don't have an 800x480 panel, it should now support that. Then you can have access to the dual-layers.


You mention that the l layer open is working only for 16-colors. That may take more study - it should work in 8-bit mode for 256 colors - by my interpretation.

I repeated some performance testing yesterday - but I haven't updated the web page performance metrics. I took a 24-bit bitmap that was 480x272, and the test was to put it onto the screen from both the local file system and from the SD card and from USB. From the local file system it took about 9.5 sec, from the SD card it was about 2.5, and I couldn't find a USB driver that would coexist with my SD driver - so couldn't run that test. A larger image will take long - if your image is the full 800x600.

If you can arrange to update only a single digit at a time, it should take far less time.

And one last thought - if you've seen the work with the soft fonts, you might be able to use that to show the digits. Once you have a font that is defined that large, I'm not sure - it may end up being about the same in terms of digit update.

In any case, if you find defects in the code along the way, we can work through them I'm sure. - David

11 Mar 2016


Thanks for your quick reply. If I make a summit of your answer then I can conclude that in 8 bit mode, the 2 layer option for a 7" panel should work. Does that mean that I have to re download the RA8875.h and .cpp file? I made a system where only the changed numbers in the clock will be updated so I don't worry about the time. So it should be possible to write over the complete area of a 800x480 panel. Can I render a file from the SD card bigger than 480x272? Is it possible to place that rendered file on every place on a 800x480 panel? If this is all a positive answer then I will buy a 7"and do the test myself. Thanks in advance for your reply.

11 Mar 2016

Hi Peter,

I hope I hit all your questions -

  • As I read the RA8875 data sheet, I interpret that in 8-bit mode it can support 2 layers with a full 800x480 panel [I mistakenly wrote 800x600 up above]. I updated the driver based to support that.
  • If you are building offline, then yes, you need the .cpp and .h file. If you are building online, you can simply import the library to your project.
  • Can you write over the complete area? yes.
  • Can you render a file from the SD card bigger than 480x272? Yes, up to 800x480.
  • Can you place it anywhere? Yes - the bitmap render mechanism reads the size of the BMP file and if it fits it will draw it.

And, repeating two things from above - I don't have that panel, so don't have direct experience, and I'll help work through the issues as best I can. If you've read the RA8875 data sheet and agree that the above items are all possible (section 2 lists the features), then the rest is simply making it work.

24 Apr 2016


I received the panel yesterday and after setting all the correct wires, it worked fine. I can write over the complete size of the panel. Calibration has been performed well. However, rendering files to the panel does not work. I made a bitmap with 256 colours size 598 to 399. This file is made in paint and is containing 4 numbers (2 3 4 5) next to each other. After rendering the file and putting it on the screen, location 200 (x) and 50 (y) I only get the 2 and the 3 on the screen. The size is also different than my original bit map. If I make a picture, resize it and put it into 8 bit size, the same problem is there, only a half of the picture is on the screen and very poor image quality. I don't need the quality because I only need the white and black colours but the image size should be correct. Can you assist? Below a part of the software. Is there something I have to do in the render option to set it to another size? Thanks in advance. Thanks in advance. const char * Pictures[] = { "/local/PIC1.bmp","/local/PIC2.bmp" };

InitTS(); RetCode_t r; pc.baud(9600); lcd.init(800,480,8); init for 7" panel lcd.cls(); lcd.cls(0) clears layer 0 lcd.cls(1) clears layer 1

while(1) { point_t p; Update_Ports(); TouchCode_t touchcode = lcd.TouchPanelReadable(&p);

while(1) { r = lcd.RenderBitmapFile(200,50, Pictures[0]); wait(4); r = lcd.RenderBitmapFile(200,50, Pictures[1]); wait(4); }

24 Apr 2016

hi Peter,

Sure, I'll try to help -

  1. Could you edit your prior comment and place <<code>> and <</code>> around your sample? (the line above and the line below) then it becomes more easily read.
  2. Could you post your PIC1.bmp and PIC2.bmp files online and provide a link to them?
  3. Oh, and are you using the current library (revision 110)?

I think I'll have time today - if you see and respond in time. And you know I don't have the larger panel, but I'll do my best.

25 Apr 2016
25 Apr 2016


25 Apr 2016
25 Apr 2016


On top some info you requested. As general I see that only part of the image is written to the screen. I have some remarks made on your code ( I use indeed the rev 110 downloaded yesterday) about the RA8875.h on the 2 layer selection. Please advice. Drawing on the panel is no problem. I can draw lines all over the panel size 800 x480 and even the touchscreen calibration has been performed well. It seems that, for the moment, the render function is a little bit strange. I have a second picture, just a holiday picture, and the result is just the same. Only half of the image is visible. I didn't put it on the web because it's personal. Even the form of the numbers is changed, a little bit stretched. Thanks in advance for your help on the 7'' panel.

25 Apr 2016


Below is the relevant code from the doc - with some changes to test.

You instantiate the SDFileSystem as "sd", but your Pictures array refers to "/local/PIC1.bmp", not "/sd/PIC1.bmp".

I guess it is unlikely that you have pictures on the local file system that are twice as wide as those on the sd file system?

The bmp file you listed at /media/uploads/Peterbarco/pic2.bmp is 598 x 399

SDFileSystem sd(p11, p12, p13, p10, "sd");    // to use with micro SD card
RA8875 lcd(p5, p6, p7, p21, NC, "tft"); 
LocalFileSystem local("local");     // to use with MBED drive: files local on mbed

const char * Pictures[] = 

int main()
    RetCode_t r;
    lcd.init(800,480,8); // init for 7" panel
    lcd.cls();  // lcd.cls(0) clears layer 0 lcd.cls(1) clears layer 1
    point_t p;
    TouchCode_t touchcode = lcd.TouchPanelReadable(&p);
    	r = lcd.RenderBitmapFile(200,50,   Pictures[0]);
        printf("%d returned for %s\r\n", r, Pictures[0]);             // double-check return value
        lcd.rect(10,10, 790, 470, Red);                            // draw some stuff over top of the picture
        lcd.line(400,0, 400,479, Blue);

    	r = lcd.RenderBitmapFile(200,50,   Pictures[1]);
        printf("%d returned for %s\r\n", r, Pictures[1]);
        lcd.rect(10,10, 790, 470, Red);
        lcd.line(400,0, 400,479, Blue);


If this doesn't reveal anything, and it might not, then please create a 5x5 bmp of some high-contrast color, render it at offset 1,1 (to see the background).

Since the strokes look so nice, it seems like some kind of 8 v. 16-bit thing, which is causes it to print double-wide.

If the 5x5 bmp shows up as stretched double-wide, then we'll turn on the #define DEBUG in the GraphicsDisplay.cpp file. This will spew a lot of stuff at the console as it renders it. This may give us a clue.

26 Apr 2016
26 Apr 2016


I did some tests this evening. The files are indeed on the local file system not on the SD card. I made some test and made a 200x200 bitmap and a 778 x 458 bitmap, they are just send. The 778x458 file is within the borders you have set. See Picture PIC778. When I make a bitmap from a picture it goes wrong. I made a bitmap from a koala and made it as big as 778x458, the same as the bitmap in 1 color. There it goes wrong. See picture PICKOALA. As a conclusion, when I make a 1 color bitmap all is fine during the render, when there are several colors involved, it goes wrong. I have also problems with the second layer. I changed the program a little bit and added the next lines for the second layer. I've added this between line 31 and 32 after the first wait(4). See picture PICLAYER1

lcd.SelectDrawingLayer(1); lcd.SetLayerMode(RA8875::ShowLayer1);

I found something in your code (RA8875.cpp). Is this the reason why the second layer does not work? My settings are 800x480 so it will take the 1 layer mode.

if (width >= 800 && height >= 480 && color_bpp > 8) /media/uploads/Peterbarco/pic778x458.jpg { WriteCommand(0x20, 0x00); DPCR - 1-layer mode when the resolution is too high } else { WriteCommand(0x20, 0x80); DPCR - 2-layer mode }

Thanks in advance /media/uploads/Peterbarco/pickoala.jpg /media/uploads/Peterbarco/piclayer1.jpg