LCD TFT 3'5" display project with Arduino Mega 2560

Hi all,

So I’m very, very new to LCD TFT screens in general, and I wanted to make sure the one I got from eBay worked, so I tried to copy some sample code from the internet. Unfortunately, I’ve run into all types of problems since then, e.g. invalid libraries, error for compiling the board, etc. I really just want a code that works because it’s driving me nuts. Here is the error message I have at the moment. I have installed the correct libraries and did it by sketch > Include Library, so I’m not sure what I did wrong. I’ve included both the sample code and the error, any help will be most appreciated, thank you!

This is the code

#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <Fonts/FreeSans9pt7b.h>
#include <Fonts/FreeSans12pt7b.h>
#include <Fonts/FreeSerif12pt7b.h>
#include <FreeDefaultFonts.h>
#define PI 3.1415926535897932384626433832795
int col[8];
void showmsgXY(int x, int y, int sz, const GFXfont *f, const char *msg)
{
int16_t x1, y1;
uint16_t wid, ht;
tft.setFont(f);
tft.setCursor(x, y);
tft.setTextColor(0x0000);
tft.setTextSize(sz);
tft.print(msg);
}
void setup() {
tft.reset();
Serial.begin(9600);
uint16_t ID = tft.readID();
tft.begin(ID);
tft.setRotation(1);
tft.invertDisplay(true);
tft.fillScreen(0xffff);
showmsgXY(170, 250, 2, &FreeSans9pt7b, "Loading...");
col[0] = tft.color565(155, 0, 50);
col[1] = tft.color565(170, 30, 80);
col[2] = tft.color565(195, 60, 110);
col[3] = tft.color565(215, 90, 140);
col[4] = tft.color565(230, 120, 170);
col[5] = tft.color565(250, 150, 200);
col[6] = tft.color565(255, 180, 220);
col[7] = tft.color565(255, 210, 240);
}
void loop() {
for (int i = 8; i > 0; i--) {
tft.fillCircle(240 + 40 * (cos(-i * PI / 4)), 120 + 40 * (sin(-i * PI / 4)), 10, col[0]); delay(15);
tft.fillCircle(240 + 40 * (cos(-(i + 1)*PI / 4)), 120 + 40 * (sin(-(i + 1)*PI / 4)), 10, col[1]); delay(15);
tft.fillCircle(240 + 40 * (cos(-(i + 2)*PI / 4)), 120 + 40 * (sin(-(i + 2)*PI / 4)), 10, col[2]); delay(15);
tft.fillCircle(240 + 40 * (cos(-(i + 3)*PI / 4)), 120 + 40 * (sin(-(i + 3)*PI / 4)), 10, col[3]); delay(15);
tft.fillCircle(240 + 40 * (cos(-(i + 4)*PI / 4)), 120 + 40 * (sin(-(i + 4)*PI / 4)), 10, col[4]); delay(15);
tft.fillCircle(240 + 40 * (cos(-(i + 5)*PI / 4)), 120 + 40 * (sin(-(i + 5)*PI / 4)), 10, col[5]); delay(15);
tft.fillCircle(240 + 40 * (cos(-(i + 6)*PI / 4)), 120 + 40 * (sin(-(i + 6)*PI / 4)), 10, col[6]); delay(15);
tft.fillCircle(240 + 40 * (cos(-(i + 7)*PI / 4)), 120 + 40 * (sin(-(i + 7)*PI / 4)), 10, col[7]); delay(15);
}
}

This is the error.

Arduino: 1.6.8 (Mac OS X), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

failed MSpanList_Insert 0x30b000 0x84b66f2b84b 0x0
fatal error: MSpanList_Insert

runtime stack:
runtime.throw(0x2ac50b)
	/usr/local/go/src/runtime/panic.go:491 +0xad fp=0x7ffeefbff4c0 sp=0x7ffeefbff490
runtime.MSpanList_Insert(0x2ca028, 0x30b000)
	/usr/local/go/src/runtime/mheap.c:692 +0x8f fp=0x7ffeefbff4e8 sp=0x7ffeefbff4c0
MHeap_FreeSpanLocked(0x2c6c20, 0x30b000, 0x100)
	/usr/local/go/src/runtime/mheap.c:583 +0x163 fp=0x7ffeefbff528 sp=0x7ffeefbff4e8
