Converting String to int. after loading up HExadecimal from SD card

I was working on an Eink display that loads hexadecimal image values from the SD Card.

I have the files in an .INO file as below and the program loads up the pic1[] when I need to display.

unsigned char pic1[]= {
  0x22, 0x11, 0x11, 0x21, 0x32, 0x33, 0x43, 0x44, 0x44, 0x44, 0x44, 0x54,
  0x54, 0x55, 0xa7, 0x89, 0x67, 0x55, 0x45, 0x55, 0x55, 0x55, 0x56, 0x56,
  0x65, 0x65, 0x66, 0x87, 0x87, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
  0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
  0x88, 0x88, 0x88, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, 0x87, 0x87, 0x87,
  0x77, 0x87, 0x77, 0x77, 0x77, 0x87, 0x77, 0x77, 0x78, 0x77, 0x78, 0x77,
  0x77, 0x88, 0xa8, 0xaa, 0x8a, 0x67, 0x45, 0x44, 0x44, 0x44, 0x44, 0x44..........}

But since the file is very large, I have to save the file as .txt on an SD Card and load up the image later bit by bit.

I saved one hexadecimal value per line as a .txt file as below

0x22
0x11
0x11
0x21
0x32 ....
......

I was able to load up the array using the function Stream.readBytesUntil('New Line")

String[h] =Myfile.readBytesUntil('\n');

If I try to convert this String to a character array, I get an error saying

"cannot convert 'String' to 'void' for argument '1' to 'void memset(void*, int, size_t)'"**

Here is my code.

#include <SD.h>

const int chipSelect = 5;   //CS for SD Card
String arrayOfChars[5000];   //The String
int i=0; 
char disp[500]; // Initialized character array
void setup()
{
 // SD Card initializtion
 strip_0.begin();
  Serial.begin(9600);
  Serial.print("Initializing SD Card....");
  if(!SD.begin(chipSelect))
  {
    Serial.println("Card failed, or not Present");
    return;
  }
  Serial.println("Card Initialized");


//Open File data2.txt

  File dataFile = SD.open("/data2.txt");
  
  if(dataFile)
  {
    Serial.println("data2.txt");
    while(dataFile.available())
    { 
     arrayOfChars[i] = dataFile.readStringUntil('\n'); // Read the charcters until you get a new string
     i++;
    }

////To check what is being stored in arrayOfChars[i])

    for(int i=0;i<10;i++)
  {
    Serial.println(arrayOfChars[i]);
    delay(3000);
  }
       arrayOfChars.toCharArray(disp,9240);


//To check what is being stored after conversion
        for(int i=0;i<10;i++) 
  {

    Serial.println(arrayOfChars[i]);

    delay(3000);
  }
    dataFile.close();    
  }
  else
  {
    Serial.println("File does not exist or named wrong");
  }
}
   

void loop()
{
 
  
}

toCharArray() - Arduino Reference note that toCharArray is method of String object not String array

...you could have kept it in PROGMEM?

Hey @anon73444976.

I tried PROGMEM. But my file was just too big.

Hey @killzone_kid.

Thank you for helping me out. I am quite new to programming, so I kind of understand what you say.

Do you know any way that I might be able to load up the hexadecimal values into my array?

I tried the Stream.readBytesUntil() as well. It reads the value digits by digit.

For Ex: If I try to read 0×50,

The array stores
A[1]=0, A[2]=x, A[3]=5, A[4]=0.

Thanks.

Why didn’t you save it as a binary file, directly writing the bytes? Then no parsing is needed.

Each line in your file is the ASCII representation, in hexidecimal, of one element in an unsigned char array. Read each individual line, convert from ASCII to hexidecimal, and store that value as an element in the unsigned char array. Repeat for each line in the file.

Would be easier to store the data in the file as actual binary data instead of ASCII, then there would be no need for the conversion, and the file would be about 1/5 its current size.