Homepage Wiki Forum Buy



severity (level) requirement Gnublin family
Gnublin logo advanced.png Kernel compile, Toolchain All



Connect the Gnublin DAC module to the Gnublin Connector and expand your Gnublin by 4 digital to analog outputs. On the module, the MCP4728 chip has been installed. The DAConverter is addressed via the I²C interface. The default address is 0x60.

The following article describes, driving the chip which is installed on the DAC module with the GNUBLIN.


The module contains four channels, each with a registers and an EEPROM. The values ​​are saved in registers will be converted into a voltage related to the value. The register has a 12 bit resolution. So, the number 4095 describes the highest voltage value. Normally, this is 3.3 V. The operating voltage of Gnublin.

Writing a value to a specific channel:

root@gnublin:~# gnublin-dac -c 0 -v 4095

Now, on channel 0 should be a voltage of 3.3V.

However, the reference voltage may not be the operating voltage of the Gnublin. The module also provides an internal reference voltage. This amounts to 2.048 V. This is activated with the command -r.

root@gnublin:~# gnublin-dac -c 1 -v 4095 -r

Now, on channel 1, there should be 2V.

The values, saved in the registers, are also readable.

Read the value on channel 0:

root@gnublin:~# gnublin-dac -c 0

Read the value on channel 1:

root@gnublin:~# gnublin-dac -c 1

Both times, the value is 4095. To derive the voltage applied to computing, so it is necessary to know which reference voltages has been applied.

For Beginners

Once you received the module from the shop, and one is in possession of the GNUBLIN distribution, so you can perform the following steps.

First, the module is connected. One must note here only that the ribbon cable with the red wire in the direction of the SD card shows.

For easy and fast reading of voltages, a small program was implemented. The program for the AD converter is pre-installed in the distribution.

The installed program is called like this:

root@gnublin:~# gnublin-dac

Adress of the modul

Please note that you set the correct address on the module or give the correct address as an option. By default, the address 0x60 is used.

If you want to for example Read the voltage of the module with the address 0x60 on input 1, then type as follows:

root@gnublin:~# gnublin-dac -c 1 -a 60

If you are not sure of the address of the block, then just ask the I2C tools:

root@gnublin:~# i2cdetect -y 1

More Commands

You will get all commands, if you type following:

root@gnublin:~# ./gnublin-dac -h
This program is designed, to easily access the GNUBLIN MODUL DAC
(Digital to Analog Converter) MCP4728.
-h Show this help
-j Convert output to json format
-b show output in raw format
-a set slave-address e.g. 0x60
-c Select channel: 0-3. If not more is given, value of register will be read. : Use -b and -j for other formats.
-v Select value. 12 bit resolution: 0-4095.
-e Write to EEPROM
-r Select Internal Referenz = 2.048V.
-g Set gain on 2x. Use -g only if you have selected Internal Ref (-r).
simple wirte on channel 0 a specific value:
gnublin-dac -c 0 -v 4095
Write to channel 2, register and EEPROM and use internal ref with gain:
gnublin-dac -c 2 -v 4095 -e -r -g
read value of channel 2:
gnublin-dac -c 2

For Advanced Users

Voltage supply

Die Voltage supply should be between: 2.7 V - 5.5 V

EEPROM and gain

The module offers another useful function. You can't only write a value in a register, but also in the channel's EEPROM. This ensures that even after power interruption, the DAC module resumes the same voltage as before.

Type this command for EEPROM usage:

root@gnublin:~# gnublin-dac -c 0 -v 2000 -e

Now you can check if it works by disconnecting and reconnecting the cable and you will see, that the voltage is still the same.

Further, the device also provides a way to amplify the voltage. This gain can be used with -g. Once gain is activated, the voltage is always doubled. NOTE: This is only possible if the reference voltage was switched on internally. Maximum voltage is for sure 3.33V.

With the command -e you can also save these settings. The following command demonstrates this:

root@gnublin:~# gnublin-dac -c 0 -v 1024 -e -r -g

You will meassure a voltage about 1.0V. Following calculation should ilustrate this:

vRef = 2.048V

Divider = 4095 / 1024 = 4

Gain = 2

Voltage = (Gain * vRef)/Divider

Voltage = 1.0V

Tip: This command (-r -g) could be very interesting, because the value is the voltage exact in millivolts.

Test it again by reconnecting the modul. If everything has been written to the EEPROM, there should be again 1.0V at channel 0.

In other languages