adafruit / adafruit/Adafruit_CircuitPython_MCP4728

Inconsistent storage and return of vref and gain as booleans vs int and wrong values for gain

Open Beginner friendly
#22 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
6
Forks
8
PR merge metrics
No merged PRs in 30d

Description

The `_get_flags()` method uses two greater comparisons which results in boolean values being returned.

https://github.com/adafruit/Adafruit_CircuitPython_MCP4728/blob/65334afea2e176a05fd146c213a4d0b3f437c03b/adafruit_mcp4728.py#L138-L142

These in turn get stored in the object.

https://github.com/adafruit/Adafruit_CircuitPython_MCP4728/blob/65334afea2e176a05fd146c213a4d0b3f437c03b/adafruit_mcp4728.py#L138-L142

While this works for these 1bit values it's confusing

- to have the getters return a different type from the setters
- it probably wasn't intended that way based on the typing and doc strings
- and for gain the numerical equivalents for `bool` type are 0 and 1 rather than 1 and 2

https://github.com/adafruit/Adafruit_CircuitPython_MCP4728/blob/65334afea2e176a05fd146c213a4d0b3f437c03b/adafruit_mcp4728.py#L360-L361

https://github.com/adafruit/Adafruit_CircuitPython_MCP4728/blob/65334afea2e176a05fd146c213a4d0b3f437c03b/adafruit_mcp4728.py#L353-L355

Here's an example of the values being retrieved

```
Adafruit CircuitPython 10.2.1 on 2026-05-13; Cytron Maker Nano RP2040 with rp2040
>>> import adafruit_mcp4728, board, busio
>>> i2c = busio.I2C(scl=board.GP1, sda=board.GP0)
>>> mcp_dac = adafruit_mcp4728.MCP4728(i2c)
>>> dac_chan = mcp_dac.channel_a
>>> dac_chan.vref
False
>>> dac_chan.gain
False
```

It gets weirder if you modify gain with the value becoming an `int` (good) but not being _presented_ as what was set (bad).

```
>>> dac_chan.gain = 2
>>> dac_chan.gain
1

```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in adafruit_mcp4728.py at the _get_flags() method and the vref and gain getter/setter locations linked in the issue. Check the returned and stored types and the gain values, then verify that getters present the values set by the caller using the interactive examples as the expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
embedded-iot
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.