mattytrentini / micropython-mcp7940 Goto Github PK
View Code? Open in Web Editor NEWA MicroPython driver for the Microchip MCP7940 RTC chip
License: MIT License
A MicroPython driver for the Microchip MCP7940 RTC chip
License: MIT License
The MCP7940 has 64 bytes of onboard storage that is retained when the RTC is powered by a battery.
Seems like this would be best implemented with a slice operator:
mcp.data[0:10] = range(10) # Set first ten bytes to 1..10
fourth = mcp.data[4] # Read fourth byte
The MCP supports calibration of the oscillator. We need to expose the fields to allow the calibration to occur.
Although there's an is_leap_year
function - and it's been tested - it's not currently used.
It should be used when setting the time on the MCP so the RTC knows how to increment time as it rolls through February.
Hi, I created a fork of your repo (by using the tinyPICO fork of it that is).
Beside the fact that the file mcp7940.py
has an is_leap_year
function, I see that this function is only mentioned in the commentary but nowhere called from inside the class. Since I decided to use the is_leap_year
function, which I needed for an added yearday
function, I discovered that the function defintion of the is_leap_year
function has no self
defined as first parameter, like I did:
def is_leap_year(self, year):
Without self
the function could be called with e.g.: MCP7940.is_leap_year(current_year)
I see that you did this also with the functions bcd_to_int(bcd):
and def int_to_bcd(i):
and call these from within the same class with t = [(MCP7940.int_to_bcd(reg) & filt) for reg, filt in zip(time_reg, reg_filter)]
in function alarm1
.
and with t = [MCP7940.bcd_to_int(reg & filt) for reg, filt in zip(time_reg, reg_filter)]
in the function _get_time
.
Can I ask you why you have chosen to do the function calls as: MCP7940.int_to_bcd
and MCP7940.bcd_to_int
and not through self.int_to_bcd
or self.bcd_to_int
?
There are some generally useful functions that should not be contained in MCP7940
. The following functions are candidates:
is_leap_year
bcd_to_int
/int_to_bcd
_set_bit
/_read_bit
The corresponding tests should also be moved.
Since 2020 is a leap year, the leap year bit is being set in the month register and was throwing off the month returned by x20 when getting mcp7940 time. I changed the mask for that register from x3F to x1F:
def _get_time(self, start_reg = 0x00):
num_registers = 7 if start_reg == 0x00 else 6
time_reg = self._i2c.readfrom_mem(MCP7940.ADDRESS, start_reg, num_registers) # Reading too much here for alarms
# reg_filter = (0x7F, 0x7F, 0x3F, 0x07, 0x3F, 0x3F, 0xFF)[:num_registers]
# changed month mask from x3F to x1F to mask off leap year bit
reg_filter = (0x7F, 0x7F, 0x3F, 0x07, 0x3F, 0x1F, 0xFF)[:num_registers]
The MCP supports two alarms; need to add to the API.
Maybe:
mcp.alarm1.time = alarmtime # Set to None to stop alarm?
mcp.alarm.mask = # An OR'd enum here?
mcp.alarm1.time # Read alarm
mcp.alarm2.time = alarmtime2
The MCP has various output configurations that can control the MFP pin. The alarm output is the most commonly used; MFP will be modified when the alarms are raised.
However there is support to also generate a square wave or a GPIO signal if the alarm output is not configured. These features should be exposed.
Hi,
How install it on micropython ?
Sincerely
Eric
utime.localtime
includes yearday in it's representation of time.
For compatibility it would be nice to return the right yearday number. Currently 0 is returned.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.