Make and run a library

Hello guys,
I'm working to solve solar position algorithm (SPA) using Arduino. I trying to check the SPA calculation using serial monitor before I continue to the next stages, but it give me a strange results like:
YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY ................

I'm using the SPA as a library and below is my sketch.

I attached the library files as well as the tester.

Your help would be highly appreciated. Thanks in advance :smiley:

#include <spa.h>
  
  spa_data spa;  //declare the SPA structure
  int result; 
  float min, sec;

void setup()
{
  Serial.begin(115200);
}
void loop()
{
    spa.year          = 2003;
    spa.month         = 10;
    spa.day           = 17;
    spa.hour          = 12;
    spa.minute        = 30;
    spa.second        = 30;
    spa.timezone      = -7.0;
    spa.delta_t       = 67;
    spa.longitude     = -105.1786;
    spa.latitude      = 39.742476;
    spa.elevation     = 1830.14;
    spa.pressure      = 820;
    spa.temperature   = 11;
    spa.slope         = 30;
    spa.azm_rotation  = -10;
    spa.atmos_refract = 0.5667;
    spa.function      = SPA_ALL;

   result = spa_calculate(&spa);  




        Serial.print ("Julian Day:     ");
        Serial.println(spa.jd);
        Serial.print ("L:             ");
        Serial.println(spa.l);
        Serial.print ("B:               ");
        Serial.println(spa.b);
        Serial.print ("R:            ");
        Serial.println(spa.r);
        Serial.print ("H:            ");
        Serial.println(spa.h);
        Serial.print ("Delta Psi:    ");
        Serial.println(spa.del_psi);
        Serial.print ("Delta Epsilon:          ");
        Serial.println(spa.del_epsilon);
        Serial.print ("Epsilon:         ");
        Serial.println(spa.epsilon);
        Serial.print ("Zenith:        ");
        Serial.println(spa.zenith);
        Serial.print ("Azimuth:        ");
        Serial.println(spa.azimuth);
        Serial.print ("Incidence:      ");
        Serial.println(spa.incidence);

        
delay(6000);


    }

spa.c (34.9 KB)

spa.h (9.06 KB)

spa_tester.c (3.74 KB)

Umm , I think it is not a serial monitor problem, It is the code itself.

To simplify the code I modified it to show only one calculation result, and now I get only zero and serial monitor displays
Julian Day: 0.00
Julian Day: 0.00
Julian Day: 0.00

And I can not solve this problem till now. Please help :slight_smile:

#include <spa.h>
spa_data spa;  
int result; 
float min, sec;

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

}

void loop()
{

    spa.year          = 2003;
    spa.month         = 10;
    spa.day           = 17;
    spa.hour          = 12;
    spa.minute        = 30;
    spa.second        = 30;
    spa.timezone      = -7.0;
    spa.delta_t       = 67;
    spa.longitude     = -105.1786;
    spa.latitude      = 39.742476;
    spa.elevation     = 1830.14;
    spa.pressure      = 820;
    spa.temperature   = 11;
    spa.slope         = 30;
    spa.azm_rotation  = -10;
    spa.atmos_refract = 0.5667;
    spa.function      = SPA_ALL;

        
Serial.print ("Julian Day:     ");
Serial.println(spa.jd);
    
delay(10000);
}

Try setting

  Serial.begin(115200);

to

  Serial.begin(9600);

I always get weird characters out of serial monitor if I have the baud rate on something weird. YMMV

Thanks for your reply, but the problem still exists.
I updated the code (below) , but still getting strange unexpected results.

#include <spa.h>
spa_data spa;  
int result; 
float min, sec;

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

}

void loop()
{

    spa.year          = 2003;
    spa.month         = 10;
    spa.day           = 17;
    spa.hour          = 12;
    spa.minute        = 30;
    spa.second        = 30;
    spa.timezone      = 7.0;
    spa.delta_t       = 67;
    spa.longitude     = -105.1786;
    spa.latitude      = 39.742476;
    spa.elevation     = 1830.14;
    spa.pressure      = 820;
    spa.temperature   = 11;
    spa.slope         = 30;
    spa.azm_rotation  = -10;
    spa.atmos_refract = 0.5667;
    spa.function      = SPA_ALL;
    result = spa_calculate(&spa);
    
if (result == 0)  
{
        
Serial.print ("Julian Day:    ");
Serial.println(spa.jd);

} 
else 
Serial.print ("SPA Error Code:    ");
Serial.println(result); 
 
delay(10000);
}

That yyy crap is almost always a speed problem for the serial communication between the arduino and the computer. Make sure that both the Serial.begin ( ) function call, and the serial monitor settting on the computer, are set to the same speed.

Add the line

Serial.begin(9600);
Serial.priintln("Hello world");

in your setup ( ) function. This will establish whether the serial communication is working, before you spa code somehow corrupts it (maybe).

Thanks Michinyon for your input. The Serial Monitor is working fine with me except in this code . I solved and displayed X = 5*6 = 30 on serial monitor. Hello World is working fine alone , but it not working by adding it to my sketch even in void setup() .

I Think I reached a dead end for this sketch today.
below is my final code and I did not receive any thing at all from the serial monitor .

Any help ?

#include <spa.h>


spa_data spa;  //declare the SPA structure
int result;
float min;
float sec;

void setup()
{  
  Serial.begin(9600);
}
void loop()
{
  spa.year          = 2003;
  spa.month         = 10;
  spa.day           = 17;
  spa.hour          = 12;
  spa.minute        = 30;
  spa.second        = 30;
  spa.timezone      = -7.0;
  spa.delta_t       = 67;
  spa.longitude     = -105.1786;
  spa.latitude      = 39.742476;
  spa.elevation     = 1830.14;
  spa.pressure      = 820;
  spa.temperature   = 11;
  spa.slope         = 30;
  spa.azm_rotation  = -10;
  spa.atmos_refract = 0.5667;
  spa.function      = SPA_ALL;

  result = spa_calculate(&spa);


  if (result == 0) {
    Serial.print ("Julian Day:    ");
    Serial.println(spa.jd);
  }
  else
  {
    Serial.print ("SPA Error Code:    ");
    Serial.println(result); 
  }

  delay(10000);
}

What are you running this on?
Doesn't SPA take up a lot of RAM?

Dear AWOL,

Binary sketch size: 27,242 bytes (of a 32,256 byte maximum)

Thanks,

Yes, but how much RAM is it using?

I'm not sure how can I get the RAM in use. Can you show me how ?

const double L_TERMS[L_COUNT][L_MAX_SUBCOUNT][TERM_COUNT]=

6 x 64 x 5 x 4 = ?

Thanks a lot AWOL for your fast replies, but I have a question: how to add this to my sketch and how to get the result ?
I need more clarification

The only Arduino this will run on without considerable rework is a Due.

I tried many times to make and run a library to get the results as shown in the tester file but I get nothing or very strange results like " Y Y Y Y Y Y Y Y "

any help will be highly appreciated

Attached library files and the tester

Thanks,

spa.h (9.06 KB)

spa.c (34.9 KB)

spa_tester.c (3.74 KB)

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Threads merged.

  • Moderator

Ok , I'll put that in my mind next post

But I still cant run my code and get the result

one problem was solved by PualS by changing the library extension from C to CPP

But the result in no thing also

I hope that some one can guide me to close this topic :smiley:

egymeda:
I tried many times to make and run a library to get the results as shown in the tester file but I get nothing or very strange results like " Y Y Y Y Y Y Y Y "

What sketch are you running? (Your xxx.ino file).

Please copy and paste the results, not say what they are "like".

egymeda:
Thanks a lot AWOL for your fast replies, but I have a question: how to add this to my sketch and how to get the result ?
I need more clarification

AWOL is telling the truth. I calculate that L_TERMS will take 4 * 6 * 64 * 3 = 4608 bytes, which is already more than you have on a Uno.

What Arduino do you have?

Thanks alot Nick ,Yes I'm using UNO and attached 2 sketches .

There is no error with the sketches , only strange results on serial monitor I cant copy like below

þþþþþþþþ

I cant find further information or data about L_TERMS, I will be grateful if you can help me with that also.

sketch_oct10a.ino (1.86 KB)

sketch_oct11a.ino (1.87 KB)