ProgMem store Unsigned Long data

Hi, all
I try to store Unsigned Long data with ProgMem.
The follwoing looks good:

#include <avr/pgmspace.h>

unsigned long mydata[] PROGMEM =
{
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
};


unsigned long byte1;


void setup()
{
Serial.begin(9600); 
Serial.println("Setup Done");
}

void loop()
{
  for(int i=0;i<10;i++)
      Serial.println(pgm_read_byte(&mydata[i]));
  Serial.print("--------");
  for( ; ; ) ;
}

The result show: 0,1,2,3,4,5,6,7,8,9

But if I replace with bigger numbers, it goes wrong:

unsigned long mydata PROGMEM =
{
0,
11111,
2,
3,
4,
5,
6,
7,
8,
9
};

The result show: 0,103,2,3,4,5,6,7,8,9

Is there any better way to deal with bigger numbers??
Thank you.

make the integer literal ( the number ) an unsigned long using a type suffix.

unsigned long mydata PROGMEM =
{
0,
11111UL,
2,
3,
4,
5,
6,
7,
8,
9
};

You can do the same with floats and others:

float f = 123.456F;
int i = 0xAABB; //Not needed
unsigned long long u = 0x1A7EBADF00DULL;

u requires the ‘ULL’ as the integer literal will be taken as a 32-bit or long.

slinbody:
The result show: 0,1,2,3,4,5,6,7,8,9

Not even close…

Setup Done
0
0
0
0
0
0
0
0
0
0
--------

If you want help post your >>> actual <<< code. Please use
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags.

Hi, pYro_65
I try the way you said.

#include <avr/pgmspace.h>

unsigned long mydata[] PROGMEM =
{
0,
11111UL,
2,
3,
4,
5,
6,
7,
8,
9
};


unsigned long byte1;


void setup()
{
Serial.begin(9600); 
Serial.println("Setup Done");
}

void loop()
{
  for(int i=0;i<10;i++)
      Serial.println(pgm_read_byte(&mydata[i]));
//  byte1 = pgm_read_byte(&mydata[6]);
//  Serial.println(byte1);
  Serial.print("--------");
  for(;;);
}

The result:

Setup Done
0
103
2
3
4
5
6
7
8
9

seems not to work correctly.

Didn’t see your setup(), unsigned longs are 4 bytes, you read only one.

DEC: 11111
BIN: 10101101100111

the highlighted part as a single byte is 103

use pgm_read_dword()
http://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html

Hi, pYro_65
I thank you very much.
The following code works perfectly as I wish:

#include <avr/pgmspace.h>

const unsigned long mydata[] PROGMEM =
{
0,
756297739,
207540906,
207540794,
207541034,
4104581197,
302518077,
7,
8,
9
};


unsigned long byte1;


void setup()
{
Serial.begin(9600); 
Serial.println("Setup Done");
}

void loop()
{
  for(int i=0;i<10;i++)
      Serial.println(pgm_read_dword(&mydata[i]));
//  byte1 = pgm_read_byte(&mydata[6]);
//  Serial.println(byte1);
  Serial.print("--------");
  for( ; ; ) ;
}