Reading long data with PROGMEM

I have been trying to read some long values off an array with PROGMEM, but with no success.

#include <avr/pgmspace.h>

const PROGMEM prog_uint32_t long_table[] = {1, 2, 3, 5, 6, 7};

void setup()			  
{
  Serial.begin(9600);
}

void loop()			  
{
  for (int i = 0; i < 6; i++)
  {
    Serial.println(pgm_read_byte_far((long_table[i]))); 
    delay( 500 );
  }
}

When I run the above code, I get the error message “‘pgm_read_byte_far’ was not declared in this scope”.

I tried to see if I could get it to work with integers rather than long values, but with no luck. Here’s that code:

#include <avr/pgmspace.h>

const PROGMEM prog_uint16_t int_table[] = {1, 2, 3, 5, 6, 7};

void setup()			  
{
  Serial.begin(9600);
}


void loop()			  
{
  for (int i = 0; i < 6; i++)
  {
    Serial.println(pgm_read_byte_near((int_table[i]))); 
    delay( 500 );
  }
}

When I run this I get a bunch of seemingly random numbers,
12
99
12
148
12
224
12
99
12
148
12
224
continually repeating.

Have you considered using pgm_read_dwordfar instead of pgm_readbyte_far?

When you want to read a variable of 32-bits, use the pgm_read_dword().
And you have to use the address with ‘&’, like this: &int_table
[/glow]
```
*// Tested with Arduino 1.5.8
// avr-libc: <avr/pgmspace.h>: Program Space Utilities
//

const unsigned long long_table PROGMEM = {1UL, 20UL, 300UL, 5000UL, 60000UL, 700000UL};

void setup()  
{
 Serial.begin(9600);
 Serial.println(F(“Started”));
}

void loop()  
{
 for (int i = 0; i < 6; i++)
 {
   // unsigned long is 32 bit, use 32-bit ‘dword’.
   unsigned long x = pgm_read_dword(&long_table[i]);
   Serial.println(x);
   delay( 500 );
 }
}
```*
(while I was writing this, Coding Badly already mentioned the dword)

A template function for accessing any type in PROGMEM

[quote author=Nick Gammon date=1421981913 link=msg=2056031] A template function for accessing any type in PROGMEM [/quote]

Does memcpy_P know the difference between pgm_xxx_near and pgm_xxx far?

That is, will it work equally well on, say, a 328P and a 2560?

Don't know, but it would be pretty useless if it didn't.

Much of the pgmspace stuff is pretty broken on chips with more than 64k of flash :-(

westfw: Much of the pgmspace stuff is pretty broken on chips with more than 64k of flash :-(

Please be aware that the PROGMEM segment is just 64KB in size.

If your program needs more than 64KB of flash memory constants (i.e. on a MEGA2560), you can just use 64KB of flash memory as PROGMEM.

And all the rest of the flash variables in your program must be accessed in a very special way of programming.

So, for example, if you want to put 100 KB image data or 200KB of sound sample data in a program for Atmega2560, this is possible, but don't try doing it with PROGMEM!

Thank you all for responding, Peter_n's fix seemed to work! :D