rapidograf
Posts: 279
Joined: Sat Mar 22, 2014 11:03 am
Location: very near from here

how read data from DS3231

Sat Apr 25, 2015 10:35 am

Dear Sirs

Colud you are please give good sampleas how read data from the RTC DS3231,
i check the connection by the sudo i2cdetect –y 1 device is in I2C map.

But how read tada i can not understand, when i reda followings topics i totally have to confusion and missunderstanding ....
where get driver
insatll
read and etc :roll: :shock:

I already red following topics.
viewtopic.php?f=44&t=99141&p=690492&hil ... 31#p690492
viewtopic.php?f=44&t=98318
viewtopic.php?f=46&t=104328&p=720666&hi ... 31#p720666

:?: :arrow: :idea:
bigest and hugest same as tiny and micro

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: how read data from DS3231

Sat Apr 25, 2015 10:46 am

Greetings, I understand. Reading the i2c bus is very confusing for everyone; do not feel like you're alone on that one!

How you read i2c bus depends on the interface you are using (do you have an i2c block?) and whether you are using a library (like mraa, or other) or whether you are writing your own library...

Typically you need to know what address your slave device is on... your i2cdetect command will tell you this... if the device is working it will show up as a device with a specific hex address, like 0x48 for instance.

To read from an i2c address you need to tell the bus what address you are going to read|write. Then, you need perhaps to write a configuration data stream to the configuration register (not always required). Then, you need to write to the register you are going to read from ( some commands in the mraa library do that for you ). Then you need to read the register data into your app with <whatever> read command in your library.

That is the simplest high level I can give you. Some people (like me) have to read the i2c tutorials *many* times before they (me) have an understanding to use the bus... it really is simple, but at first seems very very confusing... keep persisting persevering and don't give up... it will be a rewarding journey, especially since most interesting sensors are i2c !
marcus
:ugeek:

rapidograf
Posts: 279
Joined: Sat Mar 22, 2014 11:03 am
Location: very near from here

Re: how read data from DS3231

Sat Apr 25, 2015 11:06 am

MarkHaysHarris777 wrote:Greetings, I understand. Reading the i2c bus is very confusing for everyone; do not feel like you're alone on that one!

How you read i2c bus depends on the interface you are using (do you have an i2c block?) and whether you are using a library (like mraa, or other) or whether you are writing your own library...

Typically you need to know what address your slave device is on... your i2cdetect command will tell you this... if the device is working it will show up as a device with a specific hex address, like 0x48 for instance.

To read from an i2c address you need to tell the bus what address you are going to read|write. Then, you need perhaps to write a configuration data stream to the configuration register (not always required). Then, you need to write to the register you are going to read from ( some commands in the mraa library do that for you ). Then you need to read the register data into your app with <whatever> read command in your library.

That is the simplest high level I can give you. Some people (like me) have to read the i2c tutorials *many* times before they (me) have an understanding to use the bus... it really is simple, but at first seems very very confusing... keep persisting persevering and don't give up... it will be a rewarding journey, especially since most interesting sensors are i2c !
you are right.
i know address of device DS3231 .

but how read dtata and convert it to the understandable data .
bigest and hugest same as tiny and micro

User avatar
DougieLawson
Posts: 36150
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: how read data from DS3231

Sat Apr 25, 2015 11:07 am

Add this

Code: Select all

dtoverlay=i2c-rtc,ds3231
to /boot/config.txt reboot and use hwclock to read/write your RTC.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: how read data from DS3231

Sat Apr 25, 2015 11:16 am

... you can try Dougie's config.txt entry... I know I'm going to !

... but if you want to read the data yourself you're going to have to get into the spec sheet on the RTC and understand how its config register works, and how its data registers work; whether they are little-endian or big-endian and whether the data comes back as bytes or string and how your codes will need to convert or translate, if even.

Have you done a google search?
marcus
:ugeek:

