Saturday 30 May 2015

Arduino USB Host and SMTech DM620 with Datalogging

Summary
The requirement for this project is to use an Arduino (Atmel micro) to trigger the data logging feature on a digital multimeter (DMM).

For this project the DMM, SMTech DM620, is a device sold in Australia by the usual retail suspects such as Altronics - Q1198. There are a plethora of alternative low cost DMM's, less than AUD $150, with Bluetooth or wireless USB interfaces such as this device from Jaycar - QM1575 with would suit similar data logging applications.

In this project the Arduino will serve as a USB Host in order to control the functions on the DMM. There are always other solutions, especially with the latest DMM's which support Ethernet, however legacy equipment such as this DMM, can become an exciting challenge.

DMM620 Digital Multimeter with Logging
DMM620 Digital Multimeter with Logging

In the USA, companies such as CircuitSpecialists have sold this DMM in the past however it appears that the unit has become obsolete or is no longer available - http://www.circuitspecialists.com/dm620.html

Lets Begin...
Starting out the first step is to determine if the USB communications protocol between the DM620 and the corresponding PC software is open source (unlikely) or has already been dismantled by checking the many web hosted repositories such as CodeBender, GitHub and so on. Turns out lamentably not. 

Therefore the USB communications can be monitored using a software monitoring package such as USBTrace from SysNucleus http://www.sysnucleus.com/ or USBlyser of the same company - http://www.usblyzer.com/. The control codes can then be acquired and used to configure the DMM from the Arduino. Software of choice is installed and DMM hardware setup including USB cables fitted.

As with any new tool, in this instance USBTrace, it's valuable to become familiar with its features, quirks and operation.

USBTrace Screenshot
USBTrace screen shot

USBTrace has an easy to use tree structure interface, as shown in the screen shot above. By plugging and unplugging USB devices from the computer the tree updates along with brief description of attached device. This can be used to assist in identifying where the DMM is on the tree.

Across the top of the USBTrace window is the application toolbar for performing the important functions of Start, Stop Capture and Export.


USBTrace Toolbar
USBTrace Toolbar

After performing a few logs of USB devices, the logging USBTrace format is quite clear, so the DM620 software can be installed. The install files are available in the downloads section on the following websiteQ1198 


LoggerDMM Software screen shot
LoggerDMM Software screen shot

The installer will grace a Windows computer with the software - LoggerDMM.exe (software), a screenshot of the running application is shown above. Note that on the same website is a user guide to read through, although the software is relatively easy to use. For the purposes of this project only the data logger mode is required to log the DC voltage of solar panels across the day, however for completeness all the modes and ranges will be captured.

With the DMM software running, USB cable plugged into the DMM and computer, DMM powered the Link button in the PC software can be clicked to verify operation.


DMM620 Display (USB connected)
DMM620 Display (USB connected)

When a connection is established the DMM will indicate a connection in the top right hand corner of the DMM's display.

With USBTrace running and the Link button selected in the DMM software, clicking on various buttons in the software will show data exchanged on the USB. USBTrace shows this data as a bulk or interrupt type which are two of the four types of transfer. To get deeper into the USB protocol, some six hundred pages, the standard is available at USB.org - http://www.usb.org/developers/docs/  

Beginning with clicking the Link button ON the first packets can be observed.


USBTrace Capture of DMM620 Communications
USBTrace Capture of DMM620 Communications

Working from the top down of the software log the first Input/Output (IO) exchange is an output to the DMM. Selecting a line at a time, the buffer is displayed in the bottom section of the window in Hex and ASCII. For readability the window can be undocked and resized.


USBTrace Buffer Out Capture
USBTrace Buffer Out Capture

Looking at the outgoing data as Hex the first character is 02, representing ASCII Start of Text. The data of interest is followed by an End of Text, 03. As a reference for ASCII codes see - http://ascii-table.com/ascii.php. The outgoing USB packet together with the question marks that appear at the end of the ASCII commands or functions, seems to indicate a request for the DMM's configuration.

Now selecting the first incoming line of data shows values of interest. These would appear to be the enumerations for the various commands or functions of the DMM.


USBTrace Buffer In Capture
USBTrace Buffer In Capture

