How do I connect the LCD backpack and RTC clock?

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
djsfantasi
 
Posts: 54
Joined: Mon Apr 28, 2014 8:01 am

Re: How do I connect the LCD backpack and RTC clock?

Post by djsfantasi »

Ok, that has seemed to fix the issue. I removed the "Wire.begin();" statement. I re-arranged the statements, so the RTC initialization came after the LCD init.. It is working as expected now.

Code: Select all

void setup () {
// omitted

  // set up the LCD
  lcd.begin(COLUMNS_LCD, ROWS_LCD);
  lcd.print("Hello world!");

// init. the RTC
  rtc.begin();
  todayDate = now.unixtime();
  
// omitted
}
Thanks franklin97355 and adafruit2!

djsfantasi
 
Posts: 54
Joined: Mon Apr 28, 2014 8:01 am

Re: How do I connect the LCD backpack and RTC clock?

Post by djsfantasi »

This is important to me; client is waiting for it.

No, I am not necro'ing this thread! I just assembled everything again - and the LCD stops displaying when the RTC is inserted.
The following is a list of components:
  • Arduino Mega 2560
    "Music Maker" shield
    DS1307 Real Time Clock kit
    RGB backlight positive LCD 16x2
    i2c / SPI character LCD backpack
I have done some experimenting and the problem appears to halt execution of the sketch. If I start w/o the RTC, it runs as expected. If I insert it, the sketch stops. If I start with the RTC, nothing happens (sketch-wise). Until I remove the RTC, and then it runs. It looks like the Arduino clock (i.e., the millis() function) continues to run, even though the sketch does not.

This time, I am NOT including the "Wire.begin();" line.

HELP!

Test sketch:

Code: Select all

/*
 Demonstration sketch for Adafruit i2c/SPI LCD backpack
 using MCP23008 I2C expander
 ( http://www.ladyada.net/products/i2cspilcdbackpack/index.html )

 This sketch prints "Hello World!" to the LCD
 and shows the time.

  The circuit:
 * 5V to Arduino 5V pin
 * GND to Arduino GND pin
 * CLK to Analog #5
 * DAT to Analog #4
*/

// include the library code:
#include "Wire.h"
#include "LiquidCrystal.h"

const byte red = 22;
const byte blue = 24;
const byte green = 26;

// Connect via i2c, default address #0 (A0-A2 not jumpered)
LiquidCrystal lcd(0);

void setup() {
  // set up the LCD's number of rows and columns:
  Serial.println("Initializing backlight pins");
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);

  Serial.println("Initializing LCD");
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
  
  Serial.begin(9600);
  Serial.println("Setup complete");
}

void loop() {
  static byte color = 1;
  int mySeconds=0;

  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  mySeconds=millis()/1000;
  lcd.print(mySeconds);
  Serial.println(mySeconds);

  switch (color) {
    case 1: {
        color = 2;
        backlit(red);
        break;
      }
    case 2: {
        color = 3;
        backlit(green);
        break;
      }
    case 3: {
        color = 1;
        backlit(blue);
        break;
      }
  }

}

void backlit(byte myPin) {
  digitalWrite(red, LOW);
  digitalWrite(blue, LOW);
  digitalWrite(green, LOW);

  digitalWrite(myPin, HIGH);
  delay(1000);
  return;
}

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: How do I connect the LCD backpack and RTC clock?

Post by adafruit_support_mike »

If you disconnect the LCD and load a sketch that only uses the RTC, does the RTC work?

djsfantasi
 
Posts: 54
Joined: Mon Apr 28, 2014 8:01 am

Re: How do I connect the LCD backpack and RTC clock?

Post by djsfantasi »

adafruit_support_mike wrote:If you disconnect the LCD and load a sketch that only uses the RTC, does the RTC work?
Yes, it does.

Late last night, I think I was able to get it to work... I fiddled around with the order of instantiation, the order of calling the .begin methods and where I created a RTC object...

At the top of the sketch, now I instantiate the two objects in this order

Code: Select all

LiquidCrystal lcd(0);
RTC_DS1307 rtc;
Then, in the setup() function, I initialize the devices in the same order.

Code: Select all

lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("LCD initialized!");
Serial.println("LCD initialized");

Code: Select all

