arduinoarduino-uno

Add binary data file to Arduino sketch


Is it possible to add an binary data file together with a Arduino sketch that is transferred when sending it over to the Arduino? I manage to add the file in the IDE and it was copied to a "data" directory in my project folder but I can't find a way to access it in my code.

I'm just interested to send one file for testing purposes and don't want to use SD cards or network. I'm using the Arduino-Uno.


Solution

  • You can convert the binary data to a C array, and insert that into the code/source which will allow you to reference it.

    A tool like Hexworkshop or other binary file editor should have an option to do this for you.

    You could check this answer as well.

    Example output:

    unsigned char data[84] = {
    0x02, 0x00, 0x41, 0x8E, 0x08, 0x8F, 0x09, 0x85, 0x09, 0x82, 0x85, 0x08, 0x83, 0xE0, 0xFE, 0xA3,
    0xE0, 0x8E, 0x0A, 0xF5, 0x0B, 0x4E, 0x70, 0xEF, 0x85, 0x09, 0x82, 0x85, 0x08, 0x83, 0xE0, 0xFE,
    0xA3, 0xE0, 0xFF, 0x7C, 0x00, 0x7D, 0x00, 0x02, 0x00, 0x00, 0x7B, 0x00, 0x7A, 0x00, 0x79, 0x01,
    0x80, 0x06, 0x7B, 0x00, 0x7A, 0x00, 0x79, 0x00, 0x8A, 0x0A, 0x89, 0x0B, 0xE9, 0x4A, 0x70, 0xD8,
    0x22, 0x78, 0x7F, 0xE4, 0xF6, 0xD8, 0xFD, 0x75, 0x81, 0x0B, 0x02, 0x00, 0x4D, 0x7F, 0x00, 0x7E,
    0x80, 0x02, 0x00, 0x03,
    } ;