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
looks like everything is working as it should. may be your read DAC value function is not working.
if i were you i will run the dac values from 0 to 4000 and read the output on meter.
The reading the on the DMM did not change. It still reads 6.3 VDC. however, the reading from the dac changed. the data is [192, 48] causing a voltage of 0.02.