Chat GTP programming issue

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.");
}
}
'''

The SD card is irrelevant to your Arduino memory problem. You need an Arduino with more memory.

1 Like

chatGPT is just about the worst place to start.

For help on this forum, start by posting a link to the product page for the display.

In the meantime, look for a tutorial for that particular display (to learn how to wire it correctly) and/or the Arduino library that will work with it. Most libraries come with example code that should get you started.

Please use code tags when posting code. Instructions are in the "How to get the best out of this forum" post, linked at the head of every forum category.

1 Like

Welcome to the forum

@slapointe I believe that you may have tried to post your code in code tags but failed because you used 3 apostrophes before and after it instead of 3 backticks

In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

1 Like

This part of the compiler-log says:
Your code tries to use 16442 bytes
While an Arduino Uno has only 2048 bytes of RAM

Can you see that 2048 bytes is less than 16442 bytes?
Even a single line of your image does not fit into the RAM of an Arduino-Uno

A black and white picture of 400x300 pixel seems to be tiny.
Well your smartphone has a mimimum of 1GigaByte RAM which is
1073741824 bytes which is 524288 times more RAM than an Arduino Uno has.

As you have seen with this example:
Your chatGPT-prompt was too unprecise
or in case you told chatGPT that you use an Arduino-Uno chatGPT was unable to create a code that fits into the RAM of an arduino-uno.

chatGPT tries to find a code based on probability. Though a probaility of 99.9% is still too less. it has to be 100.000% to make it work.

Nobody on a real humans powered forum will help you with chatGPT-generated code
Because as soon as you input the modified code again into chatGPT, the AI will modify the code in a way that nobody will analyse the code again.

In fact this means:
Do ALL the work with chatGPT
or
Do ALL the work with real humans

1 Like