Adding a Real Time Clock to Raspberry Pi



Similar documents
Raspberry Pi Adding a Real Time Clock (RTC)

Matrix and 7-Segment LED Backpack with the Raspberry Pi

PiFace Real Time Clock user guide

Playing sounds and using buttons with Raspberry Pi

Adafruit NFC/RFID on Raspberry Pi

Setting up a Raspberry Pi as a WiFi access point

Adafruit MCP9808 Precision I2C Temperature Sensor Guide

Accessing I2C devices with Digi Embedded Linux 5.2 example on Digi Connect ME 9210

Bob Rathbone Computer Consultancy

Adafruit's Raspberry Pi Lesson 5. Using a Console Cable

TSL2561 Luminosity Sensor

Adafruit BME280 Humidity + Barometric Pressure + Temperature Sensor Breakout

DS1307 Real Time Clock Breakout Board Kit

Adafruit SHT31-D Temperature & Humidity Sensor Breakout

Adafruit's Raspberry Pi Lesson 5. Using a Console Cable

Arduino Lesson 14. Servo Motors

Drive a 16x2 LCD with the Raspberry Pi

Install bluez on the Raspberry Pi

Adafruit's Raspberry Pi Lesson 9. Controlling a DC Motor

Setting up IO Python Library on BeagleBone Black

Monitor Your Home With the Raspberry Pi B+

PiFace Control & Display

Beginner s Guide to the PI MATRIX. by Bruce E. Hall, W8BH 1) INTRODUCTION

Adafruit's Raspberry Pi Lesson 11. DS18B20 Temperature Sensing

Adafruit's Raspberry Pi Lesson 6. Using SSH

Arduino Lesson 13. DC Motors. Created by Simon Monk

Adafruit NFC/RFID on Raspberry Pi. Created by Kevin Townsend

2.2" TFT Display. Created by Ladyada. Last updated on :15:09 PM EDT

Arduino Lesson 0. Getting Started

Arduino Lesson 4. Eight LEDs and a Shift Register

secucam User Manual Version 1.1.x Darhon Software

Adafruit's Raspberry Pi Lesson 5. Using a Console Cable. Created by Simon Monk

Adafruit's Raspberry Pi Lesson 3. Network Setup

Raspberry Pi Kernel-o-Matic

Strato Pi Hardware Guide

Adafruit's Raspberry Pi Lesson 1. Preparing an SD Card for your Raspberry Pi

A REST API for Arduino & the CC3000 WiFi Chip

AR1100 Resistive Touch Screen Controller Guide

Preparing Raspberry Pi

Raspberry Pi radio player with touchscreen

2.3" Monochrome 128x32 OLED Display Module

How To Connect A Raspberry Pi To The Internet On A Microsoft Moonstone 2 (Microsoft) Microsoft Powerbook 2 (Powerbook 2) (Powerboard 2) And Powerbook 3 (Powerstation 2)

5inch HDMI LCD User Manual

1.5" & 2.1" Monochrome 128x64 OLED Display Module

Cloud Cam: Internet-Connected Security Camera

- 35mA Standby, mA Speaking pre-defined phrases with up to 1925 total characters.

7/Basic Input and Output

Adafruit's Raspberry Pi Lesson 7. Remote Control with VNC

CPSC 226 Lab Nine Fall 2015

SSH to BeagleBone Black over USB

NB3H5150 I2C Programming Guide. I2C/SMBus Custom Configuration Application Note

Arduino Lesson 9. Sensing Light

Hardware Connections between Arduino and IMU Nori Wilkins Apr. 5, 2013

Setting up WiFi with BeagleBone Black

Adafruit Proto Shield for Arduino

Character LCDs. Created by Ladyada. Last updated on :45:29 PM EDT

UniPi technical documentation REV 1.1

7" Portable HDMI Monitor

Raspberry Pi Android Projects. Raspberry Pi Android Projects. Gökhan Kurt. Create exciting projects by connecting Raspberry Pi to your Android phone

MCP4725 Digital to Analog Converter Hookup Guide

Raspberry Pi Webserver

Bluefruit LE Python Library

DS1307ZN. 64 x 8 Serial Real-Time Clock

BeagleBone Black: Installing Operating Systems

Hardware monitoring on Fujitsu mainboards. Hardware monitoring on Fujitsu mainboards

Restoring a Suse Linux Enterprise Server 9 64 Bit on Dissimilar Hardware with CBMR for Linux 1.02

Raspberry Pi WiFi Radio

Setup Cisco Call Manager on VMware

Tiny Arduino Music Visualizer

Using pcduino's WiFi Dongle With the Pi a

