Go Down

Topic: i2c clock trouble (Read 408 times) previous topic - next topic

MechNTech

May 23, 2019, 01:35 am Last Edit: May 24, 2019, 03:23 pm by MechNTech
I am trying to make a clock, seems easy enough. Everything works by itself, alone. But the code seems to hang when I introduce the RTC (DS1307) library AND the tm1637 library. When running the two things together the code just hangs. so into troubleshooting

Trying to get something to work I realized that the RTC would work and send 22 as an hour (at 10pm) but once I hooked one of the wires (clock OR data) the RTC would go to 165 only and every time.

is something not i2c? I am confused on why it changes, when the device addresses are not the same.

I am using adafruit RTClib and TM1637 library from Avishay

The device is a simple i2c connection with 3.3k resistor and a 100nf cap between vcc and ground.

please help! Ill buy a new module if I need to

Code: [Select]

#include <Wire.h>
#include <TM1637Display.h>
#include "RTClib.h"

RTC_DS1307 RTC;


TM1637Display display(SCL, SDA);


int hr1, hr2, min1, min2;
void setup()
{
    Wire.begin();
    RTC.begin();

     if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
}

void loop()
{
  DateTime now = RTC.now();

  uint8_t data[] = { 0xff, 0xff, 0xff, 0xff };
  uint8_t blank[] = { 0x00, 0x00, 0x00, 0x00 };
  display.setBrightness(0x0f);

  // All segments on
  display.setSegments(data);
  delay(5000);

  hr1 = (now.hour() / 10);
  hr2 = (now.hour() % 10);
  min1 = (now.minute() / 10);
  min2 = (now.minute() % 10);
 
  display.setBrightness(0x0f);
  display.clear();
  data[0] = display.encodeDigit(hr1);
  data[1] = display.encodeDigit(hr2);
  data[2] = display.encodeDigit(min1);
  data[3] = display.encodeDigit(min2);
 
  display.setSegments(data);
  delay(5000);
}

jremington

Please edit your post to change the quote tags to code tags.

I have no idea what you mean by this:
Quote
The device is a simple i2c connection with 3.3k resistor and a 100nf cap between vcc and ground.
Please post a hand drawn wiring diagram (not Fritzing), labeling all the connections with pin numbers.



Geek Emeritus

Quote
I am trying to make a clock, seems easy enough.
you think it is, until you try.

Build a GPS-controlled Clock
Build an AccurateGPS-Controlled Clock: Step by Step

All PMs will be deleted unopened due to arrogant argumentative pot stirring Malfoys.
 If you have not read "How to use this forum - please read", in particular: "7. If you are posting code or error messages, use "code" tags":  expect rude responses

MechNTech

#3
May 24, 2019, 03:46 pm Last Edit: May 24, 2019, 03:46 pm by MechNTech
you think it is, until you try.

Build a GPS-controlled Clock
Build an AccurateGPS-Controlled Clock: Step by Step


I think you pointed me towards the solution with these guides. I will have to test later.

Whandall

#4
May 25, 2019, 04:04 pm Last Edit: May 25, 2019, 04:10 pm by Whandall
Quote
Interface interpretationMicroprocessor  data realize  the  communicationwith TM1637by means  of two-wire  bus  interface
(Note: The communication method is not equal to 12C bus protocol totally because there isno slave address).
From https://www.mcielectronics.cl/website_MCI/static/documents/Datasheet_TM1637.pdf

Code: [Select]
TM1637Display display(SCL, SDA);

You should use different pins for I2C (RTC) and the TM1637.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

Go Up