Simple demo for the Raio RA8875 Based Display with a 4-wire SPI interface.

Dependencies:   mbed RA8875

RA8875 Based Display Controller

This page shows a simple demo program for a graphics library supporting a low cost display from buydisplay.com. While the module can be configured for support via I2C, 3-Wire SPI, 4-Wire SPI, 8-bit Parallel or 16-bit Parallel, the companion library only supports the 4-Wire SPI.

You can also find this display on the Components | RA8875 page.

Library

RA8875 Library

Display Pictures

While this image is sharp, the camera/lighting washed out the colors somewhat. /media/uploads/WiredHome/ra8875display.640x380.png

With careful study of the image below, you can see a number of solder-blob jumpers. These jumpers are described quite well in the manual, and configure the many different options. The specific unit shown here is the "entry point" model, it does not have touchscreen, SD card, extra Font memory, or the key pad interface. As you see in the top left, it is wired with an 8-signal ribbon cable (but note in the schematic that it only needs 6 as the two power and two ground are internally connected together in the module).

/media/uploads/WiredHome/ra8875displaymodulerr.jpg

Also note, that some configuration changes go beyond the jumpers. I decided to switch my configuration to 4-Wire SPI and had to remove R1, R2, and R3 (which were zero-ohm that shorted the SPI input pins to +v!). I also changed some of the solder-blob jumpers, but that was easy. Had I ordered the display with the support for 4-Wire SPI, that would not have been necessary.

Schematic

The library should be able to work with any SPI port, and the Chip Select pin is a simple DigitalOut pin, chosen from the unused pins on my baseboard.

/media/uploads/WiredHome/ra8875_display_schematic.png

Sample Program

#include "mbed.h"
#include "RA8875.h"

Serial pc(USBTX, USBRX);

