SPI program for DUE and MEGA

Hello, I am a beginner but developing a great system. I work with I2C and that is working ok. Now I connect a robot display from Arduino to my MEGA. It is working and I can send text and live data to the display. But it cost too much time. For 9 Bytes it takes 20 ms and the rest of the program is standing still at that time. I am using the pins 7,8,9,10 and the MISO, MOSI, SCK on the SPI header. on the osilloscope I see that one Byte taks 4,5 us. What do I wrong. Ruud from Holland

#define pin2 2 // Up button

#include <TFT.h> // Hardware-specific library
#include <SPI.h>

#define CS 10
#define DC 9
#define RESET 8
#define sd_cs 7


int counter1 = 0; // Counter voor uitschakelen dash-board lampjes bij lopende motor
int counter2 = 0; // Counter voor uitschakelen dash-board lampjes bij lopende motor
int bit1 = 0; // Counter voor uitschakelen dash-board lampjes bij lopende motor
int var = 0; // Counter voor uitschakelen dash-board lampjes bij lopende motor

char sensorPrintout[1];
char sensorPrintout_2[1];
char sensorPrintout_3[1];

char str1[14];
char str2[14];
char str3[14];
char str4[14];
char str5[14];
char str6[14];
char str7[14];
char str8[14];
char str9[14];
char str10[14];
char str11[14];
char str12[14];
char str13[14];
char str14[14];
char str15[14];
char str16[14];
char str17[14];
char str18[14];
char str19[14];
char str20[14];
char str21[14];
char str22[14];
char str23[14];
char str24[14];
char str25[14];
char str26[14];
char str27[14];
char str28[14];
char str29[14];
char str30[14];
char str31[14];
char str32[14];
char str33[14];
char str34[14];
char str35[14];
char str36[14];
char str37[14];
char str38[14];
char str39[14];
char str40[14];
char str41[14];
char str42[14];
char str43[14];
char str44[14];
char str45[14];
char str46[14];
char str47[14];
char str48[14];
char str49[14];
char str50[14];
char str51[14];
char str52[14];
char str53[14];
char str54[14];
char str55[14];
char str56[14];
char str57[14];
char str58[14];
char str59[14];
char str60[14];
char str61[14];
char str62[14];
char str63[14];
char str64[14];
char str65[14];
char str66[14];
char str67[14];
char str68[14];
char str69[14];
char str70[14];

void setup(){

pinMode(pin2, OUTPUT); //Res rood
pinMode(sd_cs, OUTPUT);

String string3 = “Engine Speed”;
String string4 = “Engine Load”;
String string33 = “Vehicle Speed”;
String string39 = “rpm”; // str3,
String string42 = “%”; // str4,8,11,
String string45 = “Km”;
String string46 = “%”;
String string47 = “Act”;

string3.toCharArray(str3, 14); // 6 is het aantal charachters
string4.toCharArray(str4, 14); // 6 is het aantal charachters
string33.toCharArray(str33, 14); // 6 is het aantal charachters
string42.toCharArray(str42, 14); // 6 is het aantal charachters
string43.toCharArray(str43, 14); // 6 is het aantal charachters
string44.toCharArray(str44, 14); // 6 is het aantal charachters
string45.toCharArray(str45, 14); // 6 is het aantal charachters
string46.toCharArray(str46, 14); // 6 is het aantal charachters
string47.toCharArray(str47, 14); // 6 is het aantal charachters

TFTscreen.background(0, 0, 0);

void loop()
if(counter1 > 30000)
counter1 = 0;
var = analogRead(A0);
digitalWrite(pin2, HIGH);
digitalWrite(pin2, LOW);


void screen_dashboard() // c31

TFTscreen.stroke(255, 255, 0);

TFTscreen.text(str3, 5, 00); // Engine speed
TFTscreen.text(str39, 100, 20); // RPM

TFTscreen.text(str33, 5, 45); // Vehicle speed
TFTscreen.text(str45, 100, 65); // Km

TFTscreen.text(str4, 5, 90); // belasting(4)
TFTscreen.text(str47, 100, 110); // Actueel(47)

TFTscreen.stroke(0, 0, 0);
TFTscreen.text(sensorPrintout, 30, 20);
TFTscreen.text(sensorPrintout_2, 30, 65);
TFTscreen.text(sensorPrintout_3, 30, 110);

String sensorVal = String(6000);
sensorVal.toCharArray(sensorPrintout, 5); // 6 is het aantal charachters

String sensorVal_2 = String(var);
sensorVal_2.toCharArray(sensorPrintout_2, 4); // 6 is het aantal charachters

String sensorVal_3 = String(100);
sensorVal_3.toCharArray(sensorPrintout_3, 4); // 6 is het aantal charachters

TFTscreen.stroke(255, 255, 255);
TFTscreen.text(sensorPrintout, 30, 20);

TFTscreen.stroke(255, 255, 255);
TFTscreen.text(sensorPrintout_2, 30, 65);

TFTscreen.stroke(255, 255, 255);
TFTscreen.text(sensorPrintout_3, 30, 110);



Can you please post a copy of your sketch, using code tags? Please use code tags.. See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

It will make the sketch easier to read and all the characters will be correct, the editor has a tendency to misinterpret some character combinations.

Tom..... :)

Hi Tom,

This is the first time I ask something on a forum. I see not really what you mean but I attach the scetch.
This scetch I used on a DUE. It looks that the software send a lot of the same information and he takes 20 ms before he stops.

Regards Ruud

SPI_problem.ino (3.3 KB)