LinuxKoku
Posts: 72
Joined: Wed May 16, 2018 9:16 am
Location: France

RTC management with Raspberry PI 3

Mon Jul 16, 2018 9:15 am

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)?
Thank you all :)

DirkS
Posts: 8507
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: RTC management with Raspberry PI 3

Mon Jul 16, 2018 10:46 am

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

LinuxKoku
Posts: 72
Joined: Wed May 16, 2018 9:16 am
Location: France

Re: RTC management with Raspberry PI 3

Mon Jul 16, 2018 11:24 am

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 235 times
For the code I can not find anything else, you have something to offer me? indications to target my research?
Thank you all :)

User avatar
scruss
Posts: 1730
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: RTC management with Raspberry PI 3

Mon Jul 16, 2018 1:24 pm

As DirkS said: pyb is a MicroPython thing. It's different from the Python that typically runs on a Raspberry Pi.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

LinuxKoku
Posts: 72
Joined: Wed May 16, 2018 9:16 am
Location: France

Re: RTC management with Raspberry PI 3

Mon Jul 16, 2018 1:32 pm

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?
Thank you all :)

DirkS
Posts: 8507
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: RTC management with Raspberry PI 3

Mon Jul 16, 2018 1:35 pm

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.

ericcooper
Posts: 103
Joined: Sat Apr 08, 2017 6:23 pm

Re: RTC management with Raspberry PI 3

Mon Jul 16, 2018 3:52 pm

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.

LinuxKoku
Posts: 72
Joined: Wed May 16, 2018 9:16 am
Location: France

Re: RTC management with Raspberry PI 3

Tue Jul 17, 2018 7:05 am

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
Thank you all :)

Return to “Python”

Who is online

Users browsing this forum: No registered users and 2 guests