int main()
{
    pc.baud(460800);    // I like a snappy terminal, so crank it up!
    pc.printf("\r\nRA8875 Test - Build " __DATE__ " " __TIME__ "\r\n");

    RA8875 lcd(p5, p6, p7, p12, NC, "tft");    // MOSI, MISO, SCK, /ChipSelect, /reset, name

    lcd.puts(0,0,
        "RA8875 lcd(p5, p6, p7, p12, NC, \"tft\");\r\n\r\n"
        "lcd.circle(       400,25,  25,  BrightRed);\r\n"
        "lcd.fillcircle(   400,25,  15,  RGB(128,255,128));\r\n"
        "lcd.ellipse(      440,75,  35,20, BrightBlue);\r\n"
        "lcd.fillellipse(  440,75,  25,10, Blue);\r\n"
        "lcd.triangle(     440,100, 475,110, 450,125, Magenta);\r\n"
        "lcd.filltriangle( 445,105, 467,111, 452,120, Cyan);\r\n"
        "lcd.rect(         400,130, 475,155,    Brown);\r\n"
        "lcd.fillrect(     405,135, 470,150,    Pink);\r\n"
        "lcd.roundrect(    410,160, 475,190, 10,8, Yellow);\r\n"
        "lcd.fillroundrect(415,165, 470,185,  5,3, Orange);\r\n"
        "lcd.line(         430,200, 460,230, RGB(0,255,0));\r\n"
        "for (i=0; i<=30; i+=5)\r\n"
        "    lcd.pixel(435+i,200+i, White);");

    lcd.circle(       400,25,  25,               BrightRed);
    lcd.fillcircle(   400,25,  15,               RGB(128,255,128));
    lcd.ellipse(      440,75,  35,20,            BrightBlue);
    lcd.fillellipse(  440,75,  25,10,            Blue);
    lcd.triangle(     440,100, 475,110, 450,125, Magenta);
    lcd.filltriangle( 445,105, 467,111, 452,120, Cyan);
    lcd.rect(         400,130, 475,155,          Brown);
    lcd.fillrect(     405,135, 470,150,          Pink);
    lcd.roundrect(    410,160, 475,190, 10,8,    Yellow);
    lcd.fillroundrect(415,165, 470,185,  5,3,    Orange);
    lcd.line(         430,200, 460,230,          RGB(0,255,0));
    for (i=0; i<=30; i+=5) 
        lcd.pixel(435+i,200+i, White);
    while (1)
        ;
}
Committer:
WiredHome
Date:
Mon Mar 04 12:09:46 2019 +0000
Revision:
18:307303d9c8f6
Parent:
17:c8ef96a6e43b
Child:
19:222ca90808c4
Update RA8875 Lib to add GSL1680 support.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 16:231837aa2c37 1 //
WiredHome 16:231837aa2c37 2 // Demo Program
WiredHome 17:c8ef96a6e43b 3 // mbed version Graphics Working PrintScreen Working? "/local/file.bmp"
WiredHome 17:c8ef96a6e43b 4 // v148 Yes No, FILE *Image = fopen(Name_BMP, "wb"); fails
WiredHome 17:c8ef96a6e43b 5 // v142 Yes No, FILE *Image = fopen(Name_BMP, "wb"); fails
WiredHome 17:c8ef96a6e43b 6 // v140 Yes No, FILE *Image = fopen(Name_BMP, "wb"); fails
WiredHome 17:c8ef96a6e43b 7 // v138 Yes No, FILE *Image = fopen(Name_BMP, "wb"); fails
WiredHome 17:c8ef96a6e43b 8 // v137 Yes Yes
WiredHome 17:c8ef96a6e43b 9 // v136 Yes Yes
WiredHome 17:c8ef96a6e43b 10 // v128 Yes Yes
WiredHome 17:c8ef96a6e43b 11 //
WiredHome 17:c8ef96a6e43b 12 #include "mbed.h" // testing: v147 - working: v146, v145, v142, v136, v128, fails: v148
WiredHome 17:c8ef96a6e43b 13 #include "RA8875.h" // v138 - tested working
WiredHome 5:bb970d40cd7d 14 #include "MyFont18x32.h"
WiredHome 5:bb970d40cd7d 15 #include "BPG_Arial08x08.h"
WiredHome 5:bb970d40cd7d 16 #include "BPG_Arial10x10.h"
WiredHome 5:bb970d40cd7d 17 #include "BPG_Arial20x20.h"
WiredHome 5:bb970d40cd7d 18 #include "BPG_Arial31x32.h"
WiredHome 5:bb970d40cd7d 19 #include "BPG_Arial63x63.h"
WiredHome 0:037b95a5cc85 20
WiredHome 15:ab07c064c952 21 // These two defines can be enabled, or commented out
WiredHome 16:231837aa2c37 22 #define BIG_SCREEN
WiredHome 18:307303d9c8f6 23 //#define CAP_TOUCH
WiredHome 15:ab07c064c952 24 #define LCD_C 16 // color - bits per pixel
WiredHome 15:ab07c064c952 25
WiredHome 15:ab07c064c952 26 #ifdef CAP_TOUCH
WiredHome 15:ab07c064c952 27 RA8875 lcd(p5, p6, p7, p12, NC, p9,p10,p13, "tft"); // MOSI,MISO,SCK,/ChipSelect,/reset, SDA,SCL,/IRQ, name
WiredHome 15:ab07c064c952 28 #else
WiredHome 15:ab07c064c952 29 RA8875 lcd(p5, p6, p7, p12, NC, "tft"); //MOSI, MISO, SCK, /ChipSelect, /reset, name
WiredHome 16:231837aa2c37 30 #endif
WiredHome 17:c8ef96a6e43b 31 LocalFileSystem local("local"); // access to calibration file for resistive touch and printscreen
WiredHome 15:ab07c064c952 32
WiredHome 15:ab07c064c952 33 #ifdef BIG_SCREEN
WiredHome 18:307303d9c8f6 34 #define LCD_W 800
WiredHome 18:307303d9c8f6 35 #define LCD_H 480
WiredHome 15:ab07c064c952 36 #else
WiredHome 18:307303d9c8f6 37 #define LCD_W 480
WiredHome 18:307303d9c8f6 38 #define LCD_H 272
WiredHome 15:ab07c064c952 39 #endif
WiredHome 15:ab07c064c952 40
WiredHome 5:bb970d40cd7d 41 Serial pc(USBTX, USBRX); // And a little feedback
WiredHome 13:43cc0a997c53 42 Timer measurement;
WiredHome 0:037b95a5cc85 43
WiredHome 18:307303d9c8f6 44 RetCode_t callback(RA8875::filecmd_t cmd, uint8_t * buffer, uint16_t size)
WiredHome 18:307303d9c8f6 45 {
WiredHome 18:307303d9c8f6 46 static FILE * fh = NULL;
WiredHome 18:307303d9c8f6 47 static unsigned int bytesDone = 0;
WiredHome 18:307303d9c8f6 48 static unsigned int totalBytes = 0;
WiredHome 18:307303d9c8f6 49
WiredHome 18:307303d9c8f6 50 switch(cmd) {
WiredHome 18:307303d9c8f6 51 case RA8875::OPEN:
WiredHome 18:307303d9c8f6 52 bytesDone = 0;
WiredHome 18:307303d9c8f6 53 totalBytes = *(uint32_t *)buffer;
WiredHome 18:307303d9c8f6 54 pc.printf("PrintScreen callback to write %u bytes\r\n", totalBytes);
WiredHome 18:307303d9c8f6 55 fh = fopen("/local/file.bmp", "w+b");
WiredHome 18:307303d9c8f6 56 if (!fh)
WiredHome 18:307303d9c8f6 57 return(file_not_found);
WiredHome 18:307303d9c8f6 58 break;
WiredHome 18:307303d9c8f6 59 case RA8875::WRITE:
WiredHome 18:307303d9c8f6 60 bytesDone += size;
WiredHome 18:307303d9c8f6 61 pc.printf(" Write %d bytes => %d of %d\r\n", size, bytesDone, totalBytes);
WiredHome 18:307303d9c8f6 62 fwrite(buffer, 1, size, fh);
WiredHome 18:307303d9c8f6 63 pc.printf(" %3d %% complete\r\n", ((100 * bytesDone)/totalBytes));
WiredHome 18:307303d9c8f6 64 break;
WiredHome 18:307303d9c8f6 65 case RA8875::CLOSE:
WiredHome 18:307303d9c8f6 66 fclose(fh);
WiredHome 18:307303d9c8f6 67 pc.printf("PrintScreen Closed.\r\n");
WiredHome 18:307303d9c8f6 68 break;
WiredHome 18:307303d9c8f6 69 default:
WiredHome 18:307303d9c8f6 70 pc.printf("Unexpected callback %d\r\n", cmd);
WiredHome 18:307303d9c8f6 71 break;
WiredHome 18:307303d9c8f6 72 }
WiredHome 18:307303d9c8f6 73 return noerror;
WiredHome 18:307303d9c8f6 74 }
WiredHome 18:307303d9c8f6 75
WiredHome 18:307303d9c8f6 76
WiredHome 0:037b95a5cc85 77 int main()
WiredHome 0:037b95a5cc85 78 {
WiredHome 5:bb970d40cd7d 79 pc.baud(460800); // I like a snappy terminal, so crank it up!
WiredHome 5:bb970d40cd7d 80 pc.printf("\r\nRA8875 Soft Fonts - Build " __DATE__ " " __TIME__ "\r\n");
WiredHome 2:2076d9cc6db9 81
WiredHome 13:43cc0a997c53 82 measurement.start();
WiredHome 18:307303d9c8f6 83 lcd.frequency(500000);
WiredHome 18:307303d9c8f6 84 lcd.Reset();
WiredHome 18:307303d9c8f6 85 lcd.init(LCD_W, LCD_H, LCD_C, 40);
WiredHome 15:ab07c064c952 86
WiredHome 6:8e392d0ff74a 87 // **************************
WiredHome 9:02c622fa4969 88 //RunTestSet(lcd, pc); // If the library was compiled for test mode...
WiredHome 18:307303d9c8f6 89
WiredHome 9:02c622fa4969 90 lcd.foreground(RGB(255,255,0));
WiredHome 18:307303d9c8f6 91 lcd.puts(0,100, "RA8875 Soft Fonts - Build " __DATE__ " " __TIME__ "\r\n");
WiredHome 0:037b95a5cc85 92
WiredHome 5:bb970d40cd7d 93 lcd.SelectUserFont(Dave_Smart18x32);
WiredHome 5:bb970d40cd7d 94 lcd.puts("**** ! Soft Fonts ! **** 0123456789\r\n");
WiredHome 5:bb970d40cd7d 95 lcd.puts("ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n");
WiredHome 9:02c622fa4969 96 //lcd.puts("abcdefghijklmnopqrstuvwxyz\r\n");
WiredHome 5:bb970d40cd7d 97 lcd.SelectUserFont();
WiredHome 5:bb970d40cd7d 98 lcd.puts("Back to normal\r\n");
WiredHome 5:bb970d40cd7d 99 lcd.SelectUserFont(BPG_Arial08x08);
WiredHome 5:bb970d40cd7d 100 lcd.puts("BPG_Arial08x08 ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n");
WiredHome 18:307303d9c8f6 101 //lcd.puts("BPG_Arial08x08 abcdefghijklmnopqrstuvwxyz\r\n");
WiredHome 5:bb970d40cd7d 102 lcd.SelectUserFont(BPG_Arial10x10);
WiredHome 5:bb970d40cd7d 103 lcd.puts("BPG_Arial10x10 ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n");
WiredHome 9:02c622fa4969 104 //lcd.puts("BPG_Arial10x10 abcdefghijklmnopqrstuvwxyz\r\n");
WiredHome 5:bb970d40cd7d 105 lcd.SelectUserFont(BPG_Arial20x20);
WiredHome 9:02c622fa4969 106 lcd.puts("BPG_Arial20x20 ");
WiredHome 5:bb970d40cd7d 107 lcd.SelectUserFont(BPG_Arial31x32);
WiredHome 9:02c622fa4969 108 lcd.puts("BPG_Arial31x32\r\n");
WiredHome 5:bb970d40cd7d 109 lcd.SelectUserFont(BPG_Arial63x63);
WiredHome 9:02c622fa4969 110 lcd.puts("BPG_Arial63x63");
WiredHome 13:43cc0a997c53 111 pc.printf("Time trial completed in %d uSec\r\n", measurement.read_us());
WiredHome 5:bb970d40cd7d 112
WiredHome 18:307303d9c8f6 113 lcd.rect(0,0, 10,10, BrightRed);
WiredHome 18:307303d9c8f6 114
WiredHome 9:02c622fa4969 115 pc.printf("PrintScreen activated ...\r\n");
WiredHome 18:307303d9c8f6 116 RetCode_t r = lcd.PrintScreen(0,0,LCD_W,LCD_H,"/local/file.bmp", 8);
WiredHome 18:307303d9c8f6 117 pc.printf(" PrintScreen returned %d - %s\r\n", r, lcd.GetErrorMessage(r));
WiredHome 18:307303d9c8f6 118
WiredHome 18:307303d9c8f6 119 //lcd.AttachPrintHandler(callback);
WiredHome 18:307303d9c8f6 120 //lcd.PrintScreen(0,0,LCD_W,LCD_H,8);
WiredHome 18:307303d9c8f6 121
WiredHome 18:307303d9c8f6 122
WiredHome 3:ca6a1026c28e 123 while(1) {
WiredHome 5:bb970d40cd7d 124 ; // end
WiredHome 3:ca6a1026c28e 125 }
WiredHome 0:037b95a5cc85 126 }