Recording the logged ASCII values sent from the DMM software for each Function, Range of that function, Mode and so forth allows a function table to be built. 

The next USB packet out shows additional functions, this time the ASCII is capitalised indicating requests are made in this format.


USBTrace Buffer Out Capture
USBTrace Buffer Out Capture

Clicking the next logged incoming data provides some meaningful information also. The reading of 0.40mV matches the current Relative Reference shown on the DMM display.


USBTrace Buffer In Capture
USBTrace Buffer In Capture

So the Link connect operation to the DMM has been recorded. Link disconnect and all the remaining DMM functions can be recorded using the same capture and interrogate method with USBTrace.

Command: Open Link to DMM
Upon opening a link the DMM software requests the current settings on the device:

     02 46 55 4E 3F 3F 2C 52 47 45 3F 3F 2C 4D 4F 44 3F 3F 2C 48 4C 44 3F 3F 2C 50 53 54 3F 3F 03

     STX FUN??,RGE??,MOD??,HLD??,PST?? ETX

Note that there are no spaces after the STX and before the ETX ASCII codes as shown above, this is added for readability throughout the blog. The comma separation between commands is correct.

At this stage its important to note that the commands are not completely understood. Comparing the three letter abbreviation sent between the software and the DMM against the software an educated guess can be taken, giving:

     FUN - Function

     RGE - Range
     MOD - Mode
     HLD - Hold
     PST - Paused

So in response the request for the current settings the DMM responds with:

     02 66 75 6E 30 30 2C 72 67 65 31 31 2C 6D 6F 64 30 32 2C 68 6C 64 30 30 2C 70 73 74 30 30 03

     STX fun00,rge11,mod02,hld00,p00 ETX

The second request from the software is:

     02 50 52 56 3F 3F 2C 50 53 54 3F 3F 03

     STX PRV??,PST?? ETX

In response the DMM sends:

     02 70 72 76 2D 20 20 30 2E 34 30 6D 56 64 63 03

     STX prv-  0.40mVdc ETX

So does this translate into what needs to be sent from the USB Host, certainly does, with some further prodding and poking.

Command: Changing DMM Modes
With an open Link to the DMM, each of the modes are selected and the outgoing MOD recorded giving:

     MOD00- Data Logger

     MOD01 - Record Mode
     MOD02 - Relative Mode
     MOD03 - Compare Mode
     MOD04 - Trend Plot

The DMM responds to the mode change with an acknowledge packet and also sends a second packet to read any applicable settings. The first response is a confirmation:

     02 06 03

     STX ACK ETX

The second packet sent from software to the DMM requests any additional data applicable to the mode that was selected. For the Datalogger this response is comprised of three parts:


     STX plv060,00000,09999 ETX

Looking at the ASCII there is the start and end of text wrapping the sample time, start and stop address. These settings can be seen when pressing the Set button of the DMM. The range of the settings are as follows:

     Sample Time: 1 - 999s
     Start Address: 00000 - 17000
     Stop Address: 00000 - 17000

For Record Mode there are no parameters to be configured. There is however the option to read the status of the Pause button.

     STX pst00 ETX

In the response shown above the Pause button is off, pst01 indicates that the Pause button has been activated.

Next is Relative Mode which contains a single setting as seen in the response below.

     STX prv-  0.00mVdc ETX

 The range of the settings are as follows:

     Reference: -4999.9V - 4999.9V

In the response shown above the prv represents the relative reference value in millivolts.

The Compare Mode allows two settings to be set, HI and LO limit.

     STX pcv 100.00mVdc, 100.00mVdc ETX

 The range of the settings are as follows:

     HI Limit: -4999.9V - 4999.9V
     LO Limit: -4999.9V - 4999.9V

In the example above the pcv DMM response shows the settings.

Lastly the Trend Mode contains three settings, a reference value, vertical axis in volts/div and the horizontal axis in seconds/div.


     STX ptv 100.00mVdc, 100.00mVdc,000 ETX

The range of the settings are as follows:

     Reference: -4999.9V - 4999.9V
     V/Div: -4999.9V - 4999.9V
     H/Div: 20S - 10Hr

In addition to the second packet request and responses, there additional buttons for some modes. Data logging for example, contains Start, Recal, Clear and Setup buttons on the DM620. These will be captured later on.

