==== Introduction ==== This tutorial will cover digital shipping scales! I know, exciting, right? But really, if you need to sense weights and get them into a computer or microcontroller, these are really easy to find, fairly accurate and easy to use. [[http://www.ladyada.net/images/scale/7010sbarduino.jpg|{{ http://www.ladyada.net/images/scale/7010sbarduino_t.jpg?nolink&500x364 |}}]] We use digital shipping scales for our shipping system (no surprise there!) - we weigh every package to make sure we are purchasing the right amout of postage. For postal, if we dont put the right postage on, the package can get returned or denied which is no good. We could try to approximate the weight from knowing whats in the order but packaging can vary - this way its always perfectly known when we buy the postage! ==== Smaller scale (0-10 lb) ==== For 99% of our packages, the weight of the box is under 10lb. So far we've found the **Salter Brecknell 7010SB** is a small, fairly well made scale. You can pick up the whole package for about $60-$70. This is actually a fair price, the accuracy ranges from 0.1 oz (for under 5lb packages) to 0.5 oz (for 5-10 lb packages). This is totally acceptable for shipping where under a few lbs, the postage is done by the oz and over 5 lb postage tends to be done by the lb. [[http://www.ladyada.net/images/scale/7010sbfront.jpg|{{ http://www.ladyada.net/images/scale/7010sbfront_t.jpg?nolink&500x330 |}}]] The scale comes with a wall plug and a serial cable. The plug has a 3.5mm 'audio' plug and the serial cable has only two conductors - ground and TX - connected to a 2.5mm audio plug. To use, simply power it up and plug the serial port to your computer. [[http://wiki.ladyada.net/adacomputer|We buy computers with COM ports built into them so that the COM port is fixed in hardware]], but [[http://www.adafruit.com/index.php?main_page=product_info&cPath=33&products_id=18|you can also use any USB to serial converter cable that will give you a USB plug]] [[http://www.ladyada.net/images/scale/7010sbplugs.jpg|{{ http://www.ladyada.net/images/scale/7010sbplugs_t.jpg?nolink&500x301 |}}]] If you are trying to connect to a microcontroller/microcomputer, you can use a male DB-9 and then use a MAX232 or similar to convert from the +-10V inverted serial that comes out of the cable and convert it to plain 3.3-5V TTL serial The bottom has two removable plates. One reveals a 9V battery (you can turn this into a portable scale but we think the 9V plug works best) and the other reveals some THM PCB. Not really sure what that's for but perhaps during test they use it? [[http://www.ladyada.net/images/scale/bottom.jpg|{{ http://www.ladyada.net/images/scale/bottom_t.jpg?nolink&500x385 |}}]] ==== Reading data from the 7010SB scale ==== Reading from the 7010SB is really easy, its just plain serial at 2400 baud 8N1 no flow control. The scale spits out data every 1/10 second so you just need to listen for the latest weight {{ http://www.ladyada.net/images/scale/2400b8n1.gif?nolink&455x594 |}} There are two possible formats for the data, one for each measurement scale. The second byte indicates what scale you are in ^ ^First^ ^ ^ ^ ^ ^ ^ ^ ^Last^ ^Lbs/Oz.| 0x02|**0x0B**|0x80|0x80|lb1|lb2|lb3|oz1|oz2|0x0D| ^Grams|0x02| **0x0C**| 0x80|0x80|g1|g2|g3|g4|g5|0x0D| ***STX** character - Hex **0x02**, indicates "Start of TeXt" *Scale indicator - Hex **0xB0** for lb/oz and **0xC0** for grams *Hex 0x80 (placeholder) *Hex 0x80 (placeholder) *First character of weight, ascii format *Second character of weight, ascii format *Third character of weight, ascii format *Fourth character of weight, ascii format - single Ounces in Lb/Oz weight *Fifth character of weight, ascii format - 1/10th Ounces in Lb/Oz weight *Finishing carriage return - Hex **0x0D** For example, if we are weighing a box that is **1 lb 4.1 oz** this is the output: {{ http://www.ladyada.net/images/scale/lbsoz.gif?nolink&455x594 |}} Note that the weight shows up in **ascii** character format (so its **0x31 0x34 0x31 **not **0x01 0x04 0x01**) If you need to convert to raw number, just subtract hex 0x30 Grams is a little simpler since its metric. It weighs about 390 grams {{ http://www.ladyada.net/images/scale/grams.gif?nolink&455x594 |}} You can see the 390 (385-395 g.) printed out. There is no fractional/decimals. ==== Code example for 7010SB ==== 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 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() ==== Larger scales ==== We also sometimes have to ship large packages, especially wholesale orders. In this case we use the larger floor scale. We think these scales are not suitable for shipping small envelopes because they have more error but for big boxes they are great! The scale we have is the **MyWeigh HD-150 **(about $120) which can do 0-150 lbs or 60 kgs. If you need even more you can get the HD-300 which can weight twice as much but unless you do freight its rare to ship packages over 50 or 75 lbs. [[http://www.ladyada.net/images/scale/hd150.jpg|{{ http://www.ladyada.net/images/scale/hd150_t.jpg?nolink&500x333 |}}]] It too comes with a power plug and a RS-232 serial port, you'll need a USB converter if you dont have a COM port on hand. For microcontrollers, a MAX232 or similar will be handy [[http://www.ladyada.net/images/scale/hd150port.jpg|{{ http://www.ladyada.net/images/scale/hd150port_t.jpg?nolink&500x265 |}}]] ==== Reading data from the HD-150 ==== The format of the HD-150 is different than that of the smaller scale. By default the scale is in **WorldShip** mode (a piece of UPS software). Its not a great format, and you need to press the **Data** button to have the transmisison occur. We suggest putting it into **SCI.3** mode which is continuous data transmission with higher resolution. Check the manual in the download section for how to get it into that mode You will then be able to read from the data stream at **9600** baud, 8N1 no flow control{{ http://www.ladyada.net/images/scale/mw150.gif?nolink&455x594 |}} As you can see the format is a little longer but its also human readable. ^First^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^Last^ |**:**|**W**|' ' or** '-**' |lb1|lb2|lb3|'.'|lb5|lb6|**l**|**b**|**S** if stable|**L** if lowbatt|0x0D| |**:**|**W**|' ' or** '-**' |kg1|kg2|kg3|'.'|kg5|kg6|**k**|**g**|**S** if stable|**L** if lowbatt|0x0D| Basically, its "**:W**" followed by a space or minus sign, then 3 digits of whole lb/kg, a decimal point and two fractional digits. The data format scale is indicated by two characters, **lb** or **kg'** and then two status characters that will indicate if the reading has **Stabilized** and if the battery/power is **Low** We don't have this scale with example code yet but you can probably adapt the python code above for the HD-150 or HD-300 without too much difficulty (and if you do please edit the wiki page to add it!) ==== Download ==== *[[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)