Indexing PROGMEM arrays?

I think I may be missing something fundamental about using the PROGMEM (pgmspace.h library)

I’d like to store several large arrays (thousands of unsigned longs) in flash memory. Normally, my implementation looks something like:

unsigned long myarray = {1.000, 2.000, …}:
int idx = 0;
unsigned long myvalue = 0.0;

idx = idx + 1;
myvalue = myarray[idx];

Instead, I’d like to use PROGMEM to store the array in flash memory and then access an element in the array using an index variable (as above). The following sort of implementation did not work as I expected:

#include <avr/pgmspace.h>

prog_uint32_t PROGMEM myarray = {1.000, 2.000, …};
int idx = 0;
unsigned long myvalue = 0.0;

idx = idx + 1;
myvalue = pgm_read_float_far(myarray + idx);

I’m hoping this is something simple I’m missing. Any suggestions?

prog_uint32_t PROGMEM myarray = {1.000, 2.000, …};

I’m guessing this was the cause of your problems.

Try:
typedef float PROGMEM prog_float_t ;

prog_float_t PROGMEM myarray = {1.000, 2.000, …};

Hint: “The following sort of implementation did not work as I expected” isn’t very helpful.

Other than the variable type error, is there anything else? I'm more concerned about whether or not my approach to indexing the array is correct.

Suppose for a moment that I declare the array variable with the proper data type. Is the indexing sytax I use in the example code correct?

Looks OK to me. What do you think is wrong?

http://www.arduino.cc/en/Reference/PROGMEM http://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html

Thanks for the links. I'll keep playing around with it.

Sorry for the lack of specificity earlier. I was trying to make sure that

myvalue = pgm_read_float_far(myarray + idx);

is actually pulling out the element of myarray indicated by the integer idx. Would I need to multiply idx by some number to make sure I'm actually reading from the correct address?

Please forgive the simplistic nature of these questions. I'm a beginner here.

myvalue = pgm_read_float_far(myarray + idx);This got into a tutorial someplace, and it SHOULD work fine (idx is automatically multiplied by the size of the pointer you add it to in C.) However, you don't NEED to take this departure from standard array access methods. You can do: myvalue=pgm_read_float_far(&myarray[idx]);(although I thought you only needed "far" for flash sizes larger than 64k ?)

Got it. Thanks, guys.