Adafruit and Giga Display not working together

I have a code that uses the adafruit libraries with the giga r1 and display shield. The code compiles and uploads fine but the screen is blank. I have tried using the examples and most don't do anything to the screen. I can get some examples to work but once adafruit libraries are included, nothing works. Has anyone experienced this before and if so, how did you fix it? The code I have looks perfect on paper but it just won't display properly.

#include <Adafruit_GFX.h>        // Include Adafruit GFX library
#include <Adafruit_ILI9341.h>    // Include the specific display driver library

// Initialize the display (adjust the pins as needed)
Adafruit_ILI9341 Display = Adafruit_ILI9341(10, 9, 8); // CS, DC, RESET pins

#define BLACK ILI9341_BLACK
#define WHITE ILI9341_WHITE
#define MAX_RECORDS 10

unsigned long lastReadingTime = 0; // Last reading timestamp
unsigned long timerStart = 0;       // Timer start timestamp
unsigned long recordedTimes[MAX_RECORDS] = {0}; // Array to store recorded times
int recordIndex = 0;                 // Current index for storing times
float averageTime = 0;               // Average time calculation
int readingCount = 0;                // Number of readings taken

void setup() {
    Serial.begin(9600);         // Start serial communication
    Display.begin();            // Initialize the display
    Display.setRotation(3);     // Set the rotation if needed
    Display.fillScreen(BLACK);  // Clear the screen at the beginning
    Display.setTextColor(WHITE);
    Display.setTextSize(2);     // Set the text size
    
    // Draw section headers
    Display.setCursor(10, 10);
    Display.print("Current Time:");
    
    Display.setCursor(130, 10);
    Display.print("Previous Times:");
    
    Display.setCursor(10, 240);
    Display.print("Average Time:");
}

void displayCurrentReading(unsigned long duration) {
    Display.fillRect(0, 30, 240, 80, BLACK); // Clear previous display area
    Display.setCursor(10, 30);
    Display.print("Duration: ");
    Display.print(duration);
    Display.println(" ms");
}

void displayPreviousTimes() {
    Display.fillRect(120, 30, 120, 210, BLACK); // Clear previous times display
    Display.setCursor(130, 30);
    for (int i = 0; i < MAX_RECORDS; i++) {
        if (recordedTimes[i] > 0) {
            Display.setCursor(130, 50 + i * 20); // Adjust y position for each time
            Display.print(recordedTimes[i]);
            Display.println(" ms");
        }
    }
}

void displayAverageTime() {
    Display.fillRect(0, 240, 240, 40, BLACK); // Clear previous average display
    Display.setCursor(10, 240);
    Display.print("Average: ");
    Display.print(averageTime);
    Display.println(" ms");
}

void loop() {
    int reading = analogRead(A5); // Read the value from pin A5

    if (reading > 0) { // Check if there's a valid reading
        unsigned long currentTime = millis(); // Get current time in milliseconds

        // If this is the first reading or if a new reading is detected
        if (timerStart == 0) {
            timerStart = currentTime; // Start the timer
        } else {
            // Calculate the duration since the last reading
            unsigned long duration = currentTime - timerStart;

            // Store the recorded time in the array
            recordedTimes[recordIndex] = duration;
            recordIndex = (recordIndex + 1) % MAX_RECORDS; // Increment index cyclically
            readingCount++;

            // Calculate the average time
            unsigned long totalTime = 0;
            for (int i = 0; i < MAX_RECORDS; i++) {
                totalTime += recordedTimes[i];
            }
            averageTime = (readingCount > 0) ? (float)totalTime / readingCount : 0;

            // Display the new reading duration, previous times, and average time
            displayCurrentReading(duration);
            displayPreviousTimes();
            displayAverageTime();

            // Reset the timer for the next reading
            timerStart = currentTime;
        }

        delay(1000); // Update every second
    }
}

Just to be clear, you have an external ILI9341 display connected up to your GIGA.
How is it wired?

In particular where is the main SPI pins connected (MOSI, MISO, SCLK).

Why I am asking: There are two SPI busses on the GIGA as you can see from the cheat sheet
Arduino GIGA R1 Cheat Sheet | Arduino Documentation

And this page is seriously confusing.

In that what is Marked as SPI1, is actually Software wise you use the SPI object
And what is labeled on the picture as SPI5 software wise you use the SPI1 object

So guessing you are using the SPI1 object pins. Try changing:
Adafruit_ILI9341 Display = Adafruit_ILI9341(10, 9, 8); // CS, DC, RESET pins
to
Adafruit_ILI9341 Display = Adafruit_ILI9341(&SPI1, 10, 9, 8); // CS, DC, RESET pins

And see if you get anything.

Been there!

I am brand new to this so I may be incorrect but I don't believe it is connected to either of the SPI's you included. I believe it is connected to the MIPI/DSI and its matching section on the other side of the board.

Then I am assuming you are trying to drive GIGA display that Arduino sells, that plugs
into those connectors.

This does not use the Adafruit_ILI9341 library.
Adafruit_ILI9341 Display = Adafruit_ILI9341(10, 9, 8);

Instead you use the library:
arduino-libraries/Arduino_GigaDisplay_GFX
Which you can install using the library manager:

And there are a couple of examples included with this library like Basic

#include "Arduino_GigaDisplay_GFX.h"

GigaDisplay_GFX display;

void setup() {
  Serial.begin(115200);
}

void loop() {
  Serial.println(millis());
  display.fillScreen(0);
  display.fillRect(120, 180, 120, 180, 0x8888);
  display.print(false);
  delay(100);
}

In your sketch you probably mainly need to change the include file and
the definition of your Display object and hopefully some of it will start to work

The new library worked...thank you for the help

1 Like