Adding a display to a digital scale using Arduino and USB Host shield

By Oleg Mazurov

Arduino reading digital scale

I am the proud owner of Stamps.com Model 510 5lb digital scale. It is a nice little scale which works very well (much better than Stamps.com service itself) while attached to my workstation. The scale doesn’t have a display making any kind of standalone use difficult. However, since the scale is a USB HID device reading data from it should be as easy as from a joystick and Arduino board should be adequate to provide a display function for it. To test this theory I made a simple setup consisting of Arduino UNO, USB Host shield and HD44780-compatible LCD display. I also wrote a small sketch which polls the scale and outputs the weight. The secondary objective of this project was to demonstrate LCD support in USB Host shield library.

For this project I used the following:

An Arduino board. Standard size board, such as UNO, Duemilanove or Leonardo, will work

Toshiba HD44780-compatible LCD display, in 16×1 or 16×2 configuration. If you’re planning to use this sketch for something else, like data logging, the display is optional – all output from the scale is repeated to the serial port

Stamps.com 5lb digital scale. Scales are standard HID devices with usage table 0x8d, therefore, scales from other brands may work as well with no or minimal modifications to the code

The example code is also hosted at github, as well as in ‘examples’ section of the library under ‘HID’. It has been tested with Arduino IDE version 1.0.5.

In this project, the LCD is connected to the shield’s GPOUT pins, as documented in max_LCD.h header file. In addition to data lines, 5V and ground must also be connected to the shield’s 5V and GND terminals; the RW pin must be grounded – I do it on the LCD itself. In order to see the characters, the display must be biased – a 5K-10K pot with wiper on Vo and other two pins on 5V and ground will provide contrast adjustment.
Now it’s time to load a sketch, connect the scale to the USB port of the shield and open a terminal. If everything is good, the following will be printed:

Start
Weight: 0.00 oz

If a LCD is (properly) connected, similar information will be output to it also.

In addition to the weight, several diagnostic messages will be printed, indicating, for example, excessive weight. Below, I’m placing several books on a a scale, one by one, until a limit is reached:

As I said before, the scale is a HID device and it works similarly to any other HID device – after initialization it starts responding to requests from the host reporting its state. The code is very similar to one written to poll a Logitech joystick, the main differences being (obviously) report data structure and parsing as well as using an LCD for the output along with the terminal.

I recently started a github repository containing USB device traces. If you’re curious about the protocol details, this trace contains scale initialization performed by a Windows 7 PC, as well as report polling. For the rest, the HID support in the library is designed in such a way that almost everything happens automatically, the only device-specific piece of code being the parser. Let’s go through the steps to change a joystick parser into a scale parser.

The scale report is 6 bytes. Below is a report returned by empty scale. The meaning of the bytes, from left to right, is as follows:

The first line instantiates a LCD class and it is always defined like that. Second line instantiates ScaleEvents – the class where the most important method OnScaleChanged() resides. A pointer to LCD is passed to it. The last line define a report parser instance and pointer to ScaleEvents is passed to it.

The following statement inside a setup() links report parser to the HID driver. It is the last link in the chain – from this point, everything just starts working.

For better understanding I suggest opening the joystick code mentioned in the beginning of the article and compare it to the scale example. Don’t try to understand every line, just pay attention to code elements explained above. If anything in the code is not clear please leave a comment and I’ll try to explain it better.

17 comments to Adding a display to a digital scale using Arduino and USB Host shield

Hi, Oleg
Have you ever provided some sketches that support more than 1 HID devices at same time? E.g. 1 Barcode scanner and 1 keyboard, which works great individually, but not works normally when together.

The Usb.Task() does the polling, OnScaleChanged() will be called if scale state changes. In general, scales are slow devices so one reading every 1-2 seconds is probably the fastest rate you can expect.

I had just purchased a USB Host Shield 2.0 via Citibank credit card. Your webpage keep complaining that my billing address does not match billing address of cardholder, which is definitely not the case. I received SMS from Citibank informing me the transaction is successful, so I am not sure what to do now, did I get the item purchased successfully?

I already sent an email with details of transaction but no reply after 5 days. Sorry to post it here.

I’m sorry you’re having troubles. I have 2 questions:
a) Was it a US credit card? International credit card transactions don’t work very well, try using Paypal instead. If you believe your card has been charged, get the transaction number from your bank so I can investigate it on my side
b) What was the e-mail address you’ve sent the details to? Try one you received the registration info from or one listed in the “About” section.

Anyway, so far the credit card doesn’t show any sign of being charged, I just received the SMS but does not see it get billed. I will contact you if it really get charged. I had purchased another set via TKJ electronics, and it works well. Thank you very much for the reply.

And as soon as i post i spot my error.. DOH! under 10kg the weight is less than 6 bytes, which throws out the further mapping
As my input is a string could i get away with..
struct ScaleEventData
{
char8_t[howeverlong] scaleReport
};

the mass value is the key data but also other aspects such as its stability and error status will be queried eventually.
for now it will be good to get data out i initially overlooked the master slave aspect of the usb protocol as its just a medium for peer to peer serial connections,, Whoops! Yes i had a usb header wired upto Rx1 and Tx1 on a mega board for a few evenings 😉

Its all for semi automation of a nano brewery, heating and transfering specific masses of liquor thru the 3 vessel system on schedule.
the scales will sit under the second vessel measuring the mass both in and out.