Hello All,
I am learning about I2C communication on my Arduino Mega 2560. I am trying to use two I2C devices, Sparkfun's HIH6130 temp/humidity breakout board, as well as Sparkfun's DS1307 RTC breakout board. I've gotten each device to work fine individually, but I believe I'm having an issue with either working when wired in parallel.
Running the below code for the RTC and with the HIH6130 completely disconnected, I get a normal response. As soon as I plug the HIH6130 in parallel to the RTC, however, the RTC hangs and the code fails to display any outputs.
I see that the HIH6130 already has 2.2k pull-up resistors to VCC over the SCL and SDA lines. Does this imply that I shouldn't need a pull-up resistor for the RTC if I hook it in parallel? Any guidance on wiring these two breakout boards would be hugely appreciated. I'm a mechanical guy, and circuits can be overwhelming at times.
HIH6130 homepage: SparkFun Humidity and Temperature Sensor Breakout - Si7021 - SEN-13763 - SparkFun Electronics
HIH6130 schematic: http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Weather/HIH6130_Breakout_v10.pdf
DS1307 homepage: SparkFun Real Time Clock Module - BOB-12708 - SparkFun Electronics
DS1307 schematic: http://dlnmh9ip6v2uc.cloudfront.net/datasheets/BreakoutBoards/RTC-Module-v13.pdf
#include <Wire.h>
#define DS1307_I2C_ADDRESS 0x68 //the i2C address for the RTC
//variables necessary for the RTC
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
byte zero;
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
//code for getting time from the RTC
String getTimeDs1307()
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7, true);
// A few of these need masks because certain bits are control bits
second = bcdToDec(Wire.read() & 0x7f);
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read() & 0x3f); // Need to change this if 12 hour am/pm
dayOfWeek = bcdToDec(Wire.read());
dayOfMonth = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
String timeString="";
timeString += hour, DEC;
timeString += ":";
timeString += minute, DEC;
timeString += ":";
if (second < 10)
timeString += "0";
timeString += second, DEC;
//Serial.println(timeString);
return timeString;
}
void setup() {
Wire.begin();
Serial.begin(9600);
Serial.println("Code is started");
zero=0x00;
}
void loop() {
Serial.println(getTimeDs1307());
delay(3000);
}