-
Notifications
You must be signed in to change notification settings - Fork 2
/
i2c.py
47 lines (41 loc) · 856 Bytes
/
i2c.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
from machine import I2C
import time
# known
addr = {
0x08: 'PIC',
0x10: 'GPS',
0x1e: 'LIS2HH12 (ACC)',
0x60: 'MPL3115A2',
0x29: 'LTR329ALS01',
0x40: 'SI7006A20',
}
def scan():
s = i2c.scan()
print("i2c[{}]:".format(len(s)))
for i in s:
if i in addr:
print(' 0x{:02x} /{:3d}: {}'.format(i,i,addr[i]))
else:
print(' 0x{:02x} /{:3d}'.format(i, i))
# print(i2c.scan())
# while True:
# print(i2c.scan())
# time.sleep(0.5)
#
# i2c.writeto(0xaa,1,stop=False)
# sda='P21' # default P9
# scl='P22' # default P10
print(os.uname())
# pytrack:
_sda='P22'
_scl='P21'
# IF
_sda='P2'
_scl='P3'
_i2c = I2C(2, mode=I2C.MASTER, pins=(_sda, _scl)) # , baudrate=100000)
# i2c = I2C(0, mode=I2C.MASTER)
# i2c = I2C()
# i2c = I2C(pins=(sda, scl), baudrate=400000 )
scan()
# print('done')