I am trying to generate 2KHz square wave via a MCP4725 on RPi3. I need to vary the voltage somewhere between 0 to 5Vpp, so I cannot use the digital GPIO pins and I get this MCP4725 from Adafruit.
I connect the MCP4275 and I can see it on the I2C bus.
I copy the Adafuit example and modify it as little bit, however when I run the following Python code it does not produce the 2 KHz square wave.
Code: Select all
import time # Import the MCP4725 module. import Adafruit_MCP4725 # Create a DAC instance. dac = Adafruit_MCP4725.MCP4725() # Loop forever alternating through different voltage outputs. print('Press Ctrl-C to quit...') while True: dac.set_voltage(0) time.sleep(0.00025) dac.set_voltage(4095) time.sleep(0.00025)
I have took a movie on this and I wonder if it is a software issue? I am aware of the following possibilities:
1) I2C speed default to RPi3 is too low, I should change to 3400000 (max 3.4 Mbps according to MCP4725)
2) bad cable but my cable is short and only about 10 cm
3) Adafruit python lib is slow, so I should change to pigpio python lib instead. But I have no idea on how to use those on MCP4725, http://abyz.co.uk/rpi/pigpio/python.html#i2c_open