This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
tutorials:learn:scale:index.html [2011/03/30 21:56] daigo |
tutorials:learn:scale:index.html [2016/01/28 18:05] (current) |
||
---|---|---|---|
Line 93: | Line 93: | ||
We like to use python for its cross-platform compatibility. You'll need to install **pySerial** extension to access the serial port. Under windows the **COM port **will be whatever the USB adapter shows up as or **COM1** or **COM2** if using the built-in ports. For Macs/Linux check under **/dev/cu* **or **/dev/ttyusb*** - or run **dmesg** after plugging in the adapter for hints about what the device is called | We like to use python for its cross-platform compatibility. You'll need to install **pySerial** extension to access the serial port. Under windows the **COM port **will be whatever the USB adapter shows up as or **COM1** or **COM2** if using the built-in ports. For Macs/Linux check under **/dev/cu* **or **/dev/ttyusb*** - or run **dmesg** after plugging in the adapter for hints about what the device is called | ||
- | <code C>SERIALPORT = "COM1" # this uses pySerial found here http://pyserial.sourceforge.net/# it currently exists for python 2.5import serialser = serial.Serial(SERIALPORT, 2400, timeout=1)while True:while True:x = ser.read()if (ord(x) == 13):breakstart = ord(ser.read()) # this is always 2 if the scale is on (i think - not totally sure what this is)mode = ord(ser.read()) # 176 = oz/lbs #192 = gramsnonce1 = ord(ser.read())nonce2 = ord(ser.read())if start != 2 or nonce1 != 128 or nonce2 != 128:continuevalue0 = int(ser.read()) # only used for lbs * 10value1 = int(ser.read())value2 = int(ser.read())value3 = int(ser.read())value4 = int(ser.read())if mode == 176: #ozweight = ((value0 * 10 + value1) * 16) + (value2 * 10 + value3) + (value4 * 0.1)unit = 'oz'elif mode == 192: #gramsweight = value1 * 1000 + value2 * 100 + value3 * 10 + value4 unit = 'g'print str(weight) + unit ser.close()</code> | + | <code python> |
+ | SERIALPORT = "COM1" | ||
+ | # this uses pySerial found here http://pyserial.sourceforge.net/ | ||
+ | # it currently exists for python 2.5 | ||
+ | import serialser = serial.Serial(SERIALPORT, 2400, timeout=1) | ||
+ | while True: | ||
+ | while True:x = ser.read() | ||
+ | if (ord(x) == 13): | ||
+ | breakstart = ord(ser.read()) # this is always 2 if the scale is on (i think - not totally sure what this is) | ||
+ | mode = ord(ser.read()) # 176 = oz/lbs #192 = grams | ||
+ | nonce1 = ord(ser.read()) | ||
+ | nonce2 = ord(ser.read()) | ||
+ | if start != 2 or nonce1 != 128 or nonce2 != 128: | ||
+ | continue | ||
+ | value0 = int(ser.read()) # only used for lbs * 10 | ||
+ | value1 = int(ser.read()) | ||
+ | value2 = int(ser.read()) | ||
+ | value3 = int(ser.read()) | ||
+ | value4 = int(ser.read()) | ||
+ | if mode == 176: #oz | ||
+ | weight = ((value0 * 10 + value1) * 16) + (value2 * 10 + value3) + (value4 * 0.1) | ||
+ | unit = 'oz' | ||
+ | elif mode == 192: #grams | ||
+ | weight = value1 * 1000 + value2 * 100 + value3 * 10 + value4 | ||
+ | unit = 'g' | ||
+ | print str(weight) + unit | ||
+ | ser.close() | ||
+ | </code> | ||
==== Larger scales ==== | ==== Larger scales ==== | ||
Line 132: | Line 160: | ||
- | ==== Downloads ==== | + | ==== Download ==== |
*[[http://www.adafruit.com/datasheets/HD-Manual.pdf|Manual for HD-150 ]](150 lb max scale) | *[[http://www.adafruit.com/datasheets/HD-Manual.pdf|Manual for HD-150 ]](150 lb max scale) | ||
*[[http://www.adafruit.com/datasheets/7010SB_U.pdf|Manual for 7010SB]] (10 lb max scale) | *[[http://www.adafruit.com/datasheets/7010SB_U.pdf|Manual for 7010SB]] (10 lb max scale) |