MHeap_Grow(0x2c6c20, 0x8, 0x0)
	/usr/local/go/src/runtime/mheap.c:420 +0x1a8 fp=0x7ffeefbff568 sp=0x7ffeefbff528
MHeap_AllocSpanLocked(0x2c6c20, 0x1, 0x0)
	/usr/local/go/src/runtime/mheap.c:298 +0x365 fp=0x7ffeefbff5a8 sp=0x7ffeefbff568
mheap_alloc(0x2c6c20, 0x1, 0x12, 0x0)
	/usr/local/go/src/runtime/mheap.c:190 +0x121 fp=0x7ffeefbff5d0 sp=0x7ffeefbff5a8
runtime.MHeap_Alloc(0x2c6c20, 0x1, 0x10000000012, 0x10359)
	/usr/local/go/src/runtime/mheap.c:240 +0x66 fp=0x7ffeefbff608 sp=0x7ffeefbff5d0
MCentral_Grow(0x2ce998, 0x0)
	/usr/local/go/src/runtime/mcentral.c:197 +0x8b fp=0x7ffeefbff670 sp=0x7ffeefbff608
runtime.MCentral_CacheSpan(0x2ce998, 0x0)
	/usr/local/go/src/runtime/mcentral.c:85 +0x167 fp=0x7ffeefbff6a8 sp=0x7ffeefbff670
runtime.MCache_Refill(0x307000, 0x12, 0x0)
	/usr/local/go/src/runtime/mcache.c:90 +0xa0 fp=0x7ffeefbff6d0 sp=0x7ffeefbff6a8
runtime.mcacheRefill_m()
	/usr/local/go/src/runtime/malloc.c:368 +0x57 fp=0x7ffeefbff6f0 sp=0x7ffeefbff6d0
runtime.onM(0x223be8)
	/usr/local/go/src/runtime/asm_amd64.s:273 +0x9a fp=0x7ffeefbff6f8 sp=0x7ffeefbff6f0
runtime.mallocgc(0x120, 0x1bf260, 0x0, 0x0)
	/usr/local/go/src/runtime/malloc.go:178 +0x849 fp=0x7ffeefbff7a8 sp=0x7ffeefbff6f8
runtime.newobject(0x1bf260, 0x307000)
	/usr/local/go/src/runtime/malloc.go:353 +0x49 fp=0x7ffeefbff7d0 sp=0x7ffeefbff7a8
runtime.newG(0x27eea)
	/usr/local/go/src/runtime/proc.go:233 +0x2a fp=0x7ffeefbff7e8 sp=0x7ffeefbff7d0
allocg(0x2b95e0)
	/usr/local/go/src/runtime/proc.c:925 +0x1f fp=0x7ffeefbff7f8 sp=0x7ffeefbff7e8
runtime.malg(0x8000, 0x2b9680)
	/usr/local/go/src/runtime/proc.c:2106 +0x1f fp=0x7ffeefbff828 sp=0x7ffeefbff7f8
runtime.mpreinit(0x2b9a40)
	/usr/local/go/src/runtime/os_darwin.c:137 +0x27 fp=0x7ffeefbff840 sp=0x7ffeefbff828
mcommoninit(0x2b9a40)
	/usr/local/go/src/runtime/proc.c:201 +0xc9 fp=0x7ffeefbff868 sp=0x7ffeefbff840
runtime.schedinit()
	/usr/local/go/src/runtime/proc.c:138 +0x55 fp=0x7ffeefbff890 sp=0x7ffeefbff868
runtime.rt0_go(0x7ffeefbff8c0, 0x14, 0x7ffeefbff8c0, 0x0, 0x14, 0x7ffeefbffa78, 0x7ffeefbffab9, 0x7ffeefbffac5, 0x7ffeefbffad5, 0x7ffeefbffadf, ...)
	/usr/local/go/src/runtime/asm_amd64.s:95 +0x116 fp=0x7ffeefbff898 sp=0x7ffeefbff890
arduino-builder returned 2

Error compiling for board Arduino/Genuino Mega or Mega 2560.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I have also tried including the libraries with ", but it didn’t work still. I got this sample code from the arduino website, so I am really stumped.