### Controlling the input voltage
import time
from smbus2 import SMBus, i2c_msg
# Constants for the MCP4725
MCP4725_ADDR = 0x60 # Default I2C address for MCP4725, might vary
MCP4725_WRITE_DAC = 0x40
# Adjust as needed based on your OPA548 setup
V_MAX = 12.0
V_REF = 3.3 # Voltage reference for MCP4725, connected to 3.3V in this example
# Calculate the value to send to the MCP4725
def voltage_to_dac_value(voltage):
return int((voltage / V_REF) * 4095)
def set_voltage(bus, voltage):
value = voltage_to_dac_value(voltage)
# Break the 12 - bit value into 2 bytes.
byte1 = (value >> 4) & 0xFF
byte2 = (value & 0x0F) << 4
cmatsu5