please choosego to mobile | Continue to access the PC version
Author: gaara

RTC battery interface

[Copy link]

1

threads

14

posts

129

credits

Registered member

Rank: 2

credits
129
Published in 2016-11-30 05:06:34 | Show all floors
Edited by Orange_User at 2016-11-30 05:14
shooreg replied at 2016-2-1 17:42
It is possible to add any ds1307 (I2C intf.) real-time clock to any 2nd generation OPi  - just follo ...

This command accept without output

"echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device"

But this command
"sudo ln -f -s /dev/rtc1 /dev/rtc"


i get output: sudo not found

Also this?
hwclock not found


Android image is on the pi lite with DS3231 RTC.

DS3231=OPI wiring: GND=GND(pin6), VCC=3.3V(pin1 or 5V pin4), SDA=SDA(pin3), SCL=SCK(pin5)



Thanks.

This thread contains more resources

You need to Log in to download or view,No account?    Register

x

1

threads

64

posts

240

credits

Intermediate member

Rank: 3Rank: 3

credits
240
Published in 2016-11-30 16:00:23 | Show all floors
I guess the problem is that you are using Android image - it might work different with sysfs (i'm not sure) and it definetly misses sudo and hwclock binaries (as it seems from your output)
I used RTC module with Debian and Ubuntu images. The wiring you are using is correct (except for if you are using a chargeable battery in RTC, and you want it to charge, you shoud use 5V power (but beware of possible overcharge))

As for commands:
"echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device" tells the kernel to load and activate a corresponding kernel module (ds1307 - it is universal for several Dallas/Maxim I2C RTC chips). This module then creates a device file /dev/rtcN. On OPI based on H3 SoC it becomes /dev/rtc1 because /dev/rtc0 is already occupied by internal Soc RTC (http://linux-sunxi.org/RTC) which, unfortunately, is not battery backed up, and hence almost useless.

"sudo ln -f -s /dev/rtc1 /dev/rtc" this command forcefully modifies a symlink /dev/rtc to point to /dev/rtc1, not to /dev/rtc0 as it does after boot (because sunxi rtc module is loaded earlier). This is necessary for system to use RTC chip on module, not the one inside SoC.

hwclock is a standard linux utility for query and modification of hardware clock data. You can find a manual for it easily.

1

threads

14

posts

129

credits

Registered member

Rank: 2

credits
129
Published in 2016-12-1 01:19:28 | Show all floors
Edited by Orange_User at 2016-12-1 01:52
shooreg replied at 2016-11-30 16:00
I guess the problem is that you are using Android image - it might work different with sysfs (i'm no ...

Is it possible to run DS3231 or any other RTC to work with orange pi and android?I install busybox and get hwclock.
What is pin conectors for battery for local rtc in OPI perhaps only to restart and keeping the correct time.
I`m thinking to connect rechargeable battery if not posible to run DS3231 or same other RTC?

My output from terminal:



Thanks.
P.S.
It`s my mistake in picture, last commands is:
#su i2cdetect 0
sh: 0: not found   
#su i2cdetect 1
sh: 1: not found   
#su i2cdetect -y 0
sh: sh:  -y: unknown option   










This thread contains more resources

You need to Log in to download or view,No account?    Register

x

1

threads

64

posts

240

credits

Intermediate member

Rank: 3Rank: 3

credits
240
Published in 2016-12-1 17:07:24 | Show all floors
Edited by shooreg at 2016-12-1 12:13

In Android, after the initial su command you gain persistent root priveledges, so no need to type su again in that session. The # mark at command prompt indicates than you are root.
Now, let's see (the following is only IMHO, since I'm not an Android builder/developer):
- if your kernel has built-in rtc support (it should) then there must be a folder named /sys/class/rtc. If no such - either no rtc support or no rtc kernel drivers loaded.
- i2cdetect is a linux util, not sure there is one in android, it scans I2C bus for all devices (just to make sure that kernel I2C support is enabled and RTC device is properly connected). -y is an auto-confirm option 0 is a I2C bus number if there are several.
- inside  /sys/class/rtc there should be subfolders named like rtcN - one for each RTC device your system recognized.

So, for now questions are: does your android kernel support I2C bus, and does it recognize internal sunxi-rtc as rtc0?

What is pin conectors for battery for local rtc in OPI perhaps only to restart and keeping the correct time.

- there are no pins, but pad on the PCB, labeled rtc. However it is not a good idea to apply a battery voltage (3.3v) there - due to some schematic problems (guess) it powers not only rtc in SoC, so there are isuues with poweroff and battery drains quickly. That is, as I know, for H3 based OPI PC, OPI plus and OPI one.



1

threads

14

posts

129

credits

Registered member

Rank: 2

credits
129
Published in 2016-12-5 00:57:34 | Show all floors
Edited by Orange_User at 2016-12-5 01:04

I did a little research to find out if my rtc ds3231 correct and OPI i2c bus.
I installed on another sd card Armbian 5.20 and I have used your script and put it in init.d,
after about an hour of experimentation i was able to run  and now working on Armbian perfectly.
Well everything with hardware is ok .

- inside  /sys/class/rtc there should be subfolders named like rtcN - one for each RTC device your system recognized.

Exist: /sys/class/rtc/rtc0 In that folder is txt file "name" and inside is only one line "sunxi-rtc"

does your android kernel support I2C bus

I think but I'm not sure. There is /sys/class/i2c-adapter and /sys/class/i2c-dev and also /sys/class/i2c-dev/i2c-0

and does it recognize internal sunxi-rtc as rtc0

I dont know how to check this?

I followed the instructions on the link https://github.com/azureru/orangepipc-i2c-dev and install i2c-tools and now working command i2cdetect but not expected.
I get this output:
#insmod /i2c/i2c-dev.ko
#
#lsmod
i2c_dev 5359 0 - Live 0x00000000
.
.
.
#/i2c/tools/i2cdetect -y 0
0     1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00   -   -  -   -   -   -   -   -   -   -   -   -   -   -
10   -   -  -   -   -   -   -   -   -   -   -   -   -   -
20   -   -  -   -   -   -   -   -   -   -   -   -   -   -
30   -   -  -   -   -   -   -   -   -   -   -   -   -   -
40   -   -  -   -   -   -   -   -   -   -   -   -   -   -
50   -   -  -   -   -   -   -   -   -   -   -   -   -   -
60   -   -  -   -   -   -   -   -   -   -   -   -   -   -
70   -   -  -   -   -   -   -  

Detecting duration is about 5min, every addres 2+sec, in Armbian less then second to finish complete. Smells on timeout for every address.
I`m stack here.
Run command echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device donot make file rtc1 in /dev/, something missing but I do not know what, i do not have enough experience with Linux under the hood.

Thanks.



1

threads

64

posts

240

credits

Intermediate member

Rank: 3Rank: 3

credits
240
Published in 2016-12-12 18:42:59 | Show all floors
Have you tried #/i2c/tools/i2cdetect -y 1 ?

On Armbian when you use i2cdetect you should see something like

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   -   -  -   -   -   -   -  

The mark(it is actually a status code) at address 68 (60row+8col) is a proof of presence of DS chip (I2C address 68 is a default for DS-based RTCs). With Linux kernel on OPI there are usually  2 I2C buses (i2c-0 and i2c-1) - you specify which one to scan with the last parameter of i2cdetect. (I2C bus mappings to OPI pin header is configured by kernel/*.fex)

However, it may be different with your android kernel  - guys here https://github.com/azureru/orangepipc-i2c-dev say
These modules and utils are compiled using homlet lichee kernel source, so make sure your Android kernel is based on that source.

3

threads

8

posts

31

credits

Novice

Rank: 1

credits
31
Published in 2016-12-13 03:47:13 | Show all floors
There is NO way how to use the internal RTC battery backup. The RTC pin is directly connected to the 3,3V rail via the 0R resistor.
Even more if you remove this resistor, there is other circuitry, not only RTC powered from the RTC supply rail which consumes a lot.
The only regular way how to use the really working RTC is to use external module.
I'm using DS3231 RTC module which costs less than 1$.

1

threads

14

posts

129

credits

Registered member

Rank: 2

credits
129
Published in 2016-12-13 07:39:05 | Show all floors
Edited by Orange_User at 2016-12-13 07:41
shooreg replied at 2016-12-12 18:42
Have you tried #/i2c/tools/i2cdetect -y 1 ?

I tried but it gives me the following output:

Error: Could not open file `/dev/i2c-1` or `/dev/i2c/1`: No such file or directory



However, it may be different with your android kernel  - guys here https://github.com/azureru/orangepipc-i2c-dev say

These are information about android:
Model number: dolphin
Android version: 4.4.2
Firmware version: Homlet4.4.2-Qin2-v1.0release
Kernel version: 3.4.39 allwinner@steven #4 Tue Apr 12 05:41:39 HKT 2016
Build number: dolphin_fvd_p1_eng 4.4.2 KOT49H 20160410 test-keys

Thanks!!!

1

threads

14

posts

129

credits

Registered member

Rank: 2

credits
129
Published in 2016-12-13 07:50:13 | Show all floors
jgrulich replied at 2016-12-13 03:47
There is NO way how to use the internal RTC battery backup. The RTC pin is directly connected to the ...

I understand from previous answers that the only comfortable solution that uses an external RTC. Could not run external RTC with android. With Armbian I successfully installed and launched an external RTC DS3231. On which operating system you installed DS3231 ???

3

threads

8

posts

31

credits

Novice

Rank: 1

credits
31
Published in 2016-12-13 20:05:51 | Show all floors
I'm using this RTC module on Armbian and piCore (TinyCore). Sorry, don't have any experience with the Android.
You need to log in before you can reply login | Register

Points Rule

Quick reply Top Return list