IC – MCP4725 – D/A Converter 12-bit 1 channel I2C
Hardware
Chip:
Module:
Pinout
Arduino
Sluit de module aan volgens onderstaand overzicht:
Met onderstaand arduino script kun je de uitgangsvoltage instellen:
nodig: MCP4725 Arduino Library van Adafruit.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
/* * Arduino Digital to Analog Coverter MCP4725 Interface code * Library from Adafruit-MCP4725 * see text at www.theorycircuit.com */ #include <Wire.h> //wire library #include <Adafruit_MCP4725.h> // MCP4725 library from adafruit #define analogVin A0 // Analog voltage input to A0 Adafruit_MCP4725 MCP4725; void setup(void) { Serial.begin(9600); MCP4725.begin(0x60); // Default I2C Address of MCP4725 breakout board (sparkfun) } void loop(void) { uint32_t MCP4725_value; int adcValueRead = 0; float voltageRead = 0; float MCP4725_expected_output; for (MCP4725_value = 0; MCP4725_value < 4096; MCP4725_value = MCP4725_value + 15) { MCP4725_expected_output = (5.0/4096.0) * MCP4725_value; MCP4725.setVoltage(MCP4725_value, false); delay(250); adcValueRead = analogRead(analogVin); voltageRead = (adcValueRead * 5.0 )/ 1024.0; Serial.print("MCP4725 Value: "); Serial.print(MCP4725_value); Serial.print("\tExpected Voltage: "); Serial.print(MCP4725_expected_output,3); Serial.print("\tArduino ADC Value: "); Serial.print(adcValueRead); Serial.print("\tArduino Voltage: "); Serial.println(voltageRead,3); } } |
Arduino Library
Installatie van Arduino IDE libraries: Arduino info
Informatie (ENG):
This is the Adafruit MCP4725 12-bit I2C DAC Driver library
This chip uses I2C to communicate, 2 pins are required to interface
Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!
Written by Kevin Townsend/Limor Fried for Adafruit Industries.
BSD license, check license.txt for more information All text above must be included in any redistribution
To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_MCP4725. Check that the Adafruit_MCP4725 folder contains Adafruit_MCP4725.cpp and Adafruit_MCP4725.h
Place the Adafruit_MCP4725 library folder your arduinosketchfolder/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.
Raspberry Pi
Sluit de module aan zoals aangegeven op onderstaand schema:
Ps. Altijd de pinout van je Raspberry Pi controleren, deze kan verschillen per versie.
Wat heb je nodig?
Bibliotheek: Adafruit_Python_MCP4725
git clone https://github.com/adafruit/Adafruit_Python_MCP4725
1 2 3 4 |
Cloning into 'Adafruit_Python_MCP4725'... remote: Enumerating objects: 49, done. remote: Total 49 (delta 0), reused 0 (delta 0), pack-reused 49 Unpacking objects: 100% (49/49), done. |
cd Adafruit_Python_MCP4725
sudo python setup.py install
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
running install running bdist_egg running egg_info creating Adafruit_MCP4725.egg-info writing requirements to Adafruit_MCP4725.egg-info/requires.txt writing Adafruit_MCP4725.egg-info/PKG-INFO writing top-level names to Adafruit_MCP4725.egg-info/top_level.txt writing dependency_links to Adafruit_MCP4725.egg-info/dependency_links.txt writing manifest file 'Adafruit_MCP4725.egg-info/SOURCES.txt' reading manifest file 'Adafruit_MCP4725.egg-info/SOURCES.txt' writing manifest file 'Adafruit_MCP4725.egg-info/SOURCES.txt' installing library code to build/bdist.linux-armv7l/egg running install_lib running build_py creating build creating build/lib.linux-armv7l-2.7 creating build/lib.linux-armv7l-2.7/Adafruit_MCP4725 copying Adafruit_MCP4725/__init__.py -> build/lib.linux-armv7l-2.7/Adafruit_MCP4725 copying Adafruit_MCP4725/MCP4725.py -> build/lib.linux-armv7l-2.7/Adafruit_MCP4725 creating build/bdist.linux-armv7l creating build/bdist.linux-armv7l/egg creating build/bdist.linux-armv7l/egg/Adafruit_MCP4725 copying build/lib.linux-armv7l-2.7/Adafruit_MCP4725/__init__.py -> build/bdist.linux-armv7l/egg/Adafruit_MCP4725 copying build/lib.linux-armv7l-2.7/Adafruit_MCP4725/MCP4725.py -> build/bdist.linux-armv7l/egg/Adafruit_MCP4725 byte-compiling build/bdist.linux-armv7l/egg/Adafruit_MCP4725/__init__.py to __init__.pyc byte-compiling build/bdist.linux-armv7l/egg/Adafruit_MCP4725/MCP4725.py to MCP4725.pyc creating build/bdist.linux-armv7l/egg/EGG-INFO copying Adafruit_MCP4725.egg-info/PKG-INFO -> build/bdist.linux-armv7l/egg/EGG-INFO copying Adafruit_MCP4725.egg-info/SOURCES.txt -> build/bdist.linux-armv7l/egg/EGG-INFO copying Adafruit_MCP4725.egg-info/dependency_links.txt -> build/bdist.linux-armv7l/egg/EGG-INFO copying Adafruit_MCP4725.egg-info/requires.txt -> build/bdist.linux-armv7l/egg/EGG-INFO copying Adafruit_MCP4725.egg-info/top_level.txt -> build/bdist.linux-armv7l/egg/EGG-INFO zip_safe flag not set; analyzing archive contents... creating dist creating 'dist/Adafruit_MCP4725-1.0.4-py2.7.egg' and adding 'build/bdist.linux-armv7l/egg' to it removing 'build/bdist.linux-armv7l/egg' (and everything under it) Processing Adafruit_MCP4725-1.0.4-py2.7.egg Copying Adafruit_MCP4725-1.0.4-py2.7.egg to /usr/local/lib/python2.7/dist-packages Adding Adafruit-MCP4725 1.0.4 to easy-install.pth file Installed /usr/local/lib/python2.7/dist-packages/Adafruit_MCP4725-1.0.4-py2.7.egg Processing dependencies for Adafruit-MCP4725==1.0.4 Searching for Adafruit-GPIO>=0.6.5 Downloading https://github.com/adafruit/Adafruit_Python_GPIO/tarball/master#egg=Adafruit-GPIO-0.6.5 Best match: Adafruit-GPIO 0.6.5 Processing master Writing /tmp/easy_install-jvVqj5/adafruit-Adafruit_Python_GPIO-a12fee3/setup.cfg Running adafruit-Adafruit_Python_GPIO-a12fee3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-jvVqj5/adafruit-Adafruit_Python_GPIO-a12fee3/egg-dist-tmp-lvusDn Adafruit GPIO Library Works best with Python 2.7 THIS INSTALL SCRIPT MAY REQUIRE ROOT/ADMIN PERMISSIONS Especially if you installed python for "all users" on Windows try the following in your systems terminal if ensurepip is not sufficient: $ python -m ensurepip --upgrade $ python -m pip install --upgrade pip setuptools zip_safe flag not set; analyzing archive contents... Moving Adafruit_GPIO-1.0.4-py2.7.egg to /usr/local/lib/python2.7/dist-packages Adding Adafruit-GPIO 1.0.4 to easy-install.pth file Installed /usr/local/lib/python2.7/dist-packages/Adafruit_GPIO-1.0.4-py2.7.egg Searching for adafruit-pureio Reading https://pypi.org/simple/adafruit-pureio/ Downloading https://files.pythonhosted.org/packages/90/6d/ee3b05a3016aefb446f14103e99021186aace51e9d75f5aee25e031f8e8d/Adafruit_PureIO-1.1.7.tar.gz#sha256=2d6522d9b333e60d67fad8c3169b0c6560016a5f5f8f571b1f9692db60e14eb4 Best match: Adafruit-PureIO 1.1.7 Processing Adafruit_PureIO-1.1.7.tar.gz Writing /tmp/easy_install-btfjgS/Adafruit_PureIO-1.1.7/setup.cfg Running Adafruit_PureIO-1.1.7/setup.py -q bdist_egg --dist-dir /tmp/easy_install-btfjgS/Adafruit_PureIO-1.1.7/egg-dist-tmp-kk2FxD File "build/bdist.linux-armv7l/egg/Adafruit_PureIO/spi.py", line 386 ) from e ^ SyntaxError: invalid syntax zip_safe flag not set; analyzing archive contents... Moving Adafruit_PureIO-1.1.7-py2.7.egg to /usr/local/lib/python2.7/dist-packages Adding Adafruit-PureIO 1.1.7 to easy-install.pth file Installed /usr/local/lib/python2.7/dist-packages/Adafruit_PureIO-1.1.7-py2.7.egg Searching for spidev==3.4 Best match: spidev 3.4 Adding spidev 3.4 to easy-install.pth file Using /usr/lib/python2.7/dist-packages Finished processing dependencies for Adafruit-MCP4725==1.0.4 |
Gebruikt I2c detect om te controleren of er een i2c apparaat is gevonden, standaard is dit 0x62 (met brug op GND 0x60)
1 2 3 4 5 6 7 8 9 10 |
sudo i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: 60 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- |
Met onderstaand python script worden de voltages om de x seconden aangepast:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# Simple demo of setting the output voltage of the MCP4725 DAC. # Will alternate setting 0V, 1/2VDD, and VDD each second. # Author: Tony DiCola # License: Public Domain import time # Import the MCP4725 module. import Adafruit_MCP4725 # Create a DAC instance. dac = Adafruit_MCP4725.MCP4725(address=0x60) # Note you can change the I2C address from its default (0x62), and/or the I2C # bus by passing in these optional parameters: #dac = Adafruit_MCP4725.MCP4725(address=0x49, busnum=1) # Loop forever alternating through different voltage outputs. print('Press Ctrl-C to quit...') while True: print('Setting voltage to 0!') dac.set_voltage(0) time.sleep(3.0) print('Setting voltage to 1/4 Vdd!') dac.set_voltage(1024) time.sleep(2.0) print('Setting voltage to 2/4 Vdd!') dac.set_voltage(2048) time.sleep(2.0) print('Setting voltage to 3/4 Vdd!') dac.set_voltage(3072) time.sleep(2.0) print('Setting voltage to Vdd!') dac.set_voltage(4096, True) time.sleep(2.0) |
Start het script met: sudo python test.py , druk op CTRL+C om het script te stoppen!
Dit is de output in de console:
1 2 3 4 5 6 |
Press Ctrl-C to quit... Setting voltage to 0! Setting voltage to 1/4 Vdd! Setting voltage to 2/4 Vdd! Setting voltage to 3/4 Vdd! Setting voltage to Vdd! |
Bron:
raspberrypi-spy.co.uk
Afmetingen
GEEN GEGEVENS
Schema
GEEN GEGEVENS
Teardown
GEEN GEGEVENS
Datasheet
Fritzing
GEEN GEGEVENS
Downloads
GEEN GEGEVENS