texy
Forum Moderator
Forum Moderator
Posts: 5160
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

2.8" TFT + Touch Shield + DS1307 RTC

Sun Feb 09, 2014 9:20 am

Setup instructions for this new design based on my 2.8" TFT, but with a DS1307 RTC option.
Image
First, setup the screen and touch panel by following the instructions here :
http://www.raspberrypi.org/phpBB3/viewt ... 45&t=64993

Then to setup the RTC :
If possible ensure a valid internet connection is made on the Pi to get an accurate time and date. Also fit a CR2032 lithium battery in order to maintain correct time and date on power loss to the Pi.
The DS1307 is an I2C device, so that bus needs to be enabled. Edit the /etc/modules file

Code: Select all

sudo nano /etc/modules
Add

Code: Select all

i2c-bcm2708
i2c-dev
before the

Code: Select all

ads7846_device swap_xy=1 gpio_pendown=17 x_plate_ohms=100 pressure_max=255
line.
Then remove the i2c-bcm2708 line from the blacklist file

Code: Select all

sudo nano /etc/modprobe.d/raspi-blacklist.conf
put a # in front of the

Code: Select all

blacklist i2c-bcm2708
line and save it.
Install the python-smbus package

Code: Select all

sudo apt-get install python-smbus -y
This will also install the i2ctools package as a dependency.
At this point reboot the pi

Code: Select all

sudo reboot
After the restart check the pi can see the ds1307

Code: Select all

sudo i2cdetect -y 1
for Rev 2 Pi's
or

Code: Select all

sudo i2cdetect -y 0
for Rev 1 Pi's
and the following should be reported

Code: Select all

p[email protected] ~ $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
Note the '68' detected is the ds1307.
Now that the i2c bus is set up, we need to load the driver for the ds1307

Code: Select all

sudo modprobe rtc-ds1307
We need to be root to do the next bit

Code: Select all

sudo bash
then

Code: Select all

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
exit
If you then

Code: Select all

sudo i2cdetect -y 1
again you should see

Code: Select all

[email protected] ~ $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
Notice the 'UU' at address 68 - this means that the ds1307 is under control of the driver. To test this use

Code: Select all

sudo hwclock -r
If there is no valid internet connection to the Pi, the time may not be correct and it will need to be set manually.
Once the system time is correct it can be written to the ds1307 with

Code: Select all

sudo hwclock -w
You should then get the correct time and date with

Code: Select all

sudo hwclock -r
In order to load the ds1307 module upon a reboot of the Pi you'll need to add it to /etc/modules

Code: Select all

sudo nano /etc/modules
and enter

Code: Select all

rtc-ds1307
after the i2c-dev line you entered earlier.
Then the ds1307 device needs creating by adding it to the /etc/rc.local file

Code: Select all

sudo nano /etc/rc.local
and adding

Code: Select all

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
sudo hwclock -s
for a Rev 2 Pi, or

Code: Select all

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device (v2 raspberry pi)
sudo hwclock -s
for a Rev 1 Pi before the
exit 0
line.
Power off the Pi, leave it off for a while, then repower it and check the time and date are still correct.
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

icarus
Posts: 2
Joined: Thu Jun 05, 2014 9:44 am

Re: 2.8" TFT + Touch Shield + DS1307 RTC

Thu Jun 05, 2014 10:58 am

Hi Texy,

For some reason I cannot send you a personal message. So I reply here.
Do you have any of these board for sale? I'm interested in a "2.8" TFT + Touch Shield + DS1307 RTC". I also read you have a case compatible with this shield.

texy
Forum Moderator
Forum Moderator
Posts: 5160
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: 2.8" TFT + Touch Shield + DS1307 RTC

Thu Jun 05, 2014 4:55 pm

Hi
You need to have your first post approved before you can pm.
You can now pm ;-)
Yes I have stock.
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

Return to “HATs and other add-ons”