Go Down

Topic: Using the 1.5.7 Beta with Ardunio Uno and Adafruit LCD (Read 262 times) previous topic - next topic


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) {
    }else {

all the values are output like this:
sprintf(timeBuff,"%s:%s:%s", hours, minutes, seconds);   
   clock = timeBuff; 
   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??



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.
Everything is binary, even life itself. It consists of only two things: the things that matter and the rest.


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)


Not an answer to the "E"s question

Well, maybe it is. When variables are overwritten anything can happen.
Everything is binary, even life itself. It consists of only two things: the things that matter and the rest.


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.




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!



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?
[ I won't respond to messages, use the forum please ]

Go Up