Reading a USB Stamps.com scale
Friday, 15 January 2010
Update: I now have an improved C version of this program: usbscale.
I got suckered into one of those hard-to-cancel Stamps.com trials. The upside is that they give you a $10 USB 5 lb. scale to use with their software. The downside is that they want you to only use it with their software, and the company that makes the scale has since taken down their free USB-scale program.
The good news, as Nicholas Piasecki and some Linux users figured out, is that the USB scale conforms to the USB HID specifications, which helpfully standardize how USB scales should work (no joke).
So, this little Perl hack reads from the Stamps.com scale by accessing the hidraw#
interface that Linux provides. In my case, I have hidraw4
hard-coded into the script itself. Basically, it loops until it reads a good value from the scale, at which point it prints out the weight and exits.
Edit: This code is now a Gist on GitHub.
[perl highlight=”14″]#!/usr/bin/perl
# I hereby release this script into the public domain.
use bytes;
my $data;
#prevents us from repeating messages
my $waitingflag = 0;
while (1) {
$data = `cat /dev/hidraw4 | head -c 7`;
my $report = ord(substr($data, 1, 1));
my $status = ord(substr($data, 2, 1));
my $unit = ord(substr($data, 3, 1));
my $exp = ord(substr($data, 4, 1));
my $lsb = ord(substr($data, 5, 1));
my $msb = ord(substr($data, 6, 1));
my $weight = ($msb * 255 + $lsb) / 10;
if($exp != 255 && $exp != 0) {
$weight ^= $exp;
}
#print "$report $status $unit $exp $weight\n";
if($report != 0x03) {
die "Error reading scale data!\n";
}
if($status == 0x01) {
die "Scale reports FAULT!\n";
} elsif ($status == 0x02 || $weight == 0) {
if($waitingflag != 0x02) {
print "Zero’d…\n";
$waitingflag = 0x02;
}
} elsif ($status == 0x03) {
if($waitingflag != 0x03) {
print "Weighing…\n";
$waitingflag = 0x03;
}
} elsif ($status == 0x04) {
my $unitName = "units";
if($unit == 11) {
$unitName = "ounces";
} elsif ($unit == 12) {
$unitName = "pounds";
}
print "$weight $unitName\n";
last;
} elsif ($status == 0x05) {
if($waitingflag != 0x05) {
print "Scale reports Under Zero…\n";
$waitingflag = 0x05;
}
} elsif ($status == 0x06) {
if($waitingflag != 0x06) {
print "Scale reports Over Weight!\n";
$waitingflag = 0x06;
}
} elsif ($status == 0x07) {
if($waitingflag != 0x07) {
print "Scale reports Calibration Needed!\n";
$waitingflag = 0x07;
}
} elsif ($status == 0x08) {
if($waitingflag != 0x08) {
print "Scale reports Re-zeroing Needed!\n";
$waitingflag = 0x08;
}
} else {
die "Unknown status code: $status\n";
}
}[/perl]
No. 1 — June 10th, 2010 at 21:42
Well done! Thanks!
No. 2 — June 12th, 2010 at 17:45
Hi,
I am not a programmer. Can you share your knowledge of running this on Windows?
Thanks in advance!
No. 3 — June 12th, 2010 at 18:12
This script will not run on Windows. Buy Elane’s official scale program instead: http://www.elane.net/index.php?go=USB_pcsoftware
No. 4 — October 3rd, 2010 at 16:29
Thanks very much! I got suckered into the same deal. I’m happy that I can actually use the scale now.
No. 5 — February 12th, 2011 at 00:09
Hi!
I created a warning system for our office coffee pot using your script so I thought a thanks would be in order.
Also it was posted to a perl mailinglist by someone other than me, and they made some suggestions for simplifying the code (and corrected a bug I added): http://www.perlmonks.org/?node_id=886566
Check it out at http://graph.no
I referenced your blog and github in the source/references.txt link at the bottom.
No. 6 — July 19th, 2012 at 14:59
I wanted to contribute images of the controller board internal to the Stamps.com 5lb scale. I cannot find any information on it, but it might be useful to someone down the road.
Serial: EL100906A SDC5DICE REV3A
Barcode: 804434
Top:
http://i.imgur.com/RRbjV.jpg
Bottom:
http://i.imgur.com/oTcxz.jpg
-Tres
No. 7 — August 31st, 2012 at 17:06
Interesting! Thanks for sharing! I don’t know enough to learn much from seeing this, but maybe somebody else will.
No. 8 — March 5th, 2014 at 16:45
Hi Eric,
you said “and the company that makes the scale has since taken down their free USB-scale program” – can you pls provide the name of the company that makes the scale / link to their site?
Thank you
No. 9 — March 7th, 2014 at 01:05
Elane is the company that makes the scale (at least the LCD-less one that I have). You can check them out at http://www.elane.net/
No. 10 — September 26th, 2015 at 06:32
You can zero out a stamps.com 550 scale by sending a 0x04 and 0x01 to it.
No. 11 — September 16th, 2023 at 21:16
Thanks Eric! Great work and it is still fun to hack the machine. I really appreciate the code and your hard work. Wish you all the best!