I'm trying to build a radio, with a 5110 display (SPI), RTC and Si74703 (I2C) but it does not seem to be working.
#include "LCD_5110.h"
#include <Si4703_Breakout.h>
#include <Wire.h>
#include "RTClib.h"
/////////////////////// RADIO
int resetPin = P1_4 ;
int SDIO = P1_7;
int SCLK = P1_6;
Si4703_Breakout radio(resetPin, SDIO, SCLK);
int channel;
int volume;
char rdsBuffer[10];
////////////////////// CLOCK
RTC_DS1307 RTC;
DateTime now = DateTime(__DATE__, "01:01:01") ;
////////////////////// LCD
LCD_5110 lcd_screen;
boolean backlight = false;
void setup()
{
lcd_screen.begin();
lcd_screen.setBacklight(backlight);
lcd_screen.text(0, 0, "Initializing");
Serial.begin(9600);
Wire.begin() ;
RTC.begin();
/* radio.powerOn();
radio.setVolume(3);
*/
//if(!RTC.isrunning())
{
// RTC.adjust(DateTime(__DATE__, __TIME__));
RTC.adjust(DateTime(__DATE__, "01:01:01"));
}
lcd_screen.clear();
lcd_screen.text(0, 0, "Done");
displayTime() ;
lcd_screen.text(0, 5, "Kikou");
}
void loop()
{
displayTime() ;
delay(1000);
}
void displayTime()
{
lcd_screen.text(0, 0, "Test");
now = RTC.now() ;
lcd_screen.setFont(1);
String time_str = leadZero(now.hour()) ;
time_str.concat(":") ;
time_str.concat(leadZero((int)now.minute())) ;
lcd_screen.text(0, 0, time_str) ;
String min_str = "" ;
min_str += ":" ;
min_str += leadZero(now.second()) ;
lcd_screen.setFont(0) ;
lcd_screen.text(10, 1, min_str) ;
Serial.println(min_str) ;
}
String leadZero(int val)
{
String str = "" ;
if(val<10)
{
str = "0" ;
}
str.concat(val) ;
return str ;
}
when it display the time I got
01:0 :0
on the LCD or on Serial.print and when the number of second id >= 10
01:0 :10
if I comment out
Si4703_Breakout radio(resetPin, SDIO, SCLK);
I got the right display
01:01:01 .... 01:01:02 ... 01:01:15 etc
The RTC device and the radio are on I2C both, but the constructor of the radio object does nothing...
Before this version of code I got all sort of problem with the strings manipulation of the time.
Looks like an memory problem between String and one or more of the library to me....