Command: Functions of the DMM
Onto the measurement type (function), which will be investigated while the DMM is in Relative Mode.

Requesting the DMM DV Volts (DCV) function from the software results in three requests by the software. The first is the setting of the Function from the software:


     STX FUN00 ETX

Reply from the DMM is:

     STX ACK ETX

The second packet is the Mode set:


     STX MOD01 ETX

Reply from the DMM is:

     STX ACK ETX

The last packet is the Pause button status:

     STX PST?? ETX

The reply from the DMM is the devices status, in this instance OFF:

     STX pst00 ETX

Repeating the operations above for the other functions on the DMM produces the list below:

     FUN00 - DC Volts
     FUN01 - AC Volts
     FUN02 - Ohms
     FUN03 - Beep (Continuity)
     FUN04 - Diode test
     FUN05 - Capacitance
     FUN06 - DC milliamps
     FUN07 - DC Amps
     FUN08 - AC milliamps
     FUN09 - AC Amps
     FUN10 - Frequency
     FUN11 - Period
     FUN12 - Duty
     FUN13 - Temperature

In addition, any other request and reply packets are captured for each of the functions listed above.

There are now a number of request and reply packets that can be formatted into more meaningful data. This can assist when writing code. To start, the packet requests and replies exchanged between the software and the DMM are separated into individual requests and replies. The request and sets commands for Mode and Function are shown below.


DMM620 Mode Commands
DMM620 Mode Commands

DMM620 Function Commands
DMM620 Function Commands

DMM Acknowledge
DMM Acknowledge

Continuing with the protocol there are several additional commands including the hold, function buttons, DMM date, time and termination of the link between the DMM and software.

Command: Close Link to DMM


USB Host Terminate Link Command
USB Host Terminate Link Command

Termination of the USB connection, using the GTL command from the DMM software, is similar to the other commands previously listed in that the DMM will send an acknowledge command.

It is also important to note that the DMM software is programmed to send the correct combination of commands meaning a negative acknowledge is never seen in the messages. The NACK should be tested for and trapped in the software if it is used by the DMM.

Arduino Uno with USB Host
Instead of developing a PCB for this once off task, the USB interface can be realised with off the shelf hardware. For this project an Arduino Uno and a Sparkfun USB Host shield can be coupled with ready to go software.

Arduino Uno with USB Host Shield
Arduino Uno with USB Host Shield

Pictured above is the Sparkfun USB Host shield plugged into the Uno with the obligatory Pin 7 Reset Input linked to the Reset line. This link is required to drive the reset input on the 74HC4050.

There are a number of USB Host shields such as the boards from Oleg Mazurov from Circuits@Home. Thanks to Oleg for the new revision 2.0 of the USB host library, this will be used along with the latest Arduino 1.6.5 software. By using the Arduino Library Manager, the USB Host library can easily be downloaded and installed into the Arduino software.

Arduino USB Host Shield Library
Arduino USB Host Shield Library

DM620 USB Device Manager Details
Before connecting the DM620 to the host shield, select the DM620 in Device Manager, Human Interface Devices (HID) on the PC. By using the Properties, Details buttons and then selecting Hardware ID's from the drop down list box some basic information for the DM620 can be collected. This information, Vendor ID (VID) and Product ID (PID) can be used to verify the USB Host shield connection.

DM620 in Device Manager, Details, Hardware ID's
DM620 in Device Manager, Details, Hardware ID's

DM620 Arduino USB Details
After the USB Host Shield is installed, there are a number of example sketches to choose from. In order to verify the USB VID and PID, the sketch USB_desc under the USB Host Shield Library 2.0 examples can be used.

Arduino sketch with USB_desc
Arduino sketch with USB_desc

The sketch is compiled, DM620 is connected to the USB shield and the program run.

DM620 to USB Host Shield
DM620 to USB Host Shield

From the Arduino terminal the relevant information, PID and VID, are shown at the top of the window. Device identification through USB communication appears to be running therefore some initial test code can be implemented.

Arduino Terminal Window
Arduino Terminal Window

Due to a number of reasons this post was stopped, hopefully some of the information can be useful to anyone attempting a similar interface.