rapidograf
Posts: 279
Joined: Sat Mar 22, 2014 11:03 am
Location: very near from here

Re: how read data from DS3231

Sat Apr 25, 2015 11:23 am

DougieLawson wrote:Add this

Code: Select all

dtoverlay=i2c-rtc,ds3231
to /boot/config.txt reboot and use hwclock to read/write your RTC.
Thank you .
and what next i have to do ?
may be you know ample on python for this case ?

and how i turn off internet clock Raspi ?
bigest and hugest same as tiny and micro

User avatar
DougieLawson
Posts: 36150
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: how read data from DS3231

Sat Apr 25, 2015 11:56 am

To read the RTC use sudo hwclock -r, to set the RTC use sudo hwclock -w, to find out what else you can do with the RTC use hwclock -h.

To disable NTP use sudo update-rc.d ntp disable be aware that the date will revert to 00:00:00 01/01/1970 if the system can't read a valid time from the RTC. Strange things happen when your system does that.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

rapidograf
Posts: 279
Joined: Sat Mar 22, 2014 11:03 am
Location: very near from here

Re: how read data from DS3231

Sat Apr 25, 2015 3:26 pm

DougieLawson wrote:To read the RTC use sudo hwclock -r, to set the RTC use sudo hwclock -w, to find out what else you can do with the RTC use hwclock -h.

To disable NTP use sudo update-rc.d ntp disable be aware that the date will revert to 00:00:00 01/01/1970 if the system can't read a valid time from the RTC. Strange things happen when your system does that.
WOW !!!! thank you .
step by step caveman will have fire and wire ;-)
bigest and hugest same as tiny and micro

rapidograf
Posts: 279
Joined: Sat Mar 22, 2014 11:03 am
Location: very near from here

Re: how read data from DS3231

Sat Apr 25, 2015 3:37 pm

DougieLawson wrote:To read the RTC use sudo hwclock -r, to set the RTC use sudo hwclock -w, to find out what else you can do with the RTC use hwclock -h.

To disable NTP use sudo update-rc.d ntp disable be aware that the date will revert to 00:00:00 01/01/1970 if the system can't read a valid time from the RTC. Strange things happen when your system does that.
Sorry.
may be you know sample how directly read data from memory sells of DS3231 ?
bigest and hugest same as tiny and micro

rapidograf
Posts: 279
Joined: Sat Mar 22, 2014 11:03 am
Location: very near from here

Re: how read data from DS3231

Sat Apr 25, 2015 3:53 pm

rapidograf wrote:
DougieLawson wrote:Add this

Code: Select all

dtoverlay=i2c-rtc,ds3231
to /boot/config.txt reboot and use hwclock to read/write your RTC.
i added it . but sudo hwclock -h
return only this

pi@raspberrypi ~ $ sudo hwclock -r
hwclock: Cannot access the Hardware Clock via any known method.
hwclock: Use the --debug option to see the details of our search for an access method.



pi@raspberrypi ~ $ hwclock -r
hwclock: Cannot access the Hardware Clock via any known method.
hwclock: Use the --debug option to see the details of our search for an access method.
bigest and hugest same as tiny and micro

User avatar
DougieLawson
Posts: 36150
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: how read data from DS3231

Sat Apr 25, 2015 8:18 pm

rapidograf wrote:may be you know sample how directly read data from memory sells of DS3231 ?
I'd have to read the source code for hwclock, and the ds3231 kernel driver.

Or read a datasheet for the RTC chip. There'll be a bunch of I2C commands needed and data returned from a bunch of I2C registers. It's usually trivial to do that stuff having read the datasheet.

Kernel driver is: https://github.com/raspberrypi/linux/bl ... c-ds1307.c
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

rapidograf
Posts: 279
Joined: Sat Mar 22, 2014 11:03 am
Location: very near from here

Re: how read data from DS3231

Sat Apr 25, 2015 8:45 pm

