I am having so much trouble being able to communicate with my 0-10V DAC the MCP4725.
I have tried the Adafruit MCP4725 library and the smbus library.
I prefer the Adafruit library because the calls are simple. I am open to anything though. I just can’t seem to get the DAC to change its output at all.
This is the code I have tried. The address on my DAC is 0x61, verified by i2cdetect -y 1 on my pi.
This is the inital set up. The adafruit library is the commented stuff.
This is the function I am calling to talk to the DAC.
Any assistance or advice is much appreciated! This is my first time ever using an I2C device.
No errors. I even ran the adafruit portion in a separate python file and it is definitely running because it prints the value it sends to the DAC but the DAC continues to output a constant 5.3 VDC
I have the A0 pin jumped. i2cdetect -y 1 shows the address as 0x61. The adafruit library is for their MCP4725 board which I thought may be the issue which is why I also tried the smbus.
I tried the exact sample code below from a sparkfruit tutorial and still no results.
# i2ctest.py
# A brief demonstration of the Raspberry Pi I2C interface, using the Sparkfun
# Pi Wedge breakout board and a SparkFun MCP4725 breakout board:
# https://www.sparkfun.com/products/8736
import smbus
# I2C channel 1 is connected to the GPIO pins
channel = 1
# MCP4725 defaults to address 0x60
address = 0x60
# Register addresses (with "normal mode" power-down bits)
reg_write_dac = 0x40
# Initialize I2C (SMBus)
bus = smbus.SMBus(channel)
# Create a sawtooth wave 16 times
for i in range(0x10000):
# Create our 12-bit number representing relative voltage
voltage = i & 0xfff
# Shift everything left by 4 bits and separate bytes
msg = (voltage & 0xff0) >> 4
msg = [msg, (msg & 0xf) << 4]
# Write out I2C command: address, reg_write_dac, msg[0], msg[1]
bus.write_i2c_block_data(address, reg_write_dac, msg)
I still see nothing but around 5V. I also replaced the line " bus.write_i2c_block_data(address, reg_write_dac, msg)" with “bus.write_byte_data(0x61, 0x00, 0x00)” and the output voltage doesn’t change at all.
I would believe 0v, that chip is a bit strange as it uses a “fast write” which doesn’t have a command register. Basically you want to send two bytes in a 12-bit MSB LSB. So it should just look like byte_array(0x61, 0x00, 0x00) as the only bytes going to the board.
I would think Python code that works with one MCP4725 would work with another. We don’t do anything strange, just expose it to the I2C bus.
It should set the voltage to 0v.
I can’t say I’ve ever used class attributes so I’m not 100% how the syntax/function in Python.
I don’t have one on my desk to test against.
What about sending bus.write_i2c_block_data(0x61, 0x00, bytearray(0x00, 0x00))
I looked at what Scriox wrote. I used the call bus.write_i2c_block_data(0x61, 0x61, [0x00, 0x00]) which is what he did I just replaced the raw value stuff he had with 0 to change the DAC output to 0 volts. I was unsuccessful. It did however, get rid of the TypeError