Hi,
MicroPython v1.8.5-75-g6a2c609 on 2016-10-29; PYBv1.0 with STM32F405RG
Type "help()" for more information.
>>> from machine import I2C
>>> i2c = I2C(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'sda' argument required
What I do wrong?
i2c init problem
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: i2c init problem
The machine.i2c module is poorly documented, notably the constructor which is undocumented for the Pyboard. It requires two arguments, both Pin objects, the first scl being the clock pin, and the second sda being the data pin.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 363
- Joined: Sun Apr 17, 2016 1:55 pm
Re: i2c init problem
inaugurator wrote:Hi,
MicroPython v1.8.5-75-g6a2c609 on 2016-10-29; PYBv1.0 with STM32F405RG
Type "help()" for more information.
>>> from machine import I2C
>>> i2c = I2C(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'sda' argument required
What I do wrong?
I2C usage is different between module machine and pyb.
if you using pyb, you may using like this
>>> from machine import I2C
>>> i2c = I2C(1)
but if using machine, you may using like below:
>>> from machine import I2C, Pin
>>> i2c=I2C(sda=Pin('B7'),scl=Pin('B6'))
-
- Posts: 23
- Joined: Tue Sep 30, 2014 4:02 pm
Re: i2c init problem
[quote="shaoziyang"][quote="inaugurator"]
>>> i2c=I2C(sda=Pin('B7'),scl=Pin('B6'))[/quote]
Shouldn't scl be the first parameter and sda the second?
http://docs.micropython.org/en/latest/p ... achine.I2C
>>> i2c=I2C(sda=Pin('B7'),scl=Pin('B6'))[/quote]
Shouldn't scl be the first parameter and sda the second?
http://docs.micropython.org/en/latest/p ... achine.I2C
Re: i2c init problem
When you use keyword arguments, the order of the arguments doesn't matter. For postional arguments (i.e. non-keyword arguments), then the order is important.
See this post for the different ways to construct an I2C object on the pyboard using the machine module.
See this post for the different ways to construct an I2C object on the pyboard using the machine module.
Re: i2c init problem
That make sense now. Thanks Dave for the clarification!