Skip to content

i2C problems #1071

@dnienhis

Description

@dnienhis

Please fill the info fields, it helps to get you faster support ;)

If you have a Guru Meditation Error, please decode it:
https://github.com/me-no-dev/EspExceptionDecoder

----------------------------- Remove above -----------------------------

Hardware:

Board: Espressif ESP32 ESP32-DEVKITC
Core Installation/update date: 25 Jan 18
IDE name: Arduino IDE 1.8.5 - Windows 10
Flash Frequency: 80 Mhz
Upload Speed: 921600

Description:

Trying to read time from the Adafruit DS1307 Board (https://www.adafruit.com/product/3296) - completely functional with ESP8266 & Arduino UNO over i2C - unable to read from ESP32. This is the test/demo code supplied by Adafruit - also using their library - the only thing I changed was adding and removing the #include <WiFi.h> when compiling for ESP32.

On the ESP32 I connected the i2C signals as follows:

SCL - GPIO21
SDA - GPIO22

(the connections didn't match up with what i'd read online - i found these via Oscilliscope & trial & error while running demo code below).

I'm attaching Oscilliscope captures from each of the three test scenarios.

This is my first time to post so please 'be gentle' LOL !

Arduino UNO
arduinouno-ds1307
ESP32 Dev
esp32dev-ds1307a
ESP32 Dev
esp32dev-ds1307b
ESP32 Dev
esp32dev-ds1307c
ESP-8266
esp8266-ds1307

Sketch:

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

//#include <WiFi.h>
#include <Wire.h>
#include "RTClib.h"

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
#define Serial SerialUSB
#endif

RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup () {

#ifndef ESP8266
while (!Serial); // for Leonardo/Micro/Zero
#endif

Serial.begin(9600);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}

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(F(DATE), F(TIME)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
}

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

Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();

Serial.print(" since midnight 1/1/1970 = ");
Serial.print(now.unixtime());
Serial.print("s = ");
Serial.print(now.unixtime() / 86400L);
Serial.println("d");

// calculate a date which is 7 days and 30 seconds into the future
DateTime future (now + TimeSpan(7,12,30,6));

Serial.print(" now + 7d + 30s: ");
Serial.print(future.year(), DEC);
Serial.print('/');
Serial.print(future.month(), DEC);
Serial.print('/');
Serial.print(future.day(), DEC);
Serial.print(' ');
Serial.print(future.hour(), DEC);
Serial.print(':');
Serial.print(future.minute(), DEC);
Serial.print(':');
Serial.print(future.second(), DEC);

Serial.println();

Serial.println();
delay(3000);

}

Debug Messages:

Enable Core debug level: Debug on tools menu of Arduino IDE, then put the serial output here 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions