Cannot communicate with MCP4725 with smbus or Adafruit_MCP4725 library

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.

image
This is the inital set up. The adafruit library is the commented stuff.

image
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.

I have the Vout and GND pins on the DAC connected to a DMM and it reads 5.47 VDC consistently

Does that code throw any errors?

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

So the A0 pin is jumped on the board to reach address 0x61.

The adafruit libraries I’m looking at seems odd like they’re for a different chip almost.

Can you post all of your code?

Why are you wrapping self in type()?

Can you try sending
smbus_object.write_byte_data(0x61, 0x00, 0x00)

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.

All my code can be found here https://github.com/jgatzemeier/Automated_Deburr/blob/master/MotorControl.py

I wrapped self because I have the DAC as a class attribute instead of an instance attribute, however, I might change this to see.

I will try sending that and will post the results. What would I expect to see on the DAC output if it is successful?

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))

Can you link me the source code you’re looking at from Adafruit?

I will try your above suggestions. But here is the adafruit library

When I do the bus.write_i2c_block_data(0x61, 0x00, bytearray(0x00, 0x00)) I get an error.

TypeError: bytearray() argument 2 must be str, not int

Alright it looks like the Fast Write doesn’t work with Python. So we’ll have to use smbus.write_i2c_block_data(0x61, 0x60, bytearray([0x00, 0x00])

I forgot to add array brackets to the bytearray.

Here is an post where Scroix outlines this: Raspberry Pi 0-10V Board - libraries and code samples

Okay

I tried that command and I am getting a type error that says Third argument must be a list of at least one, but not more than 32 integers

Also is the second argument supposed to be 0x60 or 0x00?

I will take a look at that post.

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

while using this code


what did you set your raw_value ?

Thanks

I just used that exact code. I set my raw value to 0 and my output was 0. I then set my raw value to 2048 and still got 0. My DMM still says 5 V.

Could it possibly be my board?

set the value to 1024 and see whats the output value.

the output of the file is 0 for the raw ADC and 0 for the voltage when I set the voltage to 1024

did you measure the voltage using multimeter?

yes it is a constant 6.31 VDC since I gave power to the DAC.

I had the script print the data it is reading when I send it 1024 and it is [192, 0]

Not sure what i should expect it to be