Hi
I am using an Arduino Nano (3.3 V, nano33IOT or RP2040 Wifi) at hand) and am trying to use an ILI9341 display and a SD card at the same time.
Adafruit ILI9341 and Arduino SD libraries
Individually they work (sdinfo or similar programs work, I can display stuff on my display). I am calling the display library first, as soon as the SD library is initialized, the display is no longer working. The code continues to execute, it writes to the SD card but there's no visual feedback any more.
I am aware of several threads asking a similar (the same) question and I have tried (most all) the things I came across.
(3V3 regulator bridged (J1 soldered in as display/SD are driven by 3V3, I even soldered a pullup Resistor on the display CS, that didn't help; there is a 10 k pullup on the SD CS on board)
I have a small code to demonstrate,
on the display I read
"Hello
I2C Done
Serial up!
starting SD
(and then it should continue with "SD online"...)
on the serial port I read
" Coffee machine I/F booting
Initializing SD Card
SD Card Initialized
finished SD
Display should have reset now"
but the display doesn't blank before the last line.
I tried manually setting cs of the display and of the sd card high/low before changing to the relevant part of the code.
If someone has an Idea where to look, I would be very grateful.
Picture of the display hanging at line before SD initializes here
//debug defines
#define FTDI
//I2C
//#include <Wire.h>
#include <WiFiNINA.h>
#include <avr/dtostrf.h>
//Display and SD card
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_ILI9341_Controls.h>
#define TFT_DC 9
#define TFT_CS 7
#define TFT_BACKLIGHT 10
#define TFT_MOSI 11
#define TFT_CLK 13
#define TFT_RST 8
#define TFT_MISO 12
#include <SD.h>
#define SD_CCS 6
char fileName[16];
uint16_t fileNumber = 0;
File dataFile;
#define RST_PIN -1
// create the display object
Adafruit_ILI9341 Display = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
//Adafruit_ILI9341 Display(TFT_CS, TFT_DC, TFT_RST);
void setup() {
//Pins
pinMode(SD_CCS, OUTPUT);
pinMode(TFT_CS, OUTPUT);
#if defined(TFT_BACKLIGHT)
pinMode(TFT_BACKLIGHT, OUTPUT);
// digitalWrite(TFT_BACKLIGHT, HIGH);
analogWrite(TFT_BACKLIGHT, 64);
#endif
// fire up the display
Display.begin();
Display.setRotation(3);
Display.fillScreen(C_BLACK);
Display.setTextSize(2);
Display.println("Hello");
Wire.begin();
Display.println("I2C Done");
//Serial
Serial.begin(115200);
Serial.println("Coffee machine I/F booting");
Display.println("Serial up!");
Display.println("starting SD");
Serial.println("Initializing SD Card");
if (!SD.begin(SD_CCS)) {
Serial.println("SD Fail");
Display.println("SD Fail, Card?");
} else {
Serial.println("SD Card Initialized");
Display.println("SD Online");
}
//Checking for Files on SD, increment Filename by 1
snprintf(fileName, sizeof(fileName), "data%03d.dat", fileNumber); //data000.dat first file
while (SD.exists(fileName)) {
fileNumber++;
Serial.println(fileNumber);
snprintf(fileName, sizeof(fileName), "data%03d.txt", fileNumber);
}
Display.println(fileName);
Serial.println("finished SD");
//I2C
delay(2000);
Display.fillScreen(C_BLACK);
Serial.println("Display should have reset now");
Display.setTextSize(1);
Display.println("More");
}
void loop() {
}