Skip to content

Commit 577943b

Browse files
configurable address
1 parent 21fcbee commit 577943b

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
A Viam module that returns sensor values from a capacitive touch sensor device with the MPR121 chip.
33

44
# Attributes
5-
No configuration attributes are required. The module is built assuming the default I2C bus.
5+
No configuration attributes are required if your device operates on the i2c address of `0x5A`. Otherwise you can configure a different address using the config example below. The module is built assuming the default I2C bus.
6+
7+
{
8+
"i2c_address": "0x5A"
9+
}
610

711
# GetReadings
812
The Sensor.GetReadings response will look like the following. A touchpads array contains the status of each pad/input to the device. True means that it is being touched, false means untouched. In the below example, input 0 is touched and 1-11 is untouched.

models.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ def reconfigure(self,
2525
config: ComponentConfig,
2626
dependencies: Mapping[ResourceName, ResourceBase]):
2727
i2c = busio.I2C(board.SCL, board.SDA)
28-
self.mpr121 = adafruit_mpr121.MPR121(i2c)
28+
29+
i2c_address: int = 0x5A
30+
if "i2c_address" in config.attributes.fields:
31+
i2c_address = int(config.attributes.fields["i2c_address"].string_value, base=16)
32+
33+
self.mpr121 = adafruit_mpr121.MPR121(i2c=i2c, address=i2c_address)
2934

3035
async def get_readings(self, **kwargs):
3136
return {"touchpads": [t.value for t in self.mpr121]}

setup.sh

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ source .env
2828
if [ -f $VIRTUAL_ENV/.install_complete ]; then
2929
echo "completion marker is present, skipping virtualenv setup"
3030
else
31+
sudo apt install -y git
3132
echo creating virtualenv at $VIRTUAL_ENV
3233
python3 -m venv $VIRTUAL_ENV
3334
echo installing dependencies from requirements.txt

0 commit comments

Comments
 (0)