Effortless Weight Measurements: How to Read Scale Values With Python and Dymo M5/M10 Scales on Windows

by FuzzyPotato in Circuits > Computers

1044 Views, 0 Favorites, 0 Comments

Effortless Weight Measurements: How to Read Scale Values With Python and Dymo M5/M10 Scales on Windows

DymoOverlay.png

Welcome to this instructable on reading scale values from Dymo M5 and M10 scales using Python!

The Dymo M5 and M10 scales are reliable devices used in various applications. With the power of Python, you can tap into these scales and retrieve weight readings programmatically.

In this tutorial, I'll walk you through the process of connecting your Dymo scale to Python and extracting weight measurements effortlessly. We'll cover hardware and software requirements, provide step-by-step instructions, and share code snippets to read scale values like a pro.

By the end of this instructable, you'll have the knowledge to leverage Python and your Dymo scale, making weight measurements a breeze. So let's dive in and discover the magic of reading scale values with Python!

Supplies

To read scale values from a Dymo M5 scale using Python, you'll need:

  1. Dymo M5 or M10 scale
  2. USB Type A to Type B Cable
  3. Windows computer with Python installed
  4. IDE (I'm using PyCharm)
  5. PyUSB library

With these supplies, you're all set to dive into the process of reading scale values programmatically. Let's get started!

Setup the Backend

Filter wizard.PNG
Filter Wizard Start.PNG
Filter Wizard Device.PNG

We will start by setting up the backend and then move on to installing the PyUSB library.


  1. Install libusb-win32: Download and install the libusb-win32 (https://sourceforge.net/projects/libusb-win32/) backend on your Windows computer.
  2. Connect the USB scale: Plug in your USB scale to your computer using the USB cable. Make sure the scale is powered on by pressing the power button.
  3. Windows device detection: Windows should automatically detect the scale and install the necessary device driver. (You should see a popup that says something like "Dymo M5 device drive installing")
  4. Filter installation: Use the libusb-win32 Filter Wizard to install a device filter specifically for this scale. The Filter wizard should start automatically but if it doesn't you can search for Filter Wizard in the search bar (See image). In the wizard, you'll see an entry in the list that looks like "vid:0922 pid:8003 rev:0100 USB Input Device" - select it and proceed with the installation. (See Image)


By following these steps, you'll have libusb-win32 installed, the scale connected to your computer, and the appropriate device filter in place.

Install the PyUSB Library

Install Library.PNG

Now that we have set up the backend let's install the PyUSB library. This library provides the necessary tools to establish a serial connection and retrieve scale values.


  1. Open the pyCharm development environment (IDE).
  2. Navigate to File>Settings>Project>Python Interpreter
  3. Install the PyUSB library. (See image)
  4. Wait for the installation process to complete. You should see a message indicating a successful installation.


With PyUSB installed, we are now ready to write the Python code to read scale values from the Dymo scale.

The Code

Now that we have the PyUSB library installed, it's time to write the Python code that will allow us to read scale values.


  1. Create a new Python script.
  2. Copy and paste the following code:


import usb.core
import usb.util
import time

VENDOR_ID = 0x0922
PRODUCT_ID = 0x8003
MAX_ATTEMPTS = 10


def find_device():
device = usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID)
while device is None:
print("Searching for device...")
device = usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID)
return device

def read_data(device, endpoint):
attempts = MAX_ATTEMPTS
while attempts > 0:
try:
data = device.read(endpoint.bEndpointAddress, endpoint.wMaxPacketSize)
grams = data[4] + (256 * data[5])
print(str(grams) + "g")
return
except usb.core.USBError as e:
device.set_configuration()
attempts -= 1
print("Failure! Attempts left:", attempts)

time.sleep(1)

print("Failed to connect")

device = find_device()
device.set_configuration()
endpoint = device[0][(0,0)][0]

while True:
read_data(device, endpoint)


With the Python code to read scale values from the Dymo M5 scale in hand lets proceed to the last step.

Reading the Scale

WeightCapture.PNG

It's time to execute the code and see the weight values in action!. Follow these steps:


  1. Make sure your Dymo M5 scale is connected to your computer via the USB cable and turned on.
  2. Run the code
  3. The script will start running and weight values read from the Dymo scale will display on the console.
  4. Keep an eye on the console to see the live weight values. You can weigh different objects on the scale and observe the changes in the displayed weight.


Congratulations! You have successfully executed the Python code to read scale values from a Dymo scale. You can now incorporate this functionality into your projects or further enhance it as per your requirements. Happy weighing!