Data Type Conversion

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?

// Serial.print(RTC.hour, DEC);
    // Serial.print(":");
     //Serial.print(RTC.minute, DEC);

I was figurin on 00,00,00 hour, min, sec for 6 char in buffer.

You don't think it's important to count the commas"? I do.

You don't think it's important to count the terminating NULL"? I do.

Should it be bigger than six?

Yes.

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.

/*
LCD  Arduino
PIN1 = GND
PIN2 = 5V
RS(CS) = 8; 
RW(SID)= 9; 
EN(CLK) = 3;
PIN15 PSB = GND;
*/

#include "LCD12864RSPI.h"
#include "Wire.h"
#include <DS1307new.h>


#define AR_SIZE( a ) sizeof( a ) / sizeof( a[0] )

uint16_t startAddr = 0x0000;            // Start address to store in the NV-RAM
uint16_t lastAddr; 

void setup()
{
   Wire.begin();
  LCDA.Initialise(); // INIT SCREEN
  delay(100);
 
  pinMode(2, INPUT);                    // Test of the SQW pin, D2 = INPUT
  digitalWrite(2, HIGH);  
  
  RTC.setRAM(0, (uint8_t *)&startAddr, sizeof(uint16_t));
  
  unsigned char header[] = "Aquaria  Control";
  LCDA.DisplayString(0,0,header,16);
  
  RTC.getTime();
  RTC.ctrl = 0x00;                      // 0x00=disable SQW pin, 0x10=1Hz,
                                        // 0x11=4096Hz, 0x12=8192Hz, 0x13=32768Hz
  RTC.setCTRL();
  
  RTC.getTime();
  
  int hr = RTC.hour;
  LCDA.displayInteger(0,0,hr);
   
}

void loop()
{

}

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);
  unsigned char colon[] = ":";

How does an array with one element offer any advantage over a scalar variable?

The sprintf() process should have worked.

unsigned char timeString[12];
sprintf((char *)timeString, "%02d:%02d:%02d", RTC.hour, RTC.minute, RTC.second);

LCDA.DisplayString(0,1,timeString, strlen(timeString));

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:

strlen((const char *)buffer)

It seems no matter, it just throughs the opposite error e.g

strlen((const char *)buffer),                                         strlen((unsigned char *)buffer)
throughs error:invalid conversion conts char* to char*,       invalid conversion unsigned char* to char*

This compiles:

void setup()
{
  unsigned char *stg = (unsigned char *)"Some silly text";
  int stgLen = strlen((char *)stg);
}

void loop()
{
}

Thank you, but I was unable to make that code work. I have working code that displays hour, minute, and second as integer, but I cannot format it on the lcd. I would like the output to be formatted nice and tight across lcd.

Thank you, but I was unable to make that code work.

This compiles:

#include "LCD12864RSPI.h"

void setup()
{
  LCDA.Initialise(); // INIT SCREEN
  
  int hour = 12;
  int minute = 47;
  int second = 23;
  
  unsigned char timeString[12];
  sprintf((char *)timeString, "%02d:%02d:%02d", hour, minute, second);

  LCDA.DisplayString(0,1,timeString, strlen((char *)timeString));
}

void loop()
{
}

I should have suspected earlier that the library was from dfrobot. I wouldn't buy anything from them if it was free. They provide no support for Arduino.

Thank you very much for that code. It works great! What hardware manufacturer would you reccomend that would be easier to work with throughout this project?

Also, how can i make this 12hr format instead of 24hr?

It works great!

So, now all you have to do is use RTC.hour, RTC.minute, and RTC.second in place of the hardcoded values.

What hardware manufacturer would you reccomend that would be easier to work with throughout this project?

I don't know where in the world you are, so a manufacturer/supplier that was good for me might not be good for you.

Also, how can i make this 12hr format instead of 24hr?

Whack the RTC into submission. If that doesn't work, test the hour. If it is greater than 12, subtract 12.

I am in Ohio, USA, but I order all my hardware from internet.

Im sorry but I dont know what you mean by whack into submission, but I can try to implement check.

The RTC you are using probably has a setting that tells it whether you want the time in 12 hour or 24 hour format. I don't know what RTC that is, though, so I can't tell you what that setting is.

I am in Ohio, USA, but I order all my hardware from internet.

Sparkfun is on the internet. They pissed me, and a whole lot of other people, off with their "free day" fiasco a couple of years ago, but when I want something that I know will work and I want it now, I order from them.