Posted on

Scripting the Analog Discovery 2 with Python in Linux Part 2

Now that Python and the Digilent DWF Python wrapper are installed (link), we can start using the Analog Discovery 2 to do something useful. The Waveforms SDK provides access to an API that allows the creation of custom applications using the Digilent Analog Design hardware (e.g. the Analog Discovery 2). The reference manual is here.

Working code examples are installed in /usr/share/digilent/waveforms/samples/

I used AnalogIn_Record_Wave_Mono.py as a basis, and along with it copied dwfconstants.py to the project folder.

For a multi-threaded front-end, I used the good example here: https://github.com/beenje/tkinter-logging-text-widget/blob/master/main.py

The script generates a sine wave at a range of frequencies on signal generator channel 1 and samples the input on scope channel 1. Gain is calculated for each frequency, with the aim of evaluating the frequency response of some audio hardware. Some flakiness with the USB connection was solved by switching the PC connection to the Analog Discovery 2 from a USB 2 to a USB 3 port. Code is available here: https://github.com/richardtoller/1007-AD2.git. I used the PyCharm IDE.

The first test to run is with the Analog Discovery 2 output connected directly back to its input, i.e. with no test hardware in the circuit, to establish the frequency response of the test kit.