How to store a bunch of pre-defined values in a library?

I’m writing a sketch to do telescope alignment and tracking, and I need to store a list of the 50 brightest stars and their metadata (name, coordinates and magnitude) somewhere.

I’ve made a structure for a star that looks like this:

typedef struct {
  float time;
  float ra;
  float dec;
  float alt;
  float az;
  String name;
  float vmag;
} Star;

and I can declare individual stars easily enough:

Star sirius   = {0.0, 1.76779309390854, -0.291751177018097, 0.0, 0.0, "Sirius",   -1.46}

but adding 50 of these to the start of my .ino file seems a little clunky.

What is the best method for storing this data? Can I declare a giant 2D array in a header file?

Can I declare a giant 2D array in a header file?

Have you tried ? Start with a small array. If it works then try a larger one up to the size of the available memory.

  float time;

What, exactly, are you storing in time? Time is usually stored in an unsigned long.

And don't believe that adding more digits to a float constant yields precision.

void setup(){
  Serial.begin(115200);
  Serial.print("extern 1.76779309390854\nintern ");
  Serial.println(1.76779309390854, 14);
  Serial.print("\nextern -0.291751177018097\nintern ");
  Serial.println(-0.291751177018097, 15);
}
void loop(){}
extern 1.76779309390854
intern 1.76779308319091

extern -0.291751177018097
intern -0.291751174926757

UKHeliBob: Have you tried ? Start with a small array. If it works then try a larger one up to the size of the available memory.

Hmmm, no I haven't tried. I'll give it a crack now. I guess I'm asking if there's a "best" approach for storing this kind of library data. For simple consts it seems normal to just #DEFINE them, but 50 stars and their associated metadata goes a bit beyond that.

PaulS: What, exactly, are you storing in time? Time is usually stored in an unsigned long.

Time in seconds since the alignment epoch that the star was observed. It's basically millis() / 1000 and is used to calculate the alignment transform matrices.

Whandall: And don't believe that adding more digits to a float constant yields precision.

It's ok, I don't. Those figures are just dumped directly from a star chart, I just couldn't be bothered trimming them when the compiler will do it for me.

Thanks for the responses!

caseyfw: Time in seconds since the alignment epoch that the star was observed. It's basically millis() / 1000 and is used to calculate the alignment transform matrices.

millis returns an unsigned long. millis / 1000 will be an unsigned long integer. Putting the result into a float won't make it more precise. It gets truncated before it ever gets assigned.

If you want to have fractional seconds (why not use milliseconds instead then) then you should change that 1000 to 1000.0 so it will do the math with floating point.

What type of Arduino are you using?

One star needs 26 bytes plus the length of the name + 1.

You will need a lot of RAM for the table if you don't place it into PROGMEM.

Putting it to PROGMEM needs some reformatting of the definition (embedded string pointers).

Whandall:
What type of Arduino are you using?

One star needs 26 bytes plus the length of the name + 1.

You will need a lot of RAM for the table if you don’t place it into PROGMEM.

Putting it to PROGMEM needs some reformatting of the definition (embedded string pointers).

I’m targetting the Uno at the moment, so not exactly ample RAM to burn. I figured I could load it all into EEPROM if I needed to. I had no idea you could load up the program memory with anything you want though, I’ll give that a crack.

Here you can find some information http://www.atmel.com/webdoc/AVRLibcReferenceManual/pgmspace.html

caseyfw: What is the best method for storing this data?

1.76779309390854, -0.291751177018097

For which type of controller is it? How accurate do you need the values to be?

Numerical floating point accuracy of 8-bit Atmega controllers is "float", this is 6 to 7 digits.

So everything in a float following digits 1.767793..., -0.2917511... is pure imagination when using 'float' as a data type.