MP730026 Python BLE Tutorial

 

At a glance, the Multicomp Pro MP730026 seems like a typical DMM. And it is! It measures voltage, current, frequency, temperature (with included K-Type thermocouple), and even features a white LED to act as a work light. The non-typical feature that caught my attention is its Bluetooth Low Energy (BLE) support.

 

Overall I like the meter. It is an excellent general-purpose DMM. After using it for a couple of months, I have discovered only three things I dislike about it. The first is that it has no min/max function. The second is that it beeps loudly before turning off. My personal preference would be for it to shut itself off quietly. Neither of these is a dealbreaker, but you should be aware of them. The last one is a more significant issue. The compelling BLE capability I mentioned one paragraph ago is barely functional out-of-the-box. However, I found a solution!

 

The software provided by Multicomp Pro is disappointing. It only works with Windows and a very specific BLE dongle. My search for a cross-platform solution leads me to a Python-based solution. Thanks to a module called Bleak, it is possible to communicate with the MP730026 DMM on practically any BLE-compatible computer. I have had success on a Microsoft Surface Book, two Macs, a Raspberry Pi, and even an Arduino BLE Sense.

 

In this post, I take you through the steps to use the attached python files to connect to the Multicomp Pro MP730026. Part two of this post digs deeper into the data the meter sends. Let's get started by making sure you have Python 3.7.

 

Step 1, Install Python

For Linux and macOS, installing Python should not be a significant issue. Both operating systems probably already have a version of Python installed. Before moving forward, verify which version of Python is in your path.

python --version

If you don't have Python 3.7 or higher, use your distribution's package manager to install it. If you are on macOS, I suggest installing it using homebrew.

 

Windows

Windows users can install it from the Microsoft Store. However, I downloaded my copy from python.org and placed it in C:\python37. Another option is Cygwin. At first, I tried to work exclusively within Cygwin, but found some issues with libraries accessing the correct Windows APIs. So, I ended just using Python "natively" in Windows. Just like with the UNIX-based operating systems, the most important aspect is knowing which version of Python is running in your path.

 

Of course, in all three cases, you can explicitly state where 3.7 is with the first line of the script. Next up is the module we need.

 

Step 2, Install Bleak

The magic module that makes this all work is called Bleak. Despite having a negative sounding name, it is a fascinating project. There is a "front end" API that works with Python and a "back end" module that communicates with the operating system. From a programming point-of-view, your code does not care which backend Bleak picks. (There is one exception for macOS.)

 

The Python package installer, PIP, simplifies Bleak's installation.

pip install bleak

 

If you have both Python 2 and Python 3 installed, you may want to make sure the Python 3.x installation does the install with this modification:

pip3 install bleak

 

Fortunately, across all of the platforms I tried, I had no issues running bleak. In the next section, we will use Bleak's scan example to find some critical information about your MP730026 DMM and to verify the software stack is working.

 

Step 3, Find DMM's MAC Address

The Media Access Controller address (MAC) is the first piece of data we need.

Enabling BLE on the MP730026

First, turn on the DMM and turn the selector to any mode. Enable Bluetooth by pressing and holding the Hz, Duty, Delta, Bluetooth button until the meter beeps. On the LCD's upper left-hand corner, the Bluetooth symbol starts blinking. When a device connects to the meter, the symbol stays on steady.

 

Next, run bleak-scan.py. (Script is attached to the bottom of this post.)

python bleak-scan.py

 

It may take up to 10 seconds before you see anything. If you do see a list of devices, it means Bleak and Python can talk to your computer's BLE API. If you are not able to connect, then look at the troubleshooting section below.

 

This code shows all of the BLE devices the OS can see advertising their services. The one you want is called "BDM."

pi@benchpi:~/ble-dmm $ python bleak_scan.py
# (this may appear to stall for a few seconds)
18:B4:30:6A:A6:E9: Nest Cam
A5:B3:C2:24:15:16: BDM
F8:04:2E:F9:FC:67: F8-04-2E-F9-FC-67
3C:0F:A2:4A:B4:EC: 3C-0F-A2-4A-B4-EC
59:EF:D5:73:6D:80: 59-EF-D5-73-6D-80
2C:41:A1:79:10:CF: LE-Bald Orange
68:9E:19:CB:D8:74: baldimeter"

 

