PROGMEM returning random numbers

Hi all,

I am exploring the PROGMEM feature on the Arduino so I can use it in the future on more applicable and effective systems, however it is returning very odd values:

Firstly I’m defining the variables:

// User settings
#include <avr/pgmspace.h>
PROGMEM prog_uint32_t  Mperiod = 95;
PROGMEM prog_uchar     MledPin = 13;
PROGMEM prog_uchar     MhPin   = 0;
PROGMEM prog_uchar     MvPin   = 7;
PROGMEM prog_uchar     MiPin   = 6;
PROGMEM prog_uchar     Msda    = 4;
PROGMEM prog_uchar     Mscl    = 5;
PROGMEM prog_uchar     MID     = 0x72;

Then printing the values to screen (note: TRACELN2 is the same as Serial.print(val,type)):

TRACELN("Commenced device-under-test debugging!");

Which returns:

Commenced device-under-test debugging!
3072 <— Should be 95
148 <— Should be 13
12 <— Should be 0
0 <— Should be 7
140 <— Should be 6
12 <— Should be 4
148 <— Should be 5
0 <— Should be 0x72

Any ideas??

I would guess that pgm_read_xxx() takes an address so you are reading the contents of address 95, 13, 0, 7 etc

try TRACELN2(Mperiod, DEC); // bet this returns 95

I was thinking something similar don't you need to dereference with a &

You sir are a legend!

If I just use Mperiod it gives me the correct number…95 in this case. And I checked a few others.

Makes the example code on the link below pretty confusing, which is what I was following.

Cheers gents

the example you linked to a) is using arrays b) is putting values in them!