Matadormac
Well-known member
White screen with ILI9341 & SD data logger - SOLVED
Hello. I have been struggling with this for most of this past week. I believe the issue is in the SPI coding I am using. I have tried to implement transactions, etc. I can implement SPI transactions when only working with the ILI9341 display or the SD datalogger sketches (from the Teensyduino installed examples) but when I combine the two I have problems and although the first loop iteration shows a black screen with two lines of text showing:
1. Just testing!...
2. Now, we loop!...
It then goes to a white screen on the tft. I have to physically remove the TFT from the female pin header holding it and then reseat it to "unfreeze" it. Only after "unfreezing" it can I successfully run the sketch "graphicstest" from the ILI9341_t3 example.
The serial output shows that the data logging is going on and the sketch is looping. Here is the first output with a few cycles of the data logging:
ILI9341 Test!
Display Power Mode: 0xDE
MADCTL Mode: 0x3C
Pixel Format: 0x7
Image Format: 0x0
Self Diagnostic: 0xE0
Initializing SD card...card initialized.
211,632,258
128,633,230
105,633,313
96,633,290
76,633,307
TFT connections are as per the recommendations on the PJRC page. SD connections are the same with the exception that its chip select is pin 20.
Thank you for all help and advice.
Here is the test sketch I am working with:
Hello. I have been struggling with this for most of this past week. I believe the issue is in the SPI coding I am using. I have tried to implement transactions, etc. I can implement SPI transactions when only working with the ILI9341 display or the SD datalogger sketches (from the Teensyduino installed examples) but when I combine the two I have problems and although the first loop iteration shows a black screen with two lines of text showing:
1. Just testing!...
2. Now, we loop!...
It then goes to a white screen on the tft. I have to physically remove the TFT from the female pin header holding it and then reseat it to "unfreeze" it. Only after "unfreezing" it can I successfully run the sketch "graphicstest" from the ILI9341_t3 example.
The serial output shows that the data logging is going on and the sketch is looping. Here is the first output with a few cycles of the data logging:
ILI9341 Test!
Display Power Mode: 0xDE
MADCTL Mode: 0x3C
Pixel Format: 0x7
Image Format: 0x0
Self Diagnostic: 0xE0
Initializing SD card...card initialized.
211,632,258
128,633,230
105,633,313
96,633,290
76,633,307
TFT connections are as per the recommendations on the PJRC page. SD connections are the same with the exception that its chip select is pin 20.
Thank you for all help and advice.
Here is the test sketch I am working with:
Code:
#include "SPI.h"
#include "ILI9341_t3.h"
#include <SD.h>
// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10
const int chipSelect = 20;
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);
SPISettings tftSettings = SPISettings(30000000, MSBFIRST, SPI_MODE0);
//SPISettings tftSettings = SPISettings(25000000, MSBFIRST, SPI_MODE0);
SPISettings SD_Settings = SPISettings(25000000, MSBFIRST, SPI_MODE0);
void setup() {
// put your setup code here, to run once:
SPI.begin();
// initalize the data ready and chip select pins:
pinMode(TFT_CS, OUTPUT);
pinMode(chipSelect, OUTPUT);
digitalWrite(chipSelect, HIGH);
SPI.beginTransaction(tftSettings);
digitalWrite(TFT_CS, LOW);
// digitalWrite(chipSelect, HIGH);
//====================================================
tft.begin();
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(2);
tft.setRotation(1);
tft.println("Just testing!...");
digitalWrite(10, HIGH);
SPI.endTransaction();
Serial.begin(9600);
while (!Serial) ; // wait for Arduino Serial Monitor
Serial.println("ILI9341 Test!");
// read diagnostics (optional but can help debug problems)
uint8_t x = tft.readcommand8(ILI9341_RDMODE);
Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDMADCTL);
Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDPIXFMT);
Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDIMGFMT);
Serial.print("Image Format: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDSELFDIAG);
Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);
//=====================================================
Serial.print("Initializing SD card...");
SPI.beginTransaction(SD_Settings);
digitalWrite(chipSelect, LOW);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
digitalWrite(chipSelect, HIGH);
SPI.endTransaction();
}
Serial.println("card initialized.");
}
void loop() {
// put your main code here, to run repeatedly:
SPI.beginTransaction(tftSettings);
digitalWrite(20, HIGH);
digitalWrite(TFT_CS, LOW);
tft.setCursor(0, 20);
tft.println("Now, we loop!...");
digitalWrite(10, HIGH);
SPI.endTransaction();
delay(1000);
// make a string for assembling the data to log:
String dataString = "";
// read three sensors and append to the string:
for (int analogPin = 0; analogPin < 3; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) {
dataString += ",";
}
}
SPI.beginTransaction(SD_Settings);
digitalWrite(10, HIGH);
digitalWrite(chipSelect, LOW);
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// digitalWrite(chipSelect, HIGH);
// SPI.endTransaction();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
digitalWrite(chipSelect, HIGH);
SPI.endTransaction();
//=========================================================
SPI.beginTransaction(tftSettings);
digitalWrite(20, HIGH);
digitalWrite(TFT_CS, LOW);
tft.setCursor(0, 30);
tft.println(dataString);
digitalWrite(10, HIGH);
SPI.endTransaction();
delay(1000);
}
Last edited: