Code: Select all
>>> i2c.scan()
[60]
1) Should i use I2C from the pyb library or machine library? Which is correct and best way?
Python rule 13 -There should be one-- and preferably only one --obvious way to do it.
2) From the machine library here (http://docs.micropython.org/en/latest/l ... e.I2C.html) it says that the class is constructed like this: class machine.I2C(id=-1, *, scl, sda, freq=400000)
Does this mean that we have 2 key words that are defaulted if you don't provide them which are id and freq? So you can construct the object by just providing the scl and sda arguments right? And those arguments have to be pin objects specifying the pin to use? So why does this work:
Code: Select all
>>> import machine
>>> i2c = machine.I2C('X')
>>> i2c.scan()
[60]
3) If I try and create an I2C object and provide it with the correct values it does not seem to work for me, maybe someone can spot my school boy error!!!! ....
Code: Select all
>>> i2c = I2C(id=-1, scl=machine.Pin(9), sda=machine.Pin(10), freq=400000)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't convert 'int' object to str implicitly
So from here: ( http://docs.micropython.org/en/latest/l ... e.Pin.html)
It says:
Code: Select all
from machine import Pin
# create an output pin on pin #0
p0 = Pin(0, Pin.OUT)
Code: Select all
>>> i2c = I2C(id=-1, scl=machine.Pin('X9'), sda=machine.Pin('X10'), freq=400000)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: extra keyword arguments given
4) I'm guessing this, but for the pyboard 'D' it's already setup to use pin X9 and X10 is this correct?
OK - I'm off for a coffee and some chicken... Please someone cheer me up and answer this post!
Kind regards, Nicholas.