SequentMicrosystems / megabas-rpi

Command Line, Python lib, Node-Red and CODESYS driver for Building Automation Card
https://www.sequentmicrosystems.com
MIT License
8 stars 1 forks source link

How to read/set RTC #9

Open Grandpa-G opened 2 years ago

Grandpa-G commented 2 years ago

In Python Library, I don't see any way to read or set the Real Time Clock.

Am I missing something?

alexburcea2877 commented 2 years ago

You have right, we will fix that.

Grandpa-G commented 2 years ago

Also, using the command line I did

megabas 0 rtcwr 12 21 21 09 31 00 it responded done then megabas 0 rtcrd and it returned 00/00/00 00:00:00

Am I doing this incorrectly?

alexburcea2877 commented 2 years ago

Looks like you do the right thing, let me know what is the firmware version of the card by issuing "megabas 0 board"

Grandpa-G commented 2 years ago

Firmware ver 01.01, CPU temperature 37 C, Power source 21.50 V, Raspberry 4.98 V

alexburcea2877 commented 2 years ago

Please update your card firmware, instructions here: https://github.com/SequentMicrosystems/megabas-rpi/blob/master/update/README.md Make sure no-one try to access the card during the update process.

Grandpa-G commented 2 years ago

Yeepee. That fixed it.

FYI

  1. the spring clip was very loose for the battery
  2. the megabas command help says megaind instead of megabas. Thanks.
alexburcea2877 commented 2 years ago

Thank you for the info will fix it except for the battery holder..

Grandpa-G commented 2 years ago

Thanks.

Is there an overlay to interface with the RTC? Or what is the best way to use the RTC?

alexburcea2877 commented 2 years ago

Can I ask what you mean by overlay? The only options are command line, python (soon), and NodeRed (i have to check but is duable).

Grandpa-G commented 2 years ago

the overlay is given in the config.txt file for the pi.

Here is a reference, mainly the first part. The reference talks about a specific RTC, but gives you the idea. https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi/set-rtc-time

alexburcea2877 commented 2 years ago

Thanks, I will take a look.

Grandpa-G commented 2 years ago

Did you come up with a way to have your RTC interact directly with Raspberry clock? By any chance is your RTC a DS 1307 look-alike?

alexburcea2877 commented 2 years ago

Will be nice, but frankly I do not know when I start doing it.. Bottom line is that I can not give you a timeframe for it.

Grandpa-G commented 2 years ago

I understand completely. I just don't know how to use your RTC then. Is the idea to set the Raspberry clock on every boot from the RTC vial a megabas command?

alexburcea2877 commented 2 years ago

That was the idea to read the RTC at power up when you have no internet connectivity, otherwise if you are connected to the internet you can read your time from there.

Grandpa-G commented 2 years ago

Ok, I will work with that. It just takes a bit more to know (in code) that you don't have an internet connection.

Thanks for your help.

shortyishere commented 2 years ago

Can I get this functionality added to a node-red node?

alexburcea2877 commented 2 years ago

You mean reading and setting the RTC?

Grandpa-G commented 1 year ago

It is good to set the RTC set and get are now available.

However - for rtcGet, the month is off by 1. For today, it reports the results as 2022 8 13 9 18 52

import megabas

year, month, day, hour, minute, second = rtcGet(0)

print(year, month, day, hour, minute, second)

Also, all the new I2C definitions of the address space aren't necessary. The definitions are already given at the top of the module, just without the I2C prefix.