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://iotworkshop.africa/pub/Embedded_Systems/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://iotworkshop.africa/pub/Embedded_Systems/Exercise8Solutions/setDac.tar.gz