commit
This commit is contained in:
parent
e61731dc50
commit
d9c7305cf8
6 changed files with 751 additions and 0 deletions
51
README.md
51
README.md
|
@ -1,2 +1,53 @@
|
||||||
# scale-code
|
# scale-code
|
||||||
|
|
||||||
|
USB ID: `1446:6a73`
|
||||||
|
|
||||||
|
A CLI utility in Go to read weight data from a Stamps.com USB postal scale via HID.
|
||||||
|
|
||||||
|
Originally developed to revive old electronics gifted by a family member. This project documents the quirks, bias, and calibration of the device for others interested in low-cost hardware reuse.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```sh
|
||||||
|
go build -o scale-code
|
||||||
|
sudo ./scale-code
|
||||||
|
```
|
||||||
|
|
||||||
|
The program continuously polls the scale and displays the weight in ounces, rounded to the nearest 0.1 oz.
|
||||||
|
|
||||||
|
You must run it as root (`sudo`) or use a proper udev rule to grant access to `/dev/hidraw` devices.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Calibration
|
||||||
|
|
||||||
|
### Observed Bias:
|
||||||
|
|
||||||
|
```
|
||||||
|
W = Stamps.com scale
|
||||||
|
WT = Taylor digital scale (Walmart, new)
|
||||||
|
|
||||||
|
Test object: consistent, arbitrary small item
|
||||||
|
|
||||||
|
W1: 1.9
|
||||||
|
W2: 1.9
|
||||||
|
W3: 2.0
|
||||||
|
|
||||||
|
WT1: 2.0
|
||||||
|
WT2: 2.0
|
||||||
|
WT3: 2.0
|
||||||
|
```
|
||||||
|
|
||||||
|
### Adjustment:
|
||||||
|
|
||||||
|
A linear correction factor of `0.952` is applied to compensate for the 0.1 oz low bias, yielding more accurate readings.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT License © firebadnofire 2025
|
||||||
|
|
||||||
|
FOSS, for the preservation of still-functional hardware and the freedom to study it.
|
||||||
|
|
5
go.mod
Normal file
5
go.mod
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
module archuser.org/scale-code
|
||||||
|
|
||||||
|
go 1.24.4
|
||||||
|
|
||||||
|
require github.com/karalabe/hid v1.0.0
|
2
go.sum
Normal file
2
go.sum
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
github.com/karalabe/hid v1.0.0 h1:+/CIMNXhSU/zIJgnIvBD2nKHxS/bnRHhhs9xBryLpPo=
|
||||||
|
github.com/karalabe/hid v1.0.0/go.mod h1:Vr51f8rUOLYrfrWDFlV12GGQgM5AT8sVh+2fY4MPeu8=
|
61
main.go
Normal file
61
main.go
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/karalabe/hid"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
vendorID = 0x1446
|
||||||
|
productID = 0x6A73
|
||||||
|
refreshRate = 500 * time.Millisecond
|
||||||
|
calibration = 0.952 // scale correction factor: 2.1 reported = 2.0 actual
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
devices := hid.Enumerate(vendorID, productID)
|
||||||
|
if len(devices) == 0 {
|
||||||
|
fmt.Println("❌ Scale not found.")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
device, err := devices[0].Open()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("❌ Failed to open scale:", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
defer device.Close()
|
||||||
|
fmt.Println("✅ Scale connected. Reading... (Ctrl+C to quit)")
|
||||||
|
|
||||||
|
c := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(c, os.Interrupt)
|
||||||
|
go func() {
|
||||||
|
<-c
|
||||||
|
fmt.Print("\n👋 Exiting.\n")
|
||||||
|
device.Close()
|
||||||
|
os.Exit(0)
|
||||||
|
}()
|
||||||
|
|
||||||
|
for {
|
||||||
|
buf := make([]byte, 8)
|
||||||
|
n, err := device.Read(buf)
|
||||||
|
if err != nil || n < 6 {
|
||||||
|
fmt.Print("\r⚠️ No data ")
|
||||||
|
time.Sleep(refreshRate)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
raw := binary.LittleEndian.Uint16(buf[4:6])
|
||||||
|
oz := float64(raw) / 10.0 * calibration
|
||||||
|
rounded := math.Round(oz*10) / 10
|
||||||
|
|
||||||
|
fmt.Printf("\r📦 Weight: %.1f oz ", rounded)
|
||||||
|
time.Sleep(refreshRate)
|
||||||
|
}
|
||||||
|
}
|
BIN
scale-code
Executable file
BIN
scale-code
Executable file
Binary file not shown.
632
stampscom.html
Normal file
632
stampscom.html
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue