I am really new to this world. I am trying to get an arduino Uno r3 to display an image on an epaper display..
I used chat gtp to program stuff in the past but it doesn't seem to give me the answer I need.
the image is stored on a fat 32 formatted SD card. it is 400x300 and black or white no gradients.
the compiler informs me that my global variables are larger than I can store on the Uno but Chat gtp can't or won't tell me how or what to store on the SD card to solve this.
"Sketch uses 22816 bytes (70%) of program storage space. Maximum is 32256 bytes.
Global variables use 16442 bytes (802%) of dynamic memory, leaving -14394 bytes for local variables. Maximum is 2048 bytes.
Not enough memory; see https://support.arduino.cc/hc/en-us/articles/360013825179 for tips on reducing your footprint.
data section exceeds available space in board
Compilation error: data section exceeds available space in board"
I know the sd card is working as other attempts I have written to it.
this is my code can anyone explain how to accomplish this to an old man
'''
#include <SPI.h>
#include <SD.h>
#include <GxEPD2_BW.h>
#include <GxEPD2_3C.h>
#define EPD_CS_PIN 10
#define EPD_DC_PIN 9
#define EPD_RST_PIN 8
#define EPD_BUSY_PIN 7
#define SD_CS_PIN 4
GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(EPD_CS_PIN, EPD_DC_PIN, EPD_RST_PIN, EPD_BUSY_PIN));
// Example global variables
int imageIndex = 0; // Example variable to store the current image index
int brightness = 128; // Example variable to store brightness (just for illustration)
void setup() {
Serial.begin(9600);
// Initialize the SD card
if (!SD.begin(SD_CS_PIN)) {
Serial.println("SD card initialization failed!");
return;
}
Serial.println("SD card initialized.");
// Retrieve global variables from SD card
retrieveVariables();
// Initialize the e-paper display
display.init(115200);
display.setRotation(1);
// Clear the display
display.setFullWindow();
display.fillScreen(GxEPD_WHITE);
display.display();
Serial.println("Display cleared");
// Load and display the image from SD card based on the stored image index
displayImageFromSD("/MIS_Icon400-300.bmp");
// Store global variables to the SD card (this could be done after an update, etc.)
storeVariables();
// Put the e-paper display to sleep
display.hibernate();
}
void loop() {
// Nothing to do here
}
void displayImageFromSD(const char *filename) {
File file = SD.open(filename);
if (!file) {
Serial.println("Failed to open image file!");
return;
}
// Skip BMP header
file.seek(54);
const int width = 400; // Width of your display
const int height = 300; // Height of your display
const int bytesPerLine = width / 8;
unsigned char lineBuffer[bytesPerLine]; // Small buffer for one line of image data
// Read and display the image line by line
for (int y = 0; y < height; y++) {
// Read a line from the file into the buffer
file.read(lineBuffer, sizeof(lineBuffer));
// Display the line on the e-paper
display.drawBitmap(0, y, lineBuffer, width, 1, GxEPD_BLACK);
}
// Update the display with the new image data
display.display();
file.close();
}
void storeVariables() {
File file = SD.open("vars.dat", FILE_WRITE);
if (file) {
file.write((byte*)&imageIndex, sizeof(imageIndex));
file.write((byte*)&brightness, sizeof(brightness));
file.close();
Serial.println("Variables stored to SD card.");
} else {
Serial.println("Failed to open file for writing.");
}
}
void retrieveVariables() {
File file = SD.open("vars.dat", FILE_READ);
if (file) {
file.read((byte*)&imageIndex, sizeof(imageIndex));
file.read((byte*)&brightness, sizeof(brightness));
file.close();
Serial.println("Variables retrieved from SD card.");
} else {
Serial.println("Failed to open file for reading.");
}
}
'''