Page 1 of 1

RTC management with Raspberry PI 3

Posted: Mon Jul 16, 2018 9:15 am
by LinuxKoku
Hello,

I own a Raspberry PI 3, and I would like to use the real-time clock (https://www.microchip.com/wwwproducts/e ... l-features), which is connected on the i2c. I started by setting up RTC and I can get the date by typing date on Terminal:

Code: Select all

[email protected]:~ $ date
lundi 16 juillet 2018, 11:03:52 (UTC+0200)
Now I want to use alarms RTC, but I not find how! I looked on the internet and I came across this code for the use of RTC:

Code: Select all

import pyb
import time


rtc=pyb.RTC() # create object RTC

print (rtc.datetime()) # (year, month, day, weekday, hours, minutes, seconds, subseconds)

#rtc.datetime((2017,9,22,4,18,39,4,0))
#print(rtc.datetime())

while True :
    print (str(rtc.datetime()[4]),':',str(rtc.datetime()[5]),':',str(rtc.datetime()[6]))) #  hh:mm:ss 
    pyb.delay(1000)
But it shows me an error that says: no module named 'pyb'


:?: Do I have to install something for python to recognize 'pyb' or am I on the wrong path? indications (for the use of RTC)?

Re: RTC management with Raspberry PI 3

Posted: Mon Jul 16, 2018 10:46 am
by DirkS
LinuxKoku wrote:
Mon Jul 16, 2018 9:15 am
I started by setting up RTC
How?
I can get the date by typing date on Terminal:

Code: Select all

[email protected]:~ $ date
lundi 16 juillet 2018, 11:03:52 (UTC+0200)
That's the normal date output, you can't see if an RTC is installed and working.
Try

Code: Select all

timedatectl
But it shows me an error that says: no module named 'pyb'


:?: Do I have to install something for python to recognize 'pyb' or am I on the wrong path? indications (for the use of RTC)?
Where did you find the code? The only pyb related stuff I see is micropython code for the pyboard

Re: RTC management with Raspberry PI 3

Posted: Mon Jul 16, 2018 11:24 am
by LinuxKoku
With the command: ls -l /dev we can also see that RTC is configured (I connected it on GPIO2/SDA and GPIO3/SCL), otherwise I followed a tutorial to install it, and I think it is well installed.
rtc.png
rtc.png (6.83 KiB) Viewed 596 times
For the code I can not find anything else, you have something to offer me? indications to target my research?

Re: RTC management with Raspberry PI 3

Posted: Mon Jul 16, 2018 1:24 pm
by scruss
As DirkS said: pyb is a MicroPython thing. It's different from the Python that typically runs on a Raspberry Pi.

Re: RTC management with Raspberry PI 3

Posted: Mon Jul 16, 2018 1:32 pm
by LinuxKoku
Hello, thank you for your answer,

I understood what he told me, now I'm looking for examples of codes that could work on Raspberry PI? Do you have any indications?

Re: RTC management with Raspberry PI 3

Posted: Mon Jul 16, 2018 1:35 pm
by DirkS
LinuxKoku wrote:
Mon Jul 16, 2018 1:32 pm
I understood what he told me, now I'm looking for examples of codes that could work on Raspberry PI? Do you have any indications?
Try googling for 'MCP79410 alarm python'. I did see some code, but it's mostly C I think

BTW: I still would have a look with timedatectl. Seeing the /dev/rtc is no guarantee it's actually working.

Re: RTC management with Raspberry PI 3

Posted: Mon Jul 16, 2018 3:52 pm
by ericcooper
You can check dmesg output to make sure the kernel is detecting the RTC and loading the right driver (also look for it in the output of "lsmod"). But the presence of /dev/rtc0 means it probably is OK.

You can use the "hwclock" command to read and set the RTC time. See "man hwclock". And you can use the "rtcwake" command to manage wake alarms, if the RTC driver supports it.

Re: RTC management with Raspberry PI 3

Posted: Tue Jul 17, 2018 7:05 am
by LinuxKoku
Hello,
I'm going to look at all this closely. Doing my research on MCP79410 alarm python I came across a lot of codes, thank you