r/MicroPythonDev • u/Maleficent_Today_780 • Feb 28 '24
how can I extend machine.I2C?
I'm trying to extend the machine.I2C class but I'm having problems with calling super().__init__ in my new class... I get an error every time that the function doesn't support
code:
import time
import struct
from machine import I2C, Pin
class SC18IS602(I2C):
def __init__(self, *args, **kargs):
super().__init__( *args, **kargs)
i2c = SC18IS602(id=0,scl=Pin(7), sda=Pin(8))I get the following error:
>>> %Run -c $EDITOR_CONTENT
MPY: soft reboot
Traceback (most recent call last):
File "<stdin>", line 10, in <module>
File "<stdin>", line 8, in __init__
TypeError: function doesn't take keyword arguments
>>>
1
Upvotes
View all comments
Show parent comment
1
u/[deleted] Feb 29 '24
My bad - see what you mean :-)
I think (and could be 100% wrong):
The **kwargs passes everything as a dictionary with the variable name and its value but the *args take a reference to the initial object that could be a hardware address and that could not be accessed via the dictionary value. This would also stop duplicating variables so saving memory space.
Passing by reference is detailed https://realpython.com/python-pass-by-reference/
As it's 03:20 ish here I think that's the best I can do at the mo...