By default, pilight uses a random port for its socket server. Use the port setting If you want to set this to a fixed port.

Standalone Attendance Monitoring and Projector System

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science Microprocessor Project Laboratory

Network Interface Failover using FONA

Basic ESXi Networking

AXE033 SERIAL/I2C LCD

Version 1.0. File System. Network Settings

7inch HDMI LCD (B) User Manual

Pwn Plug Community Edition 1.1 Installation Guide

Imprint. ecodms Version: (krusty) Manual Build Number: 20 Language: Copyright 2016: ecodms GmbH Salierallee 18a Aachen Germany

E-Blocks Easy Internet Bundle

AXE114S BINARY CLOCK. revolution Revolution Education Ltd. Web: Version /09/08 AXE114.PMD.

Pmod peripheral modules are powered by the host via the interface s power and ground pins.

Raspberry Pi Setup Tutorial

RGB LED Strips. Created by lady ada. Last updated on :00:18 PM EST

Wireless Mobile Broadband Setup Guide for Linux OS

RocketRAID 2640/2642 SAS Controller Ubuntu Linux Installation Guide

Arduino Lesson 17. Sending Movement Detector

HOWTO: Set up a Vyatta device with ThreatSTOP in router mode

7 OUT1 8 OUT2 9 OUT3 10 OUT4 11 OUT5 12 OUT6 13 OUT7 14 OUT8 15 OUT9 16 OUT10 17 OUT11 18 OUT12 19 OUT13 20 OUT14 21 OUT15 22 OUT16 OUT17 23 OUT18

Grandstream Networks, Inc. DHCP Options Guide

Your Multimeter. The Arduino Uno 10/1/2012. Using Your Arduino, Breadboard and Multimeter. EAS 199A Fall Work in teams of two!

Battery Power for LED Pixels and Strips. Created by Phillip Burgess

PORTABLE STORAGE DEVICE MANAGEMENT IN LINUX

Network Testing Tools. Ettore Tamiro GARR - Network Operation Center PAP Workshop July 15, 2009

Universal Mobile Print Server On the Cheap, and Cloud-free. What You Will Need. Configuring your Pi as a Print Server

ISP Engineering Kit Model 300

ITRAINONLINE MMTK WIRELESS CLIENT INSTALLATION HANDOUT


Intro to Intel Galileo - IoT Apps GERARDO CARMONA

Transcription:

Adding a Real Time Clock to Raspberry Pi Created by lady ada Last updated on 2016-04-29 11:45:10 PM EDT

Guide Contents Guide Contents Overview Wiring the RTC Set up I2C on your Pi Verify Wiring (I2C scan) Set RTC Time Raspbian Jessie (Systemd) Raspbian Wheezy or other pre-systemd Linux 2 3 5 6 6 8 9 10 Adafruit Industries https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi Page 2 of 11

Overview This tutorial requires a Raspberry Pi running a kernel with the RTC module and DS1307 module included. Current Raspbian distros have this, but others may not! The Raspberry Pi is designed to be an ultra-low cost computer, so a lot of things we are used to on a computer have been left out. For example, your laptop and computer have a little coin-batterypowered 'Real Time Clock' (RTC) module, which keeps time even when the power is off, or the battery removed. To keep costs low and the size small, an RTC is not included with the Raspberry Pi. Instead, the Pi is intended to be connected to the Internet via Ethernet or WiFi, updating the time automatically from the global ntp (nework time protocol) servers For stand-alone projects with no network connection, you will not be able to keep the time when the power goes out. So in this project we will show you how to add a low cost battery-backed RTC to your Pi to keep time! Adafruit Industries https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi Page 3 of 11

Adafruit Industries https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi Page 4 of 11

Wiring the RTC To keep costs low, the Raspberry Pi does not include a Real Time Clock module. Instead, users are expected to have it always connected to WiFi or Ethernet and keep time by checking the network. Since we want to include an external module, we'll have to wire one up. We'll go with the easy-to-use and low-cost DS1307. To make the job really easy, we'll use the the Adafruit DS1307 RTC Breakout Board Kit (http://adafru.it/264)- it comes with all the parts you need, even a coin battery! The Kit does require a little light soldering. In theory you could use all the parts and build them onto a breadboard, but the coin holder is a little difficult since its not breadboard-friendly, so please go ahead and build the kit (http://adafru.it/clq). When building the kit, leave out the 2.2KW resistors - by leaving them out, we force the RTC to communicate at 3.3V instead of 5V, which is better for the Pi! The diagrams below show the 2.2KW resistors in place - but please remove them either by not soldering them in or clipping them out if you did solder them in! This way, we'll use the Pi's 1.8K pull-up resistors to 3.3V Wiring is simple: 1. Connect VCC on the breakout board to the 5.0V pin of the Pi 2. Connect GND on the breakout board to the GND pin of the Pi 3. Connect SDA on the breakout board to the SDA pin of the Pi 4. Connect SCL on the breakout board to the SCL pin of the Pi DONT FORGET TO POWER IT FROM 5V - THIS IS FINE AND SAFE FOR THE PI - JUST MAKE SURE TO REMOVE THE 2.2K PULLUPS AS MENTIONED IN THE LARGE RED BOX UP ABOVE TO KEEP THE I2C PINS AT 3.3V LOGIC LEVELS Adafruit Industries https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi Page 5 of 11

Set up I2C on your Pi You'll also need to set up i2c on your Pi, to do so, check out our tutorial on Raspberry Pi i2c setup and testing at http://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuringi2c (http://adafru.it/ati) Reboot once you've done that with sudo reboot Verify Wiring (I2C scan) Verify your wiring by running sudo i2cdetect -y 1 at the command line, you should see ID #68 show up - that's the address of the DS1307! If you have an older Pi 1, you will have to run sudo i2cdetect -y 0 as the I2C bus address changed from 0 to 1 Adafruit Industries https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi Page 6 of 11

Once you have the Kernel driver running, i2cdetect will skip over 0x68 and display UU instead, this means its working! Adafruit Industries https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi Page 7 of 11

Set RTC Time Now that we have the module wired up and verified that you can see the module with i2cdetect, we can set up the module. First, load up the RTC module by running sudo modprobe i2c-bcm2708 sudo modprobe i2c-dev sudo modprobe rtc-ds1307 Then, as root (type in sudo bash) run echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device If you happen to have an old Rev 1 Pi, type in echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device You can then type in exit to drop out of the root shell. Then check the time with sudo hwclock -r which will read the time from the DS1307 module. If this is the first time the module has been used, it will report back Jan 1 2000, and you'll need to set the time First you'll need to get the right time set on the Pi, the easiest way is to connect it up to Ethernet or Wifi - it will automatically set the time from the network. Once the time is correct (check with the date command), run sudo hwclock -w to write the system time to the RTC You can then verify it with sudo hwclock -r Adafruit Industries https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi Page 8 of 11

Next, you'll want to add the RTC kernel module to the /etc/modules list, so its loaded when the machine boots. Run sudo nano /etc/modules and add rtc-ds1307 at the end of the file (the image below says rtc-1307 but its a typo) Raspbian Jessie (Systemd) Thanks to kd8twg for the hints! (http://adafru.it/ne3) Start by editing a new service configuration sudo nano /etc/conf.d/rtc-i2c And paste in the following, then save: # /etc/conf.d/rtc-i2c Adafruit Industries https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi Page 9 of 11

CHIP="ds1307" ADDRESS="0x68" BUS="1" Now create a new service file that will start/stop the real time clock manager sudo nano /lib/systemd/system/rtc-i2c.service # /lib/systemd/system/rtc-i2c.service [Unit] Description=Initialize i2c hardware RTC device driver DefaultDependencies=no Requires=systemd-modules-load.service After=systemd-modules-load.service Before=sysvinit.target ConditionPathExists=/sys/class/i2c-adapter Conflicts=shutdown.target [Service] Type=oneshot RemainAfterExit=yes EnvironmentFile=/etc/conf.d/rtc-i2c ExecStart=/bin/sh -c "echo ${CHIP} ${ADDRESS} > /sys/class/i2c-adapter/i2c-${bus}/new_device" [Install] WantedBy=sysinit.target Enable the new service, so that it will always start with the Pi when it boots! sudo systemctl enable rtc-i2c.service And disable the fake hwclock which interferes with the 'real' hwclock sudo apt-get remove fake-hwclock sudo update-rc.d -f fake-hwclock remove That's it! Next time you boot the time will automatically be synced from the RTC module Raspbian Wheezy or other pre-systemd Linux Older pre-jessie raspbian is a little different. First up, you'll want to create the DS1307 device creation at boot, edit /etc/rc.local by running sudo nano /etc/rc.local and add: Adafruit Industries https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi Page 10 of 11

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device (for v1 raspberry pi) echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device (for v2 raspberry pi) sudo hwclock -s (both versions) before exit 0 (we forgot the hwclock -s part in the screenshot below) That's it! Next time you boot the time will automatically be synced from the RTC module Adafruit Industries Last Updated: 2016-04-29 11:45:11 PM EDT Page 11 of 11