Posted on

Scripting the Analog Discovery 2 with Python in Linux Part 1

First, install Python, etc

First, check we have python installed:

python3 --version

The result is “Python 3.8.2” on my system. Now check we have setuptools and pip installed. These are third-party Python packages that we (may) need later.

command -v pip

The result is nothing, so we need to install as follows:

curl -o

This installs to /home/USER/.local/bin which is not on PATH. To add to the path:

export PATH="$HOME/.local/bin:$PATH"

Now install the Python dependency manager pipenv (this does a user installation to avoid breaking any system-wide packages):

pip install --user pipenv

Next, install the Adept 2 runtime and Waveforms software to allow communication with the hardware

Install Adept 2 from the Digilent site here. Install Waveforms here.

Next, install the Digilent DWF library wrapper for Python

pip install dwf

This installs the latest stable version of DWF.

Try it

Here’s a test script, modified from a version found on the Digilent forum (

from ctypes import *
import sys

if sys.platform.startswith("win"):
    dwf = cdll.dwf
elif sys.platform.startswith("darwin"):
    dwf = cdll.LoadLibrary("libdwf.dylib")
    dwf = cdll.LoadLibrary("")

#declare ctype variables
szerr = create_string_buffer(512)
print (szerr.value)

#declare ctype variables
IsInUse = c_bool()
hdwf = c_int()
channel = c_int()
hzfreq = c_double()
cdevices = c_int()

#declare string variables
devicename = create_string_buffer(64)
serialnum = create_string_buffer(16)

#print DWF version
version = create_string_buffer(16)
print ("DWF Version: "+str(version.value))

#enumerate and print device information
dwf.FDwfEnum(c_int(0), byref(cdevices))
print ("Number of Devices: "+str(cdevices.value))

for i in range(0, cdevices.value):
    dwf.FDwfEnumDeviceName (c_int(i), devicename)
    dwf.FDwfEnumSN (c_int(i), serialnum)
    print ("------------------------------")
    print ("Device "+str(i)+" : ")
    print ("t" + str(devicename.value))
    print ("t" + str(serialnum.value))
    dwf.FDwfEnumDeviceIsOpened(c_int(i), byref(IsInUse))

    if not IsInUse:
        dwf.FDwfDeviceOpen(c_int(i), byref(hdwf))
        dwf.FDwfAnalogInChannelCount(hdwf, byref(channel))
        dwf.FDwfAnalogInFrequencyInfo(hdwf, None, byref(hzfreq))
        print ("tAnalog input channels: "+str(channel.value))
        print ("tMax freq: "+str(hzfreq.value))
        hdwf = c_int(-1)

# ensure all devices are closed

Running the script results in the following output:

Posted on

Running multiple WordPress sites on Ubuntu Studio 20.04 LTS

Step 1: install Apache2

sudo apt install apache2

start Apache and have it run on system boot:

sudo systemctl enable --now apache2

We’re not accessing this externally, so no need for any firewall stuff.

Step 2: Install MySQL database server

sudo apt install mysql-server

The installation output tells us that the mysqld will log errors to /var/log/mysql/error.log.

Check the server is running with:

sudo mysql

This will connect to the MySQL server as the administrative database user root, which is inferred by the use of sudo when running this command. To exit the MySQL console, type ‘exit’.

Step 3: Install PHP

sudo apt install php libapache2-mod-php php-mysql

Step 4: Create databases

Logon to the mysql server:

sudo mysql


CREATE DATABASE databaseName1db;
CREATE DATABASE databaseName2db;

Now create the database users and passwords:

CREATE USER 'wp_user1'@'localhost' IDENTIFIED BY 'user1_password';
CREATE USER 'wp_user2'@'localhost' IDENTIFIED BY 'user2_password';

GRANT ALL PRIVILEGES ON databaseName1db.* TO 'wp_user1'@'localhost';
GRANT ALL PRIVILEGES ON databaseName2db.* TO 'wp_user2'@'localhost';


Step 5: create Apache server blocks

Now create a server block for each website:

sudo nano /etc/apache2/sites-available/
sudo nano /etc/apache2/sites-available/

Here’s an example of the content of each .conf file:

<VirtualHost *:80>
  DocumentRoot /var/www/

  <Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

Next, enable the server blocks:

sudo a2ensite
sudo a2ensite

Step 6: create document root folder for each site

sudo mkdir -p /var/www/
sudo mkdir -p /var/www/

When done, copy the latest WordPress into each folder.

Step 9: configure WordPress database settings

To create WordPress wp-config.php for each domain:

sudo cp /var/www/ /var/www/
sudo cp /var/www/ /var/www/

Then open each wp-config.php file and edit the database connection info.

Step 10: Permissions, etc

Modify the directory permissions:

sudo chown -R www-data:www-data /var/www/
sudo chmod -R 755 /var/www/

Check Apache settings, enable rewrite module and restart server:

sudo apachectl configtest
sudo a2enmod rewrite
sudo systemctl restart apache2.service

Step 11: set up local hosts file

We need to redirect requests to serve our locally hosted sites to the local Apache server, rather than have them go out to the external internet. This is done by adding two entries to the /etc/hosts file:

sudo nano /etc/hosts

Add a line for each of our local sites:       localhost       QPC-ATTIC
[XXX.XXX.XXX.XXX = IP address of local server]
[XXX.XXX.XXX.XXX = IP address of local server]