I have an Arduino NANO clone and a 2.4" ILI9341 TFT display. The VCC and LCD pins of the display are connected to the 5V pin of the board. The GND to the GND. All the logic pins are connected to voltage dividers (2k2 and 4k3 resistors), their connections checked and delivering 3.3V when 5V is supplied to them.
If I understand the source correctly, if I specify all the pins to the constructor, then I use software SPI, but if I don't, then I use hardware SPI.
Now, if I use the software SPI, everything is working fine, I can get the info, I can draw, etc. However if I use the hardware SPI then it is not giving me anything.
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
// Adafruit_ILI9341 tft = Adafruit_ILI9341(10, 9); // NOT WORKING!
Adafruit_ILI9341 tft = Adafruit_ILI9341(10, 9, 11, 13, 8, 12); // WORKING!
void
setup()
{
Serial.begin(9600);
while (!Serial);
Serial.println("ILI9341 Test!");
tft.begin();
// 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);
}
void
loop()
{
// pass
}
However, what really makes me totally confused is when I use the SD card reader with the SD Library
alone (the SD card reader is on the ILI9341 board), then that is working fine as well (as if the hardware SPI would be working, unless the SD Library is switching to software SPI magically). Anyway, the following is the working code:
#include <SD.h>
#include <SPI.h>
void
setup()
{
Serial.begin(9600);
while (!Serial);
Serial.println("ILI9341 Test!");
if (!SD.begin(7))
{
Serial.println("Cannot initialise SD card");
while (true);
}
File file;
if ((file = SD.open("file.txt", FILE_WRITE)))
{
Serial.print("Writing to file...");
file.println("Hello, World!");
file.close();
Serial.println(" DONE");
}
else
Serial.println("Cannot open file for writing");
if ((file = SD.open("file.txt")))
{
Serial.println("Opening file...");
while (file.available())
Serial.write(file.read());
file.close();
Serial.println("DONE");
}
else
Serial.println("Cannot open file for reading");
}
void
loop()
{
// pass
}
So what exactly is going on here? Am I doing something obviously wrong? Or is the board's hardware SPI not working? Or is there a problem with the Adafruit library?
Extra info:
I'm using the arduino-cli
to upload sketches the following ways:
# To compile:
arduino-cli \
compile \
--fqbn arduino:avr:nano:cpu=atmega328old \
--warnings all \
MyArduinoSketch;
# To upload
sudo arduino-cli \
upload \
--verify \
--verbose \
--port /dev/ttyUSB0 \
--fqbn arduino:avr:nano:cpu=atmega328old \
MyArduinoSketch;
I installed the mentioned libraries via arduino-cli
.