Skip to content

Commit 0cbb5e0

Browse files
committed
ref RobertLucian#8 : hotfix - replaced quick2wire with periphery package
1 parent ba37428 commit 0cbb5e0

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

Setup/install.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ install_dependencies() {
8181
sudo pip install -U RPi.GPIO
8282
sudo pip install pyusb
8383
sudo pip install numpy
84+
sudo pip install python-periphery
85+
sudo pip3 install -U RPi.GPIO
86+
sudo pip3 install pyusb
87+
sudo pip3 install numpy
88+
sudo pip3 install python-periphery
89+
8490

8591
feedback "Dependencies installed"
8692
}

Software/Python/line_follower/line_sensor.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141
import operator
4242
import pickle
4343
import numpy
44-
45-
from quick2wire import i2c
44+
from periphery import I2C, I2CError
4645

4746
debug = 0
4847

@@ -107,24 +106,26 @@ def read_sensor():
107106
command = 0x03
108107
unused = 0x00
109108

110-
# communicate with the line follower sensor
111109
try:
112-
with i2c.I2CMaster(bus_number) as bus:
113-
bus.transaction(i2c.writing(address, [register,command] + 3 * [unused]))
114-
bus.transaction(i2c.writing(address, [register]))
115-
read_results = bus.transaction(i2c.reading(address, 10))
116-
117-
except IOError as error:
118-
# return list of -1s on error
110+
i2c = I2C('/dev/i2c-' + str(bus_number))
111+
112+
read_bytes = 10 * [0]
113+
msgs = [
114+
I2C.Message([register, command] + 3 * [unused]),
115+
I2C.Message(read_bytes, read=True)
116+
]
117+
i2c.transfer(address, msgs)
118+
except I2CError as error:
119119
return 5 * [-1]
120120

121121
# unpack bytes received and process them
122-
bytes_list = struct.unpack('10B',read_results[0])
122+
# bytes_list = struct.unpack('10B',read_results[0])
123123
output_values = []
124+
input_values = msgs[1].data
124125

125126
for step in range(5):
126127
# calculate the 16-bit number we got
127-
sensor_buffer[step].append(bytes_list[2 * step] * 256 + bytes_list[2 * step + 1])
128+
sensor_buffer[step].append(input_values[2 * step] * 256 + input_values[2 * step + 1])
128129

129130
# if there're too many elements in the list
130131
# then remove one

0 commit comments

Comments
 (0)