1-Wire Communication
We highly encourage everyone to use our new Python package which is packed with features. This library is still supported, but is not recommended for new design.
The python script below demonstrates how to communicate with a DS2413, a dual-channel addressable switch IC. You can get one on an easy-to-use breakout board from our friends at Adafruit.
1
from binhoHostAdapter import binhoHostAdapter
2
3
from time import sleep
4
5
# change this to your COM port
6
binhoTesterCommPort = 'COM22'
7
8
print("Opening " + binhoTesterCommPort + "...")
9
print()
10
11
for i in range(3):
12
13
# create the binhoHostAdapter object
14
binhoTester = binhoHostAdapter.binhoHostAdapter(binhoTesterCommPort)
15
16
print("Connecting to binho host adapter tester...")
17
print()
18
19
oneWireIndex = 0
20
21
binhoTester.setLEDColor('CYAN')
22
23
binhoTester.setOperationMode(0, '1WIRE')
24
25
print(binhoTester.begin1WIRE(oneWireIndex, 0, True))
26
print(binhoTester.reset1WIRE(oneWireIndex))
27
28
print("Looking for a DS2413 on the bus")
29
print(binhoTester.resetSearch1WIRE(oneWireIndex))
30
print(binhoTester.search1WIRE(oneWireIndex))
31
print(binhoTester.getAddress1WIRE(oneWireIndex))
32
33
def write2413(state):
34
35
print('state orig: ' + str(state))
36
37
state |= 0xfc
38
39
print('state now: ' + str(state))
40
print('state inv: ' + str(~state + 256))
41
42
print('write2413 func begin')
43
print(binhoTester.reset1WIRE(oneWireIndex))
44
print(binhoTester.select1WIRE(oneWireIndex))
45
print(binhoTester.writeByte1WIRE(oneWireIndex, 90))
46
print(binhoTester.writeByte1WIRE(oneWireIndex, state))
47
print(binhoTester.writeByte1WIRE(oneWireIndex, ~state +256))
48
print(binhoTester.readByte1WIRE(oneWireIndex))
49
print(binhoTester.readByte1WIRE(oneWireIndex))
50
print(binhoTester.reset1WIRE(oneWireIndex))
51
52
53
write2413(3)
54
print('Sleeping for a hot sec ... ')
55
sleep(1.0)
56
print('doing it again...')
57
write2413(0)
58
print('Finished!')
59
60
binhoTester.close()
Copied!
Last modified 8mo ago
Copy link