The MCP4725 Digital to Analogue converter

Exercise 1:

Once the Digital to Analogue Converter (DAC) is correctly connected to the Raspberry Pi I2C interface the i2cdetect command will tell you that there is a device connected on I2C address 0x62.

In order to see that something is happening the dacTest program sends a square wave signal with 0 and the maximum possible value 0xfff at a frequency of 1/2 Hertz.

In the program the highest significant 4 bits go into reg while the lowest significant 8 bits go into value before being written to the DAC with i2c_write_byte_data. When the program is stopped with ^C it cleanly closes the i2c bus connection and disconnects from pigpiod.

Here is the code :

https://afnog.iotworkshop.africa/pub/UCC_Course_2018/Exercise8Solutions/dacTest.tar.gz

Exercise 2:

The setDac program is very similar to dacTest. Instead of hardcoding the DAC values we get the value from a command line argument. Please not that we use strtol which allows to convert text strings to long integers with different number base, including number base 16 for hex values. Look up the man page of strtol to learn more.

You can easily check with a Voltmeter if the programs are working correctly.

https://afnog.iotworkshop.africa/pub/UCC_Course_2018/Exercise8Solutions/setDac.tar.gz

-- Uli Raich - 2018-11-27

Comments

Topic attachments
I Attachment History Action Size Date Who Comment
Unknown file formatgz dacTest.tar.gz r1 manage 1.4 K 2018-11-27 - 18:11 UliRaich  
Unknown file formatgz setDac.tar.gz r1 manage 1.4 K 2018-11-27 - 18:11 UliRaich  
Topic revision: r1 - 2018-11-27 - UliRaich
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback