WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: setting up DS3231 RTC on piCore  (Read 9127 times)

Offline foxsam

  • Newbie
  • *
  • Posts: 12
setting up DS3231 RTC on piCore
« on: October 21, 2014, 11:30:04 PM »
I have this rtc module and need help setting it up. I tried taking 'nortc' out from cmdline.txt but it just hangs. I tried following instructions from that site but could not adapt them to picore.
Any help is apreciated.
thanks

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: setting up DS3231 RTC on piCore
« Reply #1 on: October 22, 2014, 01:23:31 AM »
Did you install the rtc kernel modules extensions? If not load rtc-3....tcz fitting your vesions.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline foxsam

  • Newbie
  • *
  • Posts: 12
Re: setting up DS3231 RTC on piCore
« Reply #2 on: October 22, 2014, 03:12:37 PM »
I installed rtc-3.16.3-piCore+ by running tce and searching for rtc and installed it. Does that mean it loaded? When i remove nortc from cmdline.txt it hangs by "setting language to c " in the boot process.
Code: [Select]
tc@piCorePlayer:~$ uname -a
Linux piCorePlayer 3.16.3-piCore+ #1 PREEMPT Sun Sep 21 20:27:08 CEST 2014 armv6l GNU/Linux
I have a b+ if that changes anything.

Thanks.

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: setting up DS3231 RTC on piCore
« Reply #3 on: October 22, 2014, 03:20:35 PM »
Unfortunately I do not have such RTC. Do not remove NORTC from the command line. When system is running, check RTC whether it is seen as an I2C device and works as expected. Then we can proceed if hw itself verified to work.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline foxsam

  • Newbie
  • *
  • Posts: 12
Re: setting up DS3231 RTC on piCore
« Reply #4 on: October 22, 2014, 03:33:06 PM »
I tried searching before but I can't find how to check if it is working. when I do hwclock i get an error:
Code: [Select]
tc@piCorePlayer:~$ hwclock
hwclock: can't open '/dev/misc/rtc': No such file or directory
Thanks again

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: setting up DS3231 RTC on piCore
« Reply #5 on: October 22, 2014, 03:37:11 PM »
try

Code: [Select]
sudo hwclock
You can check it with ls command or mc too

i2c-tools package can be used to check chip itself on the bus and the bus itself to be sure the hw layer is ok.
« Last Edit: October 22, 2014, 03:40:00 PM by bmarkus »
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline foxsam

  • Newbie
  • *
  • Posts: 12
Re: setting up DS3231 RTC on piCore
« Reply #6 on: October 22, 2014, 03:43:23 PM »
hwclock is same error with sudo
Quote
tc@piCorePlayer:~$ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Offline foxsam

  • Newbie
  • *
  • Posts: 12
Re: setting up DS3231 RTC on piCore
« Reply #7 on: October 22, 2014, 03:57:00 PM »
and if this adds anything.
Code: [Select]
tc@piCorePlayer:~$ ls -l /sys/bus/i2c/devices/i2c-*
lrwxrwxrwx    1 root     root             0 Dec 31  1969 /sys/bus/i2c/devices/i2c-0 -> ../../../devices/platform/bcm2708_i2c.0/i2c-0/
lrwxrwxrwx    1 root     root             0 Dec 31  1969 /sys/bus/i2c/devices/i2c-1 -> ../../../devices/platform/bcm2708_i2c.1/i2c-1/

Offline foxsam

  • Newbie
  • *
  • Posts: 12
Re: setting up DS3231 RTC on piCore
« Reply #8 on: October 22, 2014, 04:12:35 PM »
It works!
Code: [Select]
tc@piCorePlayer:~$ sudo modprobe i2c-bcm2708
tc@piCorePlayer:~$ echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-1/new_device
ds1307 0x68
tc@piCorePlayer:~$ sudo hwclock
Sat Jan  1 01:16:18 2000  0.000000 seconds
I am going to reboot and make sure I am clear about what I did but it definitely works.

p.s. If you can help me figure out what files i need to change and backup so that it is persistent that would be great.

Thanks alot.

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: setting up DS3231 RTC on piCore
« Reply #9 on: October 22, 2014, 04:36:30 PM »
Easiest thing is to put all commands you are typing to get it up and sync system clock to hw clock to /opt/bootlocal.sh which is executed during startup as root so no need for sudo.

Of course you must backup it with

Code: [Select]
filetool.sh -b
or using TC GUI tool to make it permanent to survive reboot.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: setting up DS3231 RTC on piCore
« Reply #10 on: October 22, 2014, 04:48:03 PM »
BTW do you know your RTC chip has a 0.25C resolution temperature sensor?
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline foxsam

  • Newbie
  • *
  • Posts: 12
Re: setting up DS3231 RTC on piCore
« Reply #11 on: October 22, 2014, 05:34:19 PM »
BTW do you know your RTC chip has a 0.25C resolution temperature sensor?
no. But I am very happy to hear as I was going to look into a temp sensor next. This is good news.

I am not sure how to read from the device tho. I am getting errors if I run 
Code: [Select]
echo ds3231 0x68 | sudo tee /sys/class/i2c-adapter/i2c-1/new_device before I try to read.
Code: [Select]
tc@piCorePlayer:~$ sudo i2cget 1 0x68 0x12
Error: Could not set address to 0x68: Device or resource busy
If I do it before running the echo command it works.

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: setting up DS3231 RTC on piCore
« Reply #12 on: October 23, 2014, 03:09:54 AM »
To get temperature you must read two registers of the RTC chip via I2C commands. Google for sample programs and read datasheet of the chip which registers for temp and how to read them. This article may help:

http://www.instructables.com/id/Raspberry-Pi-I2C-Python/

It is for Raspbian so modul initialization is different. Also smbus Python module is missing in the repo, I will add it.

For sure you will find plenty of ways to handle I2C
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: setting up DS3231 RTC on piCore
« Reply #13 on: October 23, 2014, 06:28:08 AM »
py-smbus.tcz added to repo. Install it and you can use Python

Code: [Select]
import smbus
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline Benicz

  • Newbie
  • *
  • Posts: 2
Re: setting up DS3231 RTC on piCore
« Reply #14 on: April 25, 2017, 02:32:21 PM »
Hi!

I'm trying to use i2c as well on my pi3 - no luck so far :-/

read "Enabling i2C under 8.0beta3" aswell, but it also doesn't succeed.
maybe somethong else is wrong...?
no /dev/i2c

I was trying to install py-smbus.tcz, but i can't find it. has it been removed?
do i need the dev version of i2c-tools?

thanks!