I am using a Sainsmart 128x64 LCD. which requires an unsigned char* as a third parameter in it's displaystring() function. My problem is that the DS1307 RTC code is returning hour, min, and sec in uint8_t, so how can I convert so that I can display time on lcd?
uint8_t to unsigned char*
GiGalo:
I am using a Sainsmart 128x64 LCD. which requires an unsigned char* as a third parameter in it's displaystring() function. My problem is that the DS1307 RTC code is returning hour, min, and sec in uint8_t, so how can I convert so that I can display time on lcd?
uint8_t to unsigned char*
Professor Chaos - From what I am seeing, sprintf ( char * str, const char * format, ... ) requires char, hence, when I declare as unsigned char, arduino returns error: cannot convert unsigned char* to char**
guix - Thank you! Before attempting the sprintf() idea, I explored casting and the result was just a weird looking blob on screen. More like a char rather than int. However, attempting the code change you just recommended, the code compiled with no errors, but the lcd is blank. As far as editing the displaystring function, I dont know enough about c to do that. If pointed in the right direction i could probably figure it out though
It's time to post ALL of your code. In the RTC class I use, hour and minute are methods, not fields. So, it looks to me like you are writing the address of the method to the string, not the time.
You have a Serial.begin() in setup(), but no Serial.print(ln), after getting the time. Why not? What is in hour and minute? If the values are not valid, then it is possible that you are overflowing the 6 element buffer, who's size expects hour and minute to result in not more than 2 characters per value.
After sprintf() does its thing, what is in buffer?
Given that the buffer size is 6, why does it appear that you are telling the function to print 16 characters?
The serial.begin was to initially print time to serial monitor. I just forgot to take the code back out. below is the working lines that print to serial monitor. I was figurin on 00,00,00 hour, min, sec for 6 char in buffer. Should it be bigger than six?
OK so I was able to find an updated cpp file which had a displayInteger() function that I was able to add to my cpp file. This test code prints out my hour.
So printing out the hour, min, and second are finally done! The problem is now, how do you format this output so that it is nice and tight on the lcd. Right now this print the time out accordingly but with an empty space between output. Any Ideas?
int hr = RTC.hour;
int minu = RTC.minute;
int sec = RTC.second;
unsigned char colon[] = ":";
LCDA.displayInteger(0,0,hr);
LCDA.DisplayString(0,1,colon,1);
LCDA.displayInteger(0,2,minu);
LCDA.DisplayString(0,3,colon,1);
LCDA.displayInteger(0,4,sec);
I know it does not sound right, but without the array there is a conversion error for some reason.
Thank you very much for your feedback, it is greatly appreciated!
The provided code gives me a conversion error:
invalid conversion from unsigned char* to const char*
and
error intializing argument 1 of 'size_t strlen(const char*)'
Signed char, unsigned char, const signed char, and const unsigned char are all the same size. If a function expects one type, and you have another, lie to the function. Tell it that the type you have IS the type it expects.
If strlen() expects a const char *, and you have a unsigned char *, lie to it: