3

I've setup an IR LED on my UNO, with the IRremote library, and have the code working to control an RGB LED strip from certain serial input, however as i'm storing the Raw infrared data in variables, i'm running out of RAM very quickly, and haven't managed to get code working that stores the IR data in PROGMEM, then buffers it to RAM for sending.

The current working code can be found at https://gist.github.com/dan-r/71294eaf9fe2354f1a0c7c13fc5f3bcd, and i've tried setting the int arrays as statics in PROGMEM, but whatever I do, I can't figure out how to buffer them into RAM, or even directly send them with irsend.

1 Answer 1

1

The Arduino Uno can not read data from PROGMEM (data in flash memory) in the same way as reading data from ram, there are special functions to read data from PROGMEM.

Create a buffer in ram and use one of those special functions to copy the data into that buffer.

Start with the Arduino PROGMEM reference.
Nick Gammon had made a great tutorial about PROGMEM.
All the PROMEM functions are in <avr/pgmspace.h>

Is the array of numbers always the same length ? That would make the sketch a lot easier.

Then perhaps something like this:

const unsigned int irTable[9][67] PROGMEM = { { ... }, { ... } }

unsigned int irBuf[200];

i = ...   // number of command
memcpy_P ( irBuf, &irTable[i][0], 67 * 2);
irsend.sendRaw (irBuf, 67, ...);
3
  • Works perfectly, all cleared up and into the irTable array, thank you for your help! :) (Final code is gist.github.com/dan-r/067b4857a0f44079c655855145e1518d for reference)
    – deejay31
    Commented Jul 14, 2017 at 12:14
  • Well done ! But why lay back ? You could make a table of texts in PROGMEM with "brightup", "brightdown", "off" and so on, in the same order and the same index as the IR codes. Then you can search the table with texts to find the index of the IR code.
    – Jot
    Commented Jul 14, 2017 at 15:03
  • Hmm good idea, going to try that!
    – deejay31
    Commented Jul 15, 2017 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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