-1

I have sd card reader and lcd display. I want to display bitmap with u8g2 library. My bitmap looks like:

0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x3f, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00

If i write it in arduino ide like:

static unsigned char bytes[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x3f, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00
};

Everything works fine. So how can i read it from sd card to have same result as in second code?

1

This is talked about in multiple Arduino threads. This thread, this thread & this thread are just 3 found.

It appears reading and SDCard using an Arduino results in a text like character string. The task is to parse this (if necessary) and convert it to the desired individual values.

The most efficient way to do this might be to use the toCharArray() to copy the String’s characters to a character array (buffer). However, this implies the data is stored exactly as needed in the SDCard. Which may be difficult to do. Simply put, the program would read in a string (of likely unprintable letters) from the SDCard. Then use the above function to convert that string into the supplied character array (buffer).

(Some more experienced readers might say if one used a union here, that the character string and the array of type characters would occupy the same memory and hence have the same data. So no call to a conversion function is needed. Once you read in the data as a string, it would be available to read out as an array of characters.)

More often it is preferred to store SDCard data for Arduino's in a (printable) text format. Further it appears most store data using the CSV format. When reading back this format the strings have to be parsed. That is, the commas need to be found and the printable numbers between the commas need to be individually converted from short character strings to values. The function atoi() is used to convert a character string like "123" to the integer value 123. Then you can cast that number from an integer to an unsigned character to store in your array.

Another and perhaps easier approach is to use the toint() function call. It would appear reading a number followed by a carriage return from the SDCard then unsung this function will result in an integer value. You would not have to look and remove delineation characters as the toint() function is looking for carriage returns as the delineating character for you.

Many times working with an unknown amount of data is a problem. If your data will always be a fixed size of 36 bytes - this should not concern you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.