// Initialize  RTC
Serial.println("Initializing RTC");
rtc.begin();
Serial.println("RTC initialized");
Then, in the loop() function, I create my class or variable or whatever it is called and use its values.

Code: Select all

void loop() {
  long mySeconds = 0;
  DateTime now = rtc.now();
Still was having issues (Oh, and I periodically testing the two peripherals standalone, to ensure I hadn't damaged them) Oh, yeah! I had to do one more thing. I was powering the RTC with two pins, defining them as digital output pins and setting one low and one high. So I took the RTC off the Arduino Mega, and used jumpers to connect to Vcc, Gnd and SDA/SCL on the board. It ran fine for several hours. (then it hung and had to be reset)

So I can't use pins to power the DS1307 kit?

On the Mega, SDA and SCL were moved, so I had to mount the RTC sideways and use pins 18 & 19 (RX1 & TX1) as digital pins to power it. The only other idea I have is to mount the power pins on the DS1307 board "upside down", so the SDA/SCL pins insert into the Mega board, and power is jumpered to other locations. Too bad in this configuration the Vcc pins, on the row of pins Vcc/22-53 of the Mega, are covered by the board. (Nice to have a Mega version of the PCB)

Code: Select all

// Test the RTC with the LCD functioning

// include the library code:
#include "Wire.h"
#include "LiquidCrystal.h"
#include "RTClib.h" // DS1307 Real Time Clock library

const byte red = 24;
const byte blue = 26;
const byte green = 28;
const byte RTC_GND = 18;
const byte RTC_VCC = 19;
volatile byte color = 1;
// Connect via i2c, default address #0 (A0-A2 not jumpered)
LiquidCrystal lcd(0);
RTC_DS1307 rtc;

//**************************************************
void setup() {
  Serial.begin(57600);

  // set up the LCD's number of rows and columns:
  Serial.println("Initializing LCD backlight");
  pinMode(red, OUTPUT); // initializing backlight pins
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
  switchColor();
  Serial.println("Backlight initialized");
  Serial.println("Initializing LCD");
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("LCD initialized!");
  Serial.println("LCD initialized");

  // Initialize  RTC
/*
  Serial.println("Initializing RTC power");
  pinMode(RTC_GND, OUTPUT);   // set pins to power RTC
  digitalWrite(RTC_GND, LOW);
  pinMode(RTC_VCC, OUTPUT);
  digitalWrite(RTC_VCC, HIGH);
  Serial.println("RTC power initialized");
*/
  Serial.println("Initializing RTC");
  rtc.begin();
  Serial.println("RTC initialized");

  Serial.println("Setup complete");
}

//**************************************************
void loop() {
  long mySeconds = 0;
  DateTime now = rtc.now();

  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  // mySeconds = millis() / 1000;
  mySeconds=now.second();
  lcd.print(mySeconds);
  Serial.print("Seconds ");
  Serial.println(mySeconds);

  switchColor();
}

//--------------------------------------------------
void backlit(byte myPin) {
  digitalWrite(red, LOW);
  digitalWrite(blue, LOW);
  digitalWrite(green, LOW);

  digitalWrite(myPin, HIGH);
  delay(1000);
  return;
}

//--------------------------------------------------
void switchColor() {
  
  Serial.println(color);
  
  switch (color) {
    case 1: {
        color = 2;
        backlit(red);
        break;
      }
    case 2: {
        color = 3;
        backlit(green);
        break;
      }
    case 3: {
        color = 1;
        backlit(blue);
        break;
      }
  }
}


User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: How do I connect the LCD backpack and RTC clock?

Post by adafruit_support_mike »

The DS1307 only uses a couple of milliamps, so you should be able to power it from an Arduino pin.

Using two pins is more complicated than it needs to be though, and opens the possibility for several major problems without solving any. Just connect the GND pin to the Arduino's GND and use a pin for the DS1307's VCC.

djsfantasi
 
Posts: 54
Joined: Mon Apr 28, 2014 8:01 am

Re: How do I connect the LCD backpack and RTC clock?

Post by djsfantasi »

I was trying to plug it directly onto the Arduino Mega, like I could with the Arduino Uno. I could never get it to work, so ended up jumpering the four pins to the board, and using Vcc and Gnd instead of any pins. Works fine now.

(Now I am struggling with the VS1053 hanging when I try to play a file; works in a test sketch, not the final one.)

Thanks for helping!

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”