Oh, look! One of my neighbors has a Nest Cam! Anyway, that is not what we need from this list. From the scan above, the MAC address for my Multicomp Pro MP730026 is A5:B3:C2:24:15:16. (Line 04.) The MAC for your DMM will be different, so make sure you copy it correctly! Save your MAC, we use it in the next script.

 

macOS does BLE addresses differently

On macOS, you do not use the MAC address of a device. For security reasons, macOS assigns a UUID based on the device's MAC. So when bleak-scan.py runs on macOS, the results look like the following table.

4B17AF6C-A341-476F-94D9-3B50F5AD7959: Unknown
59969AD0-ECF7-4049-96F0-4AF0181393FA: LE-Bald Orange
588672A4-C1E3-4AF7-A6D1-D1966015915C: Apple, Inc. (10065b1e41d181b3)
4DA7C422-D3DE-4AE5-AF14-CFEBDD3B85D1: BDM
76F009A7-8506-4FB8-9369-DE67A80A85EE: Hewlett-Packard Company (010001)

 

The UUID for the meter is still the entry named "BDM." In this case, 4DA7C422-D3DE-4AE5-AF14-CFEBDD3B85D1 is the identifier used in macOS. In the Python code, when you see a traditional MAC address, use this string instead. (In the comments, we can discuss the irony of Macs not using MACs correctly.)

 

Troubleshooting problems

If you run into problems with Python, here are some tips.

  • Verify the version of Python
  • Make sure the Bluetooth controller on your computer is enabled
  • Put the error into a web search

 

If you're not finding the "BDM" device:

  • Run the scan multiple times
  • Make sure the DMM's Bluetooth is still blinking
  • Change the order: run the script and then turn on the meter

 

Step 4, Subscribe to the Multicomp Pro MP730026

Edit the script mp730026_ble_subscribe.py. The address variable is defined near the top of the file. Change this line to match your DMM's MAC address.

# Change this to your meter's address
address = ("A5:B3:C2:24:15:16") # for Windows and Linux
#address = ("4DA7C422-D3DE-4AE5-AF14-CFEBDD3B85D1") # for macOS

 

Remember, macOS only has a UUID specified, instead of the MAC address.

 

This script using Python's asynchronous capabilities to react whenever a GATT message is available. Look for the line that says:

await asyncio.sleep(460.0, loop=loop)

 

The number in this call tells Python how long to run the loop. For initial testing, set that to a small value like 10-15 while you are testing. The example code uses asyncio to run a thread in the background that waits for a BLE message from the Bleak backend. When a new message arrives, the code in notification_handler runs. That function takes the bytearray received from Bleak and then decodes it into the DMM's display values.

python mp730026_ble_subscribe.py

 

Whenever any of the LCD's elements update, the meter generates a BLE message. Having some parts nearby to measure can be helpful. Or even just turning the mode selection knob causes many updates. If your computer is able to connect to the meter, the script prints the following.

pi@benchpi:~/ble-dmm $ python mp730026_ble_subscribe.py
Reading [DC Voltage]: -001.7 mV
Reading [DC Voltage]: -000.9 mV
Reading [DC Voltage]: 000.0 mV
Reading [DC Voltage]: 00.00 mV
Reading [DC Voltage]: 00.00 mV
Reading [Resistance]: O.L Ω
Reading [Resistance]: O.L MΩ
Reading [Resistance]: O.L Ω
Reading [Resistance]: O.L MΩ
Reading [Resistance]: 0.025 KΩ
Reading [Capacitor]: 00.00 nF
Reading [Resistance]: O.L Ω
Reading [Resistance]: O.L MΩ

 

Success! Python is able to connect to the meter and decode its display message. If you're getting error messages, then double-check that you are using your meter's MAC address and that all of the .py files attached to this post are in the same directory.

 

Deep dive on the decode

As the picture at the top implies, my favorite device to interface to the DMM is a Raspberry Pi. Keep this option in mind if your Mac or PC is having trouble connecting to the meter. A Pi with built-in Bluetooth works great! Now that you're communicating with the MP730026MP730026, check out the next part where I dig deeper into the decoding module.