Pages: [1]   Go Down
Author Topic: Using the 1.5.7 Beta with Ardunio Uno and Adafruit LCD  (Read 133 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello All,
I have a program that runs fine in the 1.0.5 IDE,
It counts seconds using Timer1.   it prints a string to the LCD display
as HH:MM:SS - this is a clock that updates every second.  I created my own conversion from
the "count" of seconds for this.  The hours, mins, sec are loaded into a string buffer like this:

  if (minn < 10) {
       sprintf(minutes,"0%ld",minn);
    }else {
       sprintf(minutes,"%ld",minn);
   }

all the values are output like this:
 sprintf(timeBuff,"%s:%s:%s", hours, minutes, seconds);   
   clock = timeBuff; 
   lcd.setCursor(0,1);
   lcd.println(clock + "        ");

timeBuff is defined thus: char[8] timeBuff;
clock is: String clock = "";

the string prints fine using 1.0.5 = 00:12:33 etc
The program compiles fine in 1.5.7 - but  the the clock string prints as a bunch of "E"s and funny characters.

Is it me or is it memorex??

ewholz
Logged

Offline Offline
Edison Member
*
Karma: 35
Posts: 1086
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your timeBuff is ony 8 characters, but when you use sprintf, it adds an extra '\0', or string-terminator, or zero-terminator.
So you use 9 characters. If you make it timeBuff[10] is might work.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Not an answer to the "E"s question, but if you must use the "printf" family of routines (and personally I find it very hard to justify the overhead of a run-time interpreter when the format string is almost always static, plus the storage overhead of every function the family might need even if the format is never actually used - all in a limited memory and generally slow processor!!! - end of soapbox dissertation) the why not use something like:
sprintf( buffer, "  %02ld:%02ld:%02ld  ", hours, mins, secs)
(Each of those format strings is "percent zero two lowercase-ell lowercase-d.)
That format specification tells the printf formatter to use a 2 character field with that is left-padded with zeros and does away with all of the "if - else" options. Also it can add in the spaces as necessary.
(Return to the soapbox - I would use something like the 'ltoa' function even if it does mean either testing for 'less than 10' as you have done or adding 100 and skipping the first character)
Susan
Logged

Offline Offline
Edison Member
*
Karma: 35
Posts: 1086
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Not an answer to the "E"s question

Well, maybe it is. When variables are overwritten anything can happen.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, found my problem here:

when printing to the LCD I was using lcd.println(mystring);  mystring contains a "line feed"
switched to lcd.print(mystring) = no line feed, and no extra characters.

thanks,

ewholz

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Reading AussieSusan's post gave me an idea!

just print the sprint "buffer" using lcd.print(buffer) - and delete 3 lines of dumb code (my dumb code)!

thanks again for a responsive forum!

ewholz
Logged

0
Offline Offline
Shannon Member
****
Karma: 207
Posts: 12200
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Remember 1.5.7 is BETA software - there's no guarantee it works.  Most of the
development for it is for Due and Yun, to my knowledge, so breakages for the AVR
Arduinos may not be noticed (having said that there's no reason to suspect issues).

At least read the release notes.

Why not stick to the stable release 1.0.5 for the Uno?
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: