Help with potential memory problem

Hey guys,

I tend to try my best to ask a specific question to a specific problem, but I don't think I can do that in this case.. I am trying to port over this QR encoding library: Github. I know there is qduino, but it is inefficient and uses malloc which I am trying to avoid.

I am modifying the library to be very specific. Create a QR code version 1, with M error correction, numeric, with 34 digits. I have shrunk down the library considerably, and when I throw it in arduino IDE, I am only at 11% SRAM.

If I run it as is with an arduino, it runs fine, but outputs an invalid QR code. If I try to debug it within the method "qrcodegen_encodeText()" using Serial monitor, I get a lot of garbage values, unless I add delays to slow it down.

All and all it is just really inconsistent, which is what is leading me to believe that I am still way off on my memory usage. But, I don't see anything that could be using up so much SRAM dynamically.

Could anyone please take a quick peek and let me know if I am missing something? I've been staring at this for a while, so it could be obvious.

Thank you so much

My modified code: Code

https://playground.arduino.cc/Code/AvailableMemory

Also you have two [4][41] byte constant arrays that could be in PROGMEM if you wanted.

But it sounds like it could be anything - and its a lot of code to debug. I'd trawl through that source looking for any possible buffer-overruns.

MarkT: https://playground.arduino.cc/Code/AvailableMemory

Also you have two [4][41] byte constant arrays that could be in PROGMEM if you wanted.

But it sounds like it could be anything - and its a lot of code to debug. I'd trawl through that source looking for any possible buffer-overruns.

Than you very much. I did miss that, actually was able to get rid of them completely, using the hardocoded value of version and error correction.

That did help, but I figured out the main issue.. Definitely was a stupid mistake on my end.

I was initializing these two:

uint8_t qrcode[qrcodegen_BUFFER_LEN_MAX]; uint8_t tempBuffer[qrcodegen_BUFFER_LEN_MAX];

Which is almost 4000 length for each, which is the max for Version 40, with full error correction. So I changed it down to 57, the max for my values, and it works perfect.

I'm honestly surprised it was able to work at all, considering I was using up like 3 times the total SRAM available..