I have a global uint32_t that keep tracks of used Bytes:

uint32_t usedBytes;
int bytesWritten;

byteWritten = myFile.print(data, FILE_WRITE);

if (byteWritten > 0) {
  usedBytes += bytesWritten;

What happen if usedBytes is close to the maximum (0xFFFFFFFF)? Will incrementing it make it 0, or stuck at 0xFFFFFFFF?


It will wrap around though 0.

0xFFFFFFFF + 1 = 0

You can add a higher order word to track more data:

if (byteWritten > 0) {
    uint32_t newUsed = usedBytes + byteWritten;
    if (newUsed < usedBytes) {
        fourGigsUsed ++;
    usedBytes = newUsed;

Or you could use uint64_t to automate it - however none of the Arduino print routines cope with the uint64_t variable type.

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.