rickseiden
Posts: 430
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Arduino Time Library

Sun Jan 05, 2014 2:52 am

I downloaded the Arduino Time library from here (the official Time libraries page says to get the updated version there), and installed them in my ~/sketchbook/libraries folder. When I try to compile a sketch using Time, I get the following errors:

Code: Select all

/home/pi/sketchbook/libraries/Time/DateStrings.cpp:41:22: error: variable 'monthNames_P' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
/home/pi/sketchbook/libraries/Time/DateStrings.cpp:58:20: error: variable 'dayNames_P' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
/home/pi/sketchbook/libraries/Time/DateStrings.cpp:59:24: error: variable 'dayShortNames_P' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
I've Googled it, and came up with upgrading to Arduino 1.5 Beta.

Has anyone managed to make the Time libraries work on the GertBoard, and if so, how?

Is upgrading to 1.5 Beta a bad idea when I'm using the GertBoard?

Thanks,

Rick
There are 10 types of people in this world. Those that understand binary, and those that don't.

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: Arduino Time Library

Sun Jan 05, 2014 4:53 pm

I haven't tried this myself but I got away with it a couple of times in similar situations. You could try adding a 'const' modifier to the offending lines in the library yourself. It might raise errors elsewhere in the code, but adding a 'const' there might solve your problem in the end.

In /home/pi/sketchbook/libraries/Time/DateStrings.cpp:

Code: Select all

line 41: const PGM_P monthNames_P[] PROGMEM = 
line 58: const PGM_P dayNames_P[] PROGMEM = { dayStr0,dayStr1,dayStr2,dayStr3,dayStr4,dayStr5,dayStr6,dayStr7};
line 59: const char dayShortNames_P[] PROGMEM = "ErrSunMonTueWedThrFriSat";
Hope that works!

rickseiden
Posts: 430
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Re: Arduino Time Library

Sun Jan 05, 2014 5:05 pm

panik wrote:I haven't tried this myself but I got away with it a couple of times in similar situations. You could try adding a 'const' modifier to the offending lines in the library yourself. It might raise errors elsewhere in the code, but adding a 'const' there might solve your problem in the end.

In /home/pi/sketchbook/libraries/Time/DateStrings.cpp:

Code: Select all

line 41: const PGM_P monthNames_P[] PROGMEM = 
line 58: const PGM_P dayNames_P[] PROGMEM = { dayStr0,dayStr1,dayStr2,dayStr3,dayStr4,dayStr5,dayStr6,dayStr7};
line 59: const char dayShortNames_P[] PROGMEM = "ErrSunMonTueWedThrFriSat";
Hope that works!
I tried playing with the code as you suggested, and it just made things worse! That's why I was hoping someone out there had already done it, and got it working. :)
There are 10 types of people in this world. Those that understand binary, and those that don't.

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: Arduino Time Library

Sun Jan 05, 2014 9:53 pm

If you remove the PROGMEM qualifier completely from the offending lines, the code will probably compile. The difference is, PROGMEM makes the variables save in (32K) Flash memory. Remove PROGMEM, and the variables are saved in (2K) SRAM. I'm not sure how big of a problem that is with the full program in only 2K memory. I count 190 bytes, so the names will take up almost 10% of available memory. You could "just try and hope for the best".

EDIT: Also go through the rest of the code and change the 'pgm_read_word' and 'pgm_read_byte' functions to just use the variable name ('monthNames_P' etcetera) where it's being used. I forgot, but it's kinda important. The macro pgm_read_***() is being used to retrieve the value back from Flash memory, and you don't need to do that when they're in SRAM. Then you'll just refer to the variable name, if that makes sense.

Upgrading to 1.5 beta should be possible, depending on how big the changes are with the current one (in the link you gave, a person said the directory structure changed, so there's that). At the very least you should retrace Gordon's footsteps and copy the boards.txt etcetera to the right place.

That could be an interesting exercise, but I understand you just want it to work. :D

TheMagpie
Posts: 5
Joined: Mon Jan 13, 2014 12:11 pm

Re: Arduino Time Library

Tue Jan 28, 2014 11:09 am

If you remove the PROGMEM qualifier completely from the offending lines, the code will probably compile.
Hi,

I know this post is a bit old but it's obviously still relevant as I've had the same problem this morning, trying to compile some code int the Arduino IDE on RPi.

I went through DateStrings.cpp, the offending file, and deleted all instances of PROGMEM.
No idea what consequences this will have further down the line but at least it comnplies now!

Thanks

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: Arduino Time Library

Tue Jan 28, 2014 4:09 pm

But: does it work?

If it does, then cool! I got away with it a few times with some other libraries as well.
If it doesn't, the 'pgm_read_word' and 'pgm_read_byte' should be replaced with just the variable names a bit further down.

Let us know if you run into trouble and need help with that (without PROGMEM, the code could be optimised a little bit as well).

Leaving PROGMEM as is and upgrading to a newer Arduino IDE is technically the best solution. This is a bit of a silly problem to have.

Return to “HATs and other add-ons”