adafruit / Adafruit_CircuitPython_INA219

circuit python driver for INA219 current sensor
MIT License
26 stars 26 forks source link

I2C - TypeError: extra keyword arguments given #12

Closed wallarug closed 5 years ago

wallarug commented 5 years ago

There seems that there is an issue in either i2c_bits.py or i2c_device.py. When I run the INA219 CircuitPython example, it errors out. The correct address has been entered as I tried with an incorrect address and I get a different error.

I downloaded the latest version of adafruit_register and put it in the lib/ folder on my CIRCUITPY drive.

REPL Output

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Traceback (most recent call last):
  File "code.py", line 10, in <module>
  File "/lib/adafruit_ina219.py", line 164, in __init__
  File "/lib/adafruit_ina219.py", line 309, in set_calibration_32V_2A
  File "/lib/adafruit_register/i2c_bits.py", line 88, in __set__
  File "/lib/adafruit_register/i2c_bits.py", line 74, in __set__
  File "adafruit_bus_device/i2c_device.py", line 147, in write_then_readinto
TypeError: extra keyword arguments given

Build Details Adafruit CircuitPython 5.0.0-alpha.4-8-gbd4282a-dirty on 2019-09-17; Robo HAT MM1 with samd51g19

Libraries https://github.com/adafruit/Adafruit_CircuitPython_BusDevice https://github.com/wallarug/Adafruit_CircuitPython_INA219

ladyada commented 5 years ago

hiya please move this issue to https://github.com/adafruit/Adafruit_CircuitPython_INA219 since it is not a core circuitpython issue but a library issue! thanx :)

dhalbert commented 5 years ago

Transferred and reopened.

ladyada commented 5 years ago

make sure you have the very latest of all libraries from the bundle

jerryneedell commented 5 years ago

FYI - I tried this on a grand_central and was not able to reproduce the error. The ina219_simpletest worked for me.


Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.

Press any key to enter the REPL. Use CTRL-D to reload.
Adafruit CircuitPython 5.0.0-alpha.4-72-g7f1bc48a8 on 2019-09-20; Adafruit Grand Central M4 Express with samd51p20
>>> import ina219_simpletest
ina219 test
Config register:
  bus_voltage_range:    0x1
  gain:                 0x3
  bus_adc_resolution:   0x3
  shunt_adc_resolution: 0x3
  mode:                 0x7

PSU Voltage:    0.868 V
Shunt Voltage: -0.000030 V
Load Voltage:   0.868 V
Current:       -0.000300 A
timvgso commented 5 years ago

I ran into this using an MCP23008 device with CircuitPython 5.0 a week or so ago and casually reported it on Discord. I still get the same problem using a Circuit Playground Express after downloading and installing adafruit-circuitpython-circuitplayground_express-en_US-5.0.0-alpha.4x.uf2 and installing the driver from adafruit-circuitpython-bundle-5.x-mpy-20190924x.zip.

>>> from adafruit_mcp230xx.mcp23008 import MCP23008
>>> i2c = busio.I2C(board.SCL, board.SDA)
>>> mcp = MCP23008(i2c)
>>> pin0 = mcp.get_pin(0)
>>> pin0.switch_to_output(value=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "adafruit_mcp230xx/digital_inout.py", line 71, in switch_to_output
  File "adafruit_mcp230xx/digital_inout.py", line 112, in direction
  File "adafruit_mcp230xx/mcp23008.py", line 76, in iodir
  File "adafruit_mcp230xx/mcp230xx.py", line 74, in _read_u8
  File "adafruit_mcp230xx/mcp230xx.py", line 73, in _read_u8
  File "adafruit_bus_device/i2c_device.py", line 147, in write_then_readinto
TypeError: extra keyword arguments given

I can work around this error as follows:

Now the five-line test above runs without error.

It appears that the i2c_device submodule of adafruit_bus_device compiled into at least some of the current CircuitPython 5.0 bundles is out of date, while the corresponding i2c_device.mpy in the library bundle (the version for memory-limited non-Express devices where adafruit_bus_device isn't compiled in) is correct.

dhalbert commented 5 years ago

@timvgso - Ah, thank you, what this means is that the frozen version of adafruit_bus_device in the CPX build needs to be updated.

timvgso commented 5 years ago

@dhalbert Yes. However I was using a PyPortal when I initially found the problem and @wallarug just found it with a SAMD51 something so the problem might also be there in some other builds.

dhalbert commented 5 years ago

The robohat_mm1_m4 that @wallarug was using does have adafruit_bus_device frozen in (https://github.com/adafruit/circuitpython/blob/7f1bc48a88b45fc98fccd3722bed1f679a70fd66/ports/atmel-samd/boards/robohatmm1_m4/mpconfigboard.mk#L25)I am not sure about your PyPortal issue, but do bring everything up to date on the PyPortal and see if it's still the case. Thanks. From the repl you can do:

>>> import adafruit_bus_device
>>> adafruit_bus_device.__version__

It should be at least 4.0.0.

timvgso commented 5 years ago
>>> import adafruit_bus_device
>>> adafruit_bus_device.__version__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '__version__'
>>> dir(adafruit_bus_device)
['__class__', '__file__', '__name__', '__path__']

I don't have the MCP23008 connected to the PyPortal and don't have time to undo and redo the jumper wires and pull-up resistors at the moment as it's on a breadboard. In any case, maybe safer to make sure that all versions are up to date and get updated as needed rather than attempt to spot-fix?

dhalbert commented 5 years ago

Ah sorry, the version line is in each file, unusually:

>>> import adafruit_bus_device.i2c_device
>>> adafruit_bus_device.i2c_device.__version__

But, yes, it should just be fixed, and I'll submit a PR to update the frozen libraries.

wallarug commented 5 years ago

Thanks @dhalbert ! I'll rebuild and check it out this afternoon. I figured as much that this was an issue with the frozen module.

dhalbert commented 5 years ago

@wallarug It's probably your worth considering whether it's worth freezing a few libraries into the board vs just uploading them. Our original motivation for using frozen libraries was mostly just to save RAM space on the CPX. It did make it be usable out of the box without loading any libraries, at the expense of making updating more trouble.

wallarug commented 5 years ago

I completely understand. The reason they are frozen into the Robo HAT MM1 files is that we kept having RAM issues using the SAMD21 - as you said.

I do like the idea of not having to put the libraries on the board separately as well.

wallarug commented 5 years ago

@dhalbert

I cleared out the frozen lib includes as you suggested and recompiled a fresh circuitpython.

I am still having issues using this repository in the lib/ folder. I downloaded the Adafruit_CircuitPython_BusDevice library from GitHub and put the extracted files into the lib folder. But end up getting this error:

Traceback (most recent call last):
  File "code.py", line 5, in <module>
  File "/lib/adafruit_ina219.py", line 47, in <module>
ImportError: cannot import name i2c_device

I also tested from the bundle released yesterday (25th Sept) and got the same error when I put the files in the lib/ folder.

It looks like someone maybe changed the name of the class from i2c_device toI2CDevice. I cannot see any i2c_device in the file anymore.

I tried to use I2CDevice in the adafruit_ina219.py file but it still errors out with what I had before about read_into_write().

After changing to I2CDevice in adafruit_ina219 library

Output

Traceback (most recent call last):
  File "code.py", line 10, in <module>
  File "/lib/adafruit_ina219.py", line 164, in __init__
  File "/lib/adafruit_ina219.py", line 309, in set_calibration_32V_2A
  File "/lib/adafruit_register/i2c_bits.py", line 88, in __set__
  File "/lib/adafruit_register/i2c_bits.py", line 74, in __set__
  File "adafruit_bus_device/i2c_device.py", line 147, in write_then_readinto
TypeError: extra keyword arguments given

There is something going on here...

Output

>>> import adafruit_bus_device.i2c_device
>>> adafruit_bus_device.i2c_device.__version__
'3.0.0'
>>> 
wallarug commented 5 years ago

@timvgso is this issue fixed for you? I am still getting it with latest updates.

I don't think it is related to this library. Only the adafruit_bus_device / adafruit_register libraries and how they communicate.

Traceback (most recent call last):
  File "code.py", line 10, in <module>
  File "/lib/adafruit_ina219.py", line 164, in __init__
  File "/lib/adafruit_ina219.py", line 309, in set_calibration_32V_2A
  File "/lib/adafruit_register/i2c_bits.py", line 88, in __set__
  File "/lib/adafruit_register/i2c_bits.py", line 74, in __set__
  File "adafruit_bus_device/i2c_device.py", line 147, in write_then_readinto
TypeError: extra keyword arguments given
timvgso commented 5 years ago

I haven't done anything with I2C lately and I didn't get a chance today to set up a testbed and check, but the "latest stable release" on circuitpython.org is still 5.0.0-alpha.4 which I was using when I saw the problem. The time stamp on that file is 2019-09-15, from before you opened this issue. Are you seeing it with one of the more recent "Absolute Newest" builds from Amazon S3?

wallarug commented 5 years ago

This issue is now officially resolved. The CPY version was the cause of the issue.