Newby Tyro
Posts: 7
Joined: Tue Mar 17, 2020 3:02 pm

I2C compatibility issue

Wed May 13, 2020 5:05 pm

Can any kind soul please help with this:

I am using a Pi 2B. It will eventually be offline, and I need to use a real time clock with it: I have successfully connected and programmed the SDA and SCL GPIO pins to run a DS1307 RTC, setting and reading the clock.

All this has been done using a HDMI monitor, keyboard and mouse. BUT I would like to use the 7 inch RPi touchscreen monitor in the final configuration, though I don't need the touchscreen facility.

Does anyone know whether the screen will be compatible with the simultaneous, quite frequent use of the real time clock on the same I2C bus?

Or is there a better workaround?

Thanks!

trejan
Posts: 2134
Joined: Tue Jul 02, 2019 2:28 pm

Re: I2C compatibility issue

Wed May 13, 2020 5:56 pm

Newby Tyro wrote:
Wed May 13, 2020 5:05 pm
I am using a Pi 2B. It will eventually be offline, and I need to use a real time clock with it: I have successfully connected and programmed the SDA and SCL GPIO pins to run a DS1307 RTC, setting and reading the clock.
Linux already has support for DS1307 RTCs. Once configured properly, it will read the RTC at startup and then write it back at shutdown/restart. You don't need to manually access the RTC.
Newby Tyro wrote:
Wed May 13, 2020 5:05 pm
All this has been done using a HDMI monitor, keyboard and mouse. BUT I would like to use the 7 inch RPi touchscreen monitor in the final configuration, though I don't need the touchscreen facility.

Does anyone know whether the screen will be compatible with the simultaneous, quite frequent use of the real time clock on the same I2C bus?
The touchscreen uses a different I2C bus so it is separate. As you've got a Pi 2, you shouldn't connect the SDA/SCL jumper wires between the Pi and the official touchscreen interface board. Those wires are only needed for the early Pi 1 models. Any guide that tells you to blindly connect them for everything is wrong.

Newby Tyro
Posts: 7
Joined: Tue Mar 17, 2020 3:02 pm

Re: I2C compatibility issue

Thu May 14, 2020 9:06 am

Thanks very much for this. If Linux handles a DS1307 with a different bus, which GPIO pins does it use for SDA and SCL?

I have used pins 2 and 3 for my DS1307, which I need to read every 2 seconds to provide a time stamp for measurements made with my Python script, not to show time on the screen. Can I use other pins, and if so what smbus commands should I use to activate them?

ALL the guides that I have been able to find tell you to blindly connect the touchscreen SDA and SCL line to GPIO 2 and 3 - and they are surely more likely to be oriented towards Pi 3 or 4 since (I believe) the touch part of the screen is relatively recent ? - my guess was that those lines work the touchscreen function now, but I have not been able to find any data on their use.

Thanks very much for your comments!

User avatar
rpdom
Posts: 17174
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: I2C compatibility issue

Thu May 14, 2020 9:19 am

You don't need to connect the official touchscreen to pins 2 & 3 except on the very first Pi 1 series. The later models 1B+ moved that i2c bus to the screen cable instead of the GPIO pins. You can connect your DS1307 to pins 2 & 3 as normal and with the correct dtoverlay in /boot/config.txt it will just work.
Unreadable squiggle

Newby Tyro
Posts: 7
Joined: Tue Mar 17, 2020 3:02 pm

Re: I2C compatibility issue

Thu May 14, 2020 10:47 am

Thanks very much for your comments - I will try it out....

trejan
Posts: 2134
Joined: Tue Jul 02, 2019 2:28 pm

Re: I2C compatibility issue

Thu May 14, 2020 3:33 pm

Newby Tyro wrote:
Thu May 14, 2020 9:06 am
Thanks very much for this. If Linux handles a DS1307 with a different bus, which GPIO pins does it use for SDA and SCL?
It is the touchscreen that is on a different I2C bus. You should still attach your DS1307 to the GPIO header on GPIO2 + GPIO3.
Newby Tyro wrote:
Thu May 14, 2020 9:06 am
I have used pins 2 and 3 for my DS1307, which I need to read every 2 seconds to provide a time stamp for measurements made with my Python script, not to show time on the screen.
Is there a reason why you don't trust the Linux clock and need to read directly from the RTC? It would be much simpler to get the Linux kernel to read the RTC at startup then use the regular time functions in your script. I would expect accuracy to be slightly better as well since you're not doing a slow I2C transaction for each timestamp.
Newby Tyro wrote:
Thu May 14, 2020 9:06 am
ALL the guides that I have been able to find tell you to blindly connect the touchscreen SDA and SCL line to GPIO 2 and 3
All of those guides are wrong. See https://www.raspberrypi.org/documentati ... e/display/ where it says "Legacy support for Raspberry Pi 1 Model A/B". The additional two wires shouldn't be connected on anything except the original Pi 1A and 1B. If you do use those additional wires on a newer Pi then you're actually connecting two different I2C controllers together which can cause problems.
Newby Tyro wrote:
Thu May 14, 2020 9:06 am
and they are surely more likely to be oriented towards Pi 3 or 4 since (I believe) the touch part of the screen is relatively recent ?
The touchscreen has been part of the official display since it was released.

Newby Tyro
Posts: 7
Joined: Tue Mar 17, 2020 3:02 pm

Re: I2C compatibility issue

Thu May 14, 2020 8:08 pm

Thanks again for setting me right!!

Return to “Beginners”