====== Logging Data to a Flash Drive with Analog Discovery Pro (ADP3450/ADP3250) ======
~~TechArticle~~
This page is under construction.
===== Overview =====
This guide demonstrates using the Analog Discovery Pro in Linux mode to automate data logging directly to a USB flash drive. Automation is accomplished using WaveForms SDK and Python 3. Before following this guide, make sure that you run the latest Linux version on your device. Follow this guide to update the Linux on your Analog Discovery Pro: [[test-and-measurement:analog-discovery-pro-3x50:recover-linux-mode|]].
----
===== Inventory =====
* [[test-and-measurement:analog-discovery-pro-3x50:start|Analog Discovery Pro (ADP3450/ADP3250)]]
* A FAT/FAT32 USB drive
* [[https://ttssh2.osdn.jp/index.html.en|Tera Term]], [[https://www.chiark.greenend.org.uk/~sgtatham/putty/|PuTTY]], or any other terminal emulator of your choice
----
===== Boot Into Linux Mode =====
Mode selection can be done through WaveForms using the Device Manager. With the Analog Discovery Pro connected to the host computer by Ethernet, open WaveForms. If the Device Manager hasn't opened yet, then click Settings -> Device Manager.
{{ :test-and-measurement:analog-discovery-pro-3x50:usb_st.png?400 |}}
Select the Analog Discovery Pro from the device menu, then click the Boot button. The Boot Mode window should open. By default, Standard Mode which allows the user to communicate with the instrumentation device over USB or Ethernet will be selected.
To change to Linux Mode, select Linux, then click "Apply & Reboot".
{{ :reference:software:waveforms:waveforms-sdk:linux_mode.png?400 |}}
At this time, an audible click should be heard and the Analog Discovery Pro will disconnect from WaveForms. About 10-15 seconds should pass before it reconnects. Confirm that the second column next to the Analog Discovery Pro says "USB Linux", confirming the mode has successfully been switched.
{{ :test-and-measurement:analog-discovery-pro-3x50:usb_lx.png?400 |}}
----
===== Connect Through a Terminal Emulator =====
Find what serial port the Analog Discovery Pro is connected to and note it.
Open a terminal emulator such as PuTTY or TeraTerm and connect to the noted serial port using 115200 Baud, 8 data, 1 stop, and no parity bits.
{{ reference:test-and-measurement:analog-discovery-pro-3x50:terminal-settings.png?400 |}}
Login with username: "digilent" and password: "digilent".
{{ reference:test-and-measurement:analog-discovery-pro-3x50:linux-mode-login.png?400 |}}
----
===== Mount the Flash Drive =====
Download {{ :test-and-measurement:analog-discovery-pro-3x50:logger.zip |this}} package and extract the contents onto the USB drive.
Plug the USB into the back of the Analog Discovery Pro. In the terminal, type sudo fdisk -l to find the USB device path. It should look like ///dev/sd//. This guide will use /dev/sda1 in its text and images, and care must be taken to match the drive letter and partition number of your USB drive.
{{ reference:test-and-measurement:analog-discovery-pro-3x50:fdisk-output.png?400 |}}
Make the drive contents accessible by entering the command sudo mount /dev/sda1 /mnt and then cd /mnt to navigate into the USB's directory.
{{ reference:test-and-measurement:analog-discovery-pro-3x50:mount-usb.png?400 |}}
----
===== Script Overview =====
Import the necessary Python packages, then define the name of the output file and the drive letter and number of the USB drive.
# import modules
from ctypes import *
from dwfconstants import *
from subprocess import call
import sys
# parameters
filename = "voltages.txt"
drive = "sda1"
Load the WaveForms SDK dynamic library, then open the device.
# load WaveForms SDK
if sys.platform.startswith("win"):
dwf = cdll.dwf # on windows
elif sys.platform.startswith("darwin"):
dwf = cdll.LoadLibrary("/Library/Frameworks/dwf.framework/dwf")
else:
dwf = cdll.LoadLibrary("libdwf.so")
# global variables
hdwf = c_int() # device handle
# open device
dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf)) # open first device
# check for errors
if hdwf.value == hdwfNone.value:
print("failed to open device") # display error
quit()
Initialize the Oscilloscope. If you want to use a different instrument, change this part at your will.
Mount the USB storage. If the file system is already mounted, this command will only return a message. Set the path and the name of your file.
try:
# initialize the oscilloscope
# enable the channel
dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(0), c_bool(True))
# set 0V offset
dwf.FDwfAnalogInChannelOffsetSet(hdwf, c_int(0), c_double(0))
# set the range from -5V to +5V
dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(0), c_double(5))
# start the oscilloscope
dwf.FDwfAnalogInConfigure(hdwf, c_bool(False), c_bool(False))
# mount the USB strorage
call(["sudo", "mount", "/dev/" + drive, "/mnt"])
# set file path
filename = "/mnt/" + filename
Load and save the oscilloscope data in a buffer, then write out the content of the buffer to the file. The file remains opened, until the script runs.
# create/open the file
with open(filename, "w") as f:
while True:
# measure voltage
# load internal buffer
dwf.FDwfAnalogInStatus(hdwf, False, None)
voltage = c_double() # buffer for raw values
# save the internal buffer
dwf.FDwfAnalogInStatusSample(hdwf, c_int(0), byref(voltage))
voltage = float(voltage.value) # get voltage values
# save voltage
f.write("{}\n".format(voltage))
Finally, exit the script on "Ctrl+C", then reset the used instruments and disconnect from the device.
except KeyboardInterrupt:
# exit on Ctrl+C
pass
finally:
# reset and close the device
dwf.FDwfAnalogInReset(hdwf) # reset the oscilloscope
dwf.FDwfDeviceClose(hdwf) # disconnect the device
----
===== Testing =====
Start the script with the following command:
sudo python3 /mnt/logger.py
To terminate the script and to close the file, press "Ctrl+C" on the keyboard. When the script is exited, the file is saved on your USB flash drive.
----
===== Next Steps =====
The script can be modified as needed for your project.
For more information on WaveForms SDK, see its [[software:waveforms:waveforms-sdk:start|Resource Center]].
For technical support, please visit the [[https://forum.digilentinc.com/forum/8-test-and-measurement/|Test and Measurement]] section of the Digilent Forums.