Skip to content

Commit ca6e96b

Browse files
committed
Updating I2C addresses
Updating both variants of the board as public global variables and adding an example in the main example file. Also fixing spacing from original local pre-commit run
1 parent 367e4d7 commit ca6e96b

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

adafruit_mcp4728.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
from time import sleep
3333
from adafruit_bus_device import i2c_device
3434

35-
_MCP4728_DEFAULT_ADDRESS = 0x60
35+
MCP4728_DEFAULT_ADDRESS = 0x60
36+
37+
MCP4728A4_DEFAULT_ADDRESS = 0x64
3638

3739
_MCP4728_CH_A_MULTI_EEPROM = 0x50
3840

@@ -115,7 +117,7 @@ class MCP4728:
115117
116118
"""
117119

118-
def __init__(self, i2c_bus, address: int = _MCP4728_DEFAULT_ADDRESS):
120+
def __init__(self, i2c_bus, address: int = MCP4728_DEFAULT_ADDRESS):
119121

120122
self.i2c_device = i2c_device.I2CDevice(i2c_bus, address)
121123

examples/mcp4728_generalcalltest.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,30 @@
11
# SPDX-FileCopyrightText: 2021 codenio (Aananth K)
2-
32
# SPDX-License-Identifier: MIT
43

5-
64
import board
7-
85
import adafruit_mcp4728
96

10-
117
i2c = board.I2C() # uses board.SCL and board.SDA
12-
138
mcp4728 = adafruit_mcp4728.MCP4728(i2c)
149

15-
1610
mcp4728.channel_a.value = 65535 # Voltage = VDD
17-
1811
mcp4728.channel_b.value = int(65535 / 2) # VDD/2
19-
2012
mcp4728.channel_c.value = int(65535 / 4) # VDD/4
21-
2213
mcp4728.channel_d.value = 0 # 0V
2314

24-
2515
mcp4728.save_settings() # save current voltages into EEPROM
2616

2717
print("Settings Saved into EEPROM")
2818

29-
3019
input("Press Enter to modify the channel outputs...")
3120

32-
3321
mcp4728.channel_a.value = 0 # Modify output
34-
3522
mcp4728.channel_b.value = 0 # Modify output
36-
3723
mcp4728.channel_c.value = 0 # Modify output
38-
3924
mcp4728.channel_d.value = 65535 # Modify output
4025

41-
4226
print("Channel Outputs Modified")
4327

44-
4528
input("Press Enter to invoke General Call Reset ...")
4629

47-
4830
mcp4728.reset() # reset MCP4728

examples/mcp4728_simpletest.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44
import board
55
import adafruit_mcp4728
66

7+
MCP4728_DEFAULT_ADDRESS = 0x60
8+
MCP4728A4_DEFAULT_ADDRESS = 0x64
9+
710
i2c = board.I2C() # uses board.SCL and board.SDA
8-
mcp4728 = adafruit_mcp4728.MCP4728(i2c)
11+
# use for MCP4728 variant
12+
mcp4728 = adafruit_mcp4728.MCP4728(i2c, adafruit_mcp4728.MCP4728_DEFAULT_ADDRESS)
13+
# use for MCP4728A4 variant
14+
# mcp4728 = adafruit_mcp4728.MCP4728(i2c, adafruit_mcp4728.MCP4728A4_DEFAULT_ADDRESS)
915

1016
mcp4728.channel_a.value = 65535 # Voltage = VDD
1117
mcp4728.channel_b.value = int(65535 / 2) # VDD/2

0 commit comments

Comments
 (0)