Multiplexing for RTCs

I'm trying to get an RTC working, specifically an DS1307. The module works if I use it alone, but I want to use it together with other analog inputs, and since I only have 2 left, because the others are occupied by an LCD Screen I tried using a multiplexer, the multiplexer works for the other analog inputs (photoresistor and thermistor) but fluctuates for the RTC module.

I have is set up to switch between 1 of the 2 analog values from the RTC and the other 2 analog values of photoresistor and thermistor.

Using the ReadTest example from the DS1307 library I get varying results, it sometimes works and sometimes doesn't.

Ok, Time = 11:48:07, Date (D/M/Y) = 9/6/2016
DS1307 read error!  Please check the circuitry.

Ok, Time = 11:48:18, Date (D/M/Y) = 9/6/2016
Ok, Time = 11:48:19, Date (D/M/Y) = 9/6/2016
DS1307 read error!  Please check the circuitry.

DS1307 read error!  Please check the circuitry.

Ok, Time = 11:48:40, Date (D/M/Y) = 9/6/2016
Ok, Time = 11:48:41, Date (D/M/Y) = 9/6/2016
Ok, Time = 11:48:42, Date (D/M/Y) = 9/6/2016
Ok, Time = 11:48:43, Date (D/M/Y) = 9/6/2016
Ok, Time = 11:48:44, Date (D/M/Y) = 9/6/2016
DS1307 read error!  Please check the circuitry.

DS1307 read error!  Please check the circuitry.

Ok, Time = 11:49:05, Date (D/M/Y) = 9/6/2016
Ok, Time = 11:49:06, Date (D/M/Y) = 9/6/2016
Ok, Time = 11:49:07, Date (D/M/Y) = 9/6/2016
DS1307 read error!  Please check the circuitry.

DS1307 read error!  Please check the circuitry.

This is an example, you can see that some times (more often than not) the value of the analog input pin is messed up, even if I've set the multiplexer to the right pin the whole time.

What could be the cause of this problem? Is the multiplexer faulty? Why does it sometimes output different values? Maybe because it shares the 5V Vcc with the 2 variable resistors, and thus not having a "clean" or stable source?

Why would you be using analog inputs for an LCD screen or a RTC module?

Do you mean they are both I2C devices which both connect to A4 and A5? So you connect them. What's the problem?

Sounds like the photoresistor and thermistor are hosing the I2C lines, or the mux is not working as intended. What part are you using and how is it wired up?

I would recommend not using a multiplexer on the i2c pins.

Are you using an LCD shield? That means you have no choice over which pins it uses.

If not an lcd shield, to free up pins, get an i2c adaptor for your display. If you need more analog pins, get an as1115 module. Both are very cheap.

Paul

16-Bit-I2C-4-Channel-ADS1115-Mod.jpg
86014-Free-Shipping-1602-2004-LC.jpg