Editing MCP4725.py for controlling 2 MCP4725 at same time

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
AWK073
 
Posts: 1
Joined: Fri Nov 24, 2017 6:22 pm

Editing MCP4725.py for controlling 2 MCP4725 at same time

Post by AWK073 »

I have two MCP4725 from adafruit. I2c address is 0x62 and 0x63. They are working ok when I operate them separately.

I want to output voltage from each one from one script. I want to edit MCP4725.py which is Adafruit_MCP4725 folder. When I edit this file this error showed up [errno 13] permission denied.
This file I want to edit. Can it be edited. have a look at Default 12c address........

Code: Select all


import logging
# Register values:
WRITEDAC         = 0x40
WRITEDACEEPROM   = 0x60

# Default I2C address:
DEFAULT_ADDRESS  = 0x62  [color=#0040BF]### I can write 0x63 also with it like. DEFAULT_ADDRESS =[0x62,0x63][/color]


logger = logging.getLogger(__name__)


class MCP4725(object):
    """Base functionality for MCP4725 digital to analog converter."""

    def __init__(self, address=DEFAULT_ADDRESS, i2c=None, **kwargs):
        """Create an instance of the MCP4725 DAC."""
        if i2c is None:
            import Adafruit_GPIO.I2C as I2C
            i2c = I2C
        self._device = i2c.get_i2c_device(address, **kwargs)

    def set_voltage(self, value, persist=False):
        """Set the output voltage to specified value.  Value is a 12-bit number
        (0-4095) that is used to calculate the output voltage from:
          Vout =  (VDD*value)/4096
        I.e. the output voltage is the VDD reference scaled by value/4096.
        If persist is true it will save the voltage value in EEPROM so it
        continues after reset (default is false, no persistence).
        """
        # Clamp value to an unsigned 12-bit value.
        if value > 4095:
            value = 4095
        if value < 0:
            value = 0
        logging.debug('Setting value to {0:04}'.format(value))
        # Generate the register bytes and send them.
        # See datasheet figure 6-2:
        #   https://www.adafruit.com/datasheets/mcp4725.pdf 
        reg_data = [(value >> 4) & 0xFF, (value << 4) & 0xFF]
        if persist:
            self._device.writeList(WRITEDACEEPROM, reg_data)
        else:
            self._device.writeList(WRITEDAC, reg_data) 

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”