DougieLawson wrote:
rapidograf wrote:may be you know sample how directly read data from memory sells of DS3231 ?
I'd have to read the source code for hwclock, and the ds3231 kernel driver.

Or read a datasheet for the RTC chip. There'll be a bunch of I2C commands needed and data returned from a bunch of I2C registers. It's usually trivial to do that stuff having read the datasheet.

Kernel driver is: https://github.com/raspberrypi/linux/bl ... c-ds1307.c
mmmm . sorry/ how install kernell driver i open your link but didnot found any hints how dod it :?
bigest and hugest same as tiny and micro

User avatar
DougieLawson
Posts: 36150
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: how read data from DS3231

Sat Apr 25, 2015 9:08 pm

Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

rapidograf
Posts: 279
Joined: Sat Mar 22, 2014 11:03 am
Location: very near from here

Re: how read data from DS3231

Sun Apr 26, 2015 5:14 am

DougieLawson wrote:Read the datasheet http://datasheets.maximintegrated.com/en/ds/DS3231.pdf
thank you for datasheet .

but anyway , how install which link you gave to me - Kernel driver is: https://github.com/raspberrypi/linux/bl ... c-ds1307.c :?
bigest and hugest same as tiny and micro

rapidograf
Posts: 279
Joined: Sat Mar 22, 2014 11:03 am
Location: very near from here

Re: how read data from DS3231

Sun Apr 26, 2015 7:02 am

Last summary.

DS3231 is found by the sudo i2cdetect -y 1 . return 0x68
from registers od DS 3231 i can read data
Seconds 00h= 0b1010100
Minutes 01h= 0b110101
Hours 02h= 0b101
Day of week 03h= 0b1
Date 04h= 0b1
Month 05h= 0b1
Year 06h= 0b0

registered 0x00 , 0x01 , 0x2 changed in time , registered 0x03, 0x04, 0x05 , 0x06 not changed in time.

====================================

As adviced Mr Lawson
i add into /boot/config.txt to last lines dtoverlay=i2c-rtc,ds3231 save and reboot.

after reboot i tried use the sudo hwclock -r , this command returned only
hwclock: Cannot access the Hardware Clock via any known method.
hwclock: Use the --debug option to see the details of our search for an access method.
===================================================================

by the easy googling i found only advices as connect RTC to kernel before the 2015 , but as you know new version of kernell has totally another methods for run RTC
===================================================================

Of course i give something wrong or miss very small but important step .
somebody help :?

P\S =>
pi@raspberrypi ~ $ sudo hwclock --debug
hwclock from util-linux 2.20.1
hwclock: Open of /dev/rtc failed: No such file or directory
No usable clock interface found.
hwclock: Cannot access the Hardware Clock via any known method.
pi@raspberrypi ~ $
bigest and hugest same as tiny and micro

rapidograf
Posts: 279
Joined: Sat Mar 22, 2014 11:03 am
Location: very near from here

Re: how read data from DS3231

Sun Apr 26, 2015 7:38 am

by the Sheakespire's monkey method i setup the RTC and hwclock .
but immidiately i had another problem , i cnat read data from RTC by the i2c registers !!!!

how i can turn off the RTC , that i can use i2c reading from DS 3231 ;-)

yeas -yes i know that you begin thhink ;-)
bigest and hugest same as tiny and micro

User avatar
DougieLawson
Posts: 36150
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: how read data from DS3231

Sun Apr 26, 2015 7:46 am

sudo apt-get update && sudo apt-get dist-upgrade should get you a kernel with the DT support you need to run with a config.txt entry. Also are you updating the right config.txt? Hold [SHIFT] during boot and use the NOOBS recovery editor.

If the kernel module works you'll get

Code: Select all

pi@apollo:~$ sudo i2cdetect -y 1
[sudo] password for pi:
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
pi@apollo:~$
from an i2cdetect command.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

rapidograf
Posts: 279
Joined: Sat Mar 22, 2014 11:03 am
Location: very near from here

Re: how read data from DS3231

Sun Apr 26, 2015 8:04 am

DougieLawson wrote:sudo apt-get update && sudo apt-get dist-upgrade should get you a kernel with the DT support you need to run with a config.txt entry. Also are you updating the right config.txt? Hold [SHIFT] during boot and use the NOOBS recovery editor.
.
Thank you Mr. Lavson

i alreadu unconnect RTC DS 3231 from autoboot and now i can use time from internet and time from registers of DS3231 separately .
i can directly read data from registers and recalculate to understandable data.
Why reason ? because i did not found how make parsing for the hwclock -r returned data ;) i'm not so deep programmer for this case.
bigest and hugest same as tiny and micro

User avatar
DougieLawson
Posts: 36150
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: how read data from DS3231

Wed Jul 15, 2015 3:03 pm

supra wrote:Do I hafta to added this if I'm using SwitchDoc Lab's code? :?: :?: :?:
No idea, ask the code maintainer.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
sommersoft
Posts: 35
Joined: Sat Jul 11, 2015 1:43 pm
Location: Delaware, US

Re: how read data from DS3231

Thu Jul 16, 2015 1:13 am

Obsolete post is obsolete.
Last edited by sommersoft on Thu Jul 16, 2015 9:47 pm, edited 1 time in total.
"We mock what we don't understand." - Dr. Trowbridge

User avatar
DougieLawson
Posts: 36150
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: how read data from DS3231

Thu Jul 16, 2015 10:43 am

That document is out of date. The device tree support in the kernel supersedes that.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
sommersoft
Posts: 35
Joined: Sat Jul 11, 2015 1:43 pm
Location: Delaware, US

Re: how read data from DS3231

Thu Jul 16, 2015 2:19 pm

:arrow:
Last edited by sommersoft on Thu Jul 16, 2015 9:47 pm, edited 1 time in total.
"We mock what we don't understand." - Dr. Trowbridge

User avatar
DougieLawson
Posts: 36150
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: how read data from DS3231

Thu Jul 16, 2015 6:12 pm

sommersoft wrote:
DougieLawson wrote:
That document is out of date. The device tree support in the kernel supersedes that.
Oddly enough, it worked flawlessly for me a few days ago...
But the device tree stuff is 1000 times easier.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
sommersoft
Posts: 35
Joined: Sat Jul 11, 2015 1:43 pm
Location: Delaware, US

Re: how read data from DS3231

Thu Jul 16, 2015 9:50 pm

DougieLawson wrote:But the device tree stuff is 1000 times easier.
Copy.
"We mock what we don't understand." - Dr. Trowbridge

baconater
Posts: 2
Joined: Fri Mar 04, 2016 5:32 am

Re: how read data from DS3231

Thu Mar 17, 2016 11:54 pm

Try this in the command line:

Code: Select all

sudo apt-get install i2c-tools
sudo i2cdetect -y 1
sudo nano /etc/modules
Now add "snd-bcm2835", "i2c-bcm2835", "i2c-dev", and "rtc-ds1307" to the bottom if it isn't there already.

Code: Select all

sudo reboot
Plug in your RTC.

After your pi reboots, use

Code: Select all

sudo i2cdetect -y 1
The RTC should show up as "UU". If it doesn't, try plugging VCC to 5v instead of 3.3v.

To read the time on the RTC, try

Code: Select all

sudo hwclock -r
.
To set the time on the RTC, first you need to set the time on the Raspberry Pi. Then, use

Code: Select all

sudo hwclock -w
to write the Raspberry Pi's time to the RTC.

If all that doesn't work, then try reading this guide:
http://www.raspberrypi-spy.co.uk/2015/0 ... pberry-pi/

Return to “Interfacing (DSI, CSI, I2C, etc.)”