Got a strange problem with my Arduino Mega2560… just for fun I wanted to try making a sketch that implements an algorithm for calculating the sun’s position, using a library published by NREL (see here: http://rredc.nrel.gov/solar/codesandalgorithms/spa/). I basically just took their example program, and converted it to run on an Arduino and print the calculations to the Serial terminal… Unfortunately when I upload the sketch, the Arduino does nothing.
The sketch compiles successfully, and is only 29kb in size (well under the Mega’s 256kb max) to I figured I’d be ok. But after I upload the sketch the only response I get from the Mega is the “L” light… it blinks quickly two times, then about a half second pause, then again in an infinite loop. I let it run for several hours this way, but I never got anything on the Serial terminal.
I have also made very sure that I’m compiling for the right board in the Arduino IDE… so that’s not the problem either.
The code I’m using is here: http://pastebin.com/8PnnC5ur
The code depends on the NREL SPA algorithm library, which has not been modified. The SPA library only depends on the standard C math library, which I have used before on the Arduino without incident, so I don’t think the issue is there…
My only thought is that the Arduino may be getting mad because the algorithm uses references/pointers, but I havent found any evidence that the Arduino can’t handle them… if I’m wrong though, I’d sorely appreciate somebody setting me straight.
Any suggestions? Thanks!
I’ve put a vastly simplified version of the code, which still fails here: http://pastebin.com/eimmw2Hn
The sketch fails when I uncomment line 38 the line: result = spa_calculate( &spa );
I’ve tried creating references and pointers in the sketch elsewhere, and everything seemed to work just fine… I was also successfully able to make reference variables, and pointers to an spa_data structure without issues… its only when I pass that reference to a function that the code chokes.
I could try modifying the library to just take the straight data structure instead of a reference to it, but doing so would take a long time and probably cause a lot more problems for me…
Since there was some confusion below about what exactly I was trying to do, and people having difficulty getting at the code I’m using, I’ve attached all relevant code here (which in hindsight probably would have been good to do first) for future reference. The attached Arduino sketch is the simpler, easier-to-understand one, not the full sketch I linked to originally.
test.pde (1004 Bytes)
spa.h (9.06 KB)
spa.c (35.1 KB)