Tuesday, November 20, 2012


We used to have an old bar as our dining table. It kind of came about by chance. It wasn't designed for that and was a bit of pain to use - not much overhang meant you couldn't get your knees under. But we liked the height.

When thinking about a replacement, I thought of making the underside more functional too.

Why not put a chest freezer under there to hold our beer? An upgrade from the 2-keg system we had would also be welcome. Chest freezers are great for the job - they are well insulated and when you open the lid, you don't let all the cold air out.

So in early 2011 I got a new chest freezer, built a collar, a bigger 4'x4' birch hardwood table top and installed our taps.

I built up a temperature controller to maintain the beer temperature (turn off before freezing).

All good. Only problem was it quickly accumulates junk, so often it isn't opened easily. Which makes checking beer levels harder.

There is nothing worse than running out of beer.

So I started scheming on ways to detect the beer level in the kegs.

The method I decided on was to weigh each keg.

I had seen a hack online where a guy had modified his bathroom scales to log his weight each time he got on. I think the hack involved wiring the display output to a micro controller.

I got a $15 set of bathroom scales thinking I could do the same. But the scales I had only turned on when you got on, and first needed to calibrate itself with no weight on it. Not so good for continuously weighing the kegs.

So I started to poke around the load cells it used. It had one in each corner. They seemed to be 3-wire units setup as a 2 wheatstone bridges. But they also seemed pretty insensitive. I could only get a single load cell to give a 0.5 mV change with the weight of a full keg when driven at 10V.

I originally hoped that I could use one load cell from each corner of the bathroom scales for each keg. But that signal was just too small. The gain needed would make the amplifiers unstable and susceptible to noise.

I ended up using 2 load cells for each keg, in a wheatstone bridge (so about 1mV signal at full deflection) and some INA129 instrumentation amplifiers setup with a gain of about 2000.

The circuit consists of + and - 5V regulators supplying the load cells and amps. Each amp has a low pass filter and diodes to clip the signal to 0-3.3V to keep the micro controller happy.

The display is a pretty simple bar graph and estimation of the amount of beer left.

Finally a demo of it in action:

Thursday, October 25, 2012

STM32 LCD touch screen demo

[Update: Torrent available for downloading the Virtualbox image ]

You see many hobby projects use the good old 16x2 LCD.

Pretty easy to use. But limiting. No graphics. Limited text. Hard to have a very complicated UI. You need some other device for input - push buttons usually. Unintuitive.

In a word: ugly.

Most consumer devices these days include a graphical LCD and touch screen interface. People understand how to use them. People expect them.

So I started to get away from 16x2 LCDs in my projects.

Fortunately 320x240 LCDs with touch screen and micro controller can be had cheaply on ebay. So I have been using them for my projects.

I have a some friends who have started using these boards or expressed interest in using them. Now they are ARM based and can be tougher to bring up that an Arduino. So I have decided to make a downloadable VirtualBox image that has the toolchain and environment setup, with a demo project, that includes a simple menu system. This should help people get started with these boards.

Which boards?

ebay auctions expire all the time, so it's hard to link to specific boards. Instead take a look at a search:


Look for the ones that are clearly 2 boards - the LCD board on top. CPU is usually a STM32F103.

The first sort of board has a 2.4" LCD:

The second has a 3.2" LCD:

Both LCDs are the same resolution, but I prefer the 3.2", it's substantially bigger (and so buttons will be bigger for fingers to hit).

However the board with the smaller LCDs have other goodies, like 16MB flash, speaker and RS232.

You can take a look at the schematics for each:

Either way, LCD + touch screen + STM32 CPU for less than some Arduinos cost.

STM32 CPUs are significantly more powerful than the trusty old Atmels (Arduinos).
 Your code may have a main task to accomplish, and then the LCD+touch UI to look after. Programming to bare metal, this can be tricky to pull off. Why not use a multi-tasking OS to help?

FreeRTOS to the rescue. Go read the 5 or so pages here for a good overview of how it works:


So then how to get started?

I have put together a VirtualBox image you can download that contains:

  • Ubuntu desktop
  • ARM toolchain (gcc + newlib)
  • Eclipse C++ IDE
  • stm32loader.py - for loading code into the board
  • openocd - for loading code and debugging
  • Example FreeRTOS project with all source code, include LCD+touch drivers and a simple menuing system to get you started quickly


Getting started

Download the virtual box image: https://www.dropbox.com/s/rkpiq3wa1jfnof9/ubuntu_stm32.7z


(~800MB download, ~3GB disk space uncompressed)

Login/password: ubuntu/reverse

Install virtualbox if you don't already have it: https://www.virtualbox.org/

You will need 7-zip to uncompress the image: http://www.7-zip.org/

Create a new virtual machine in the Virtual box manager. Give it a gig or ram or so. Select "Use existing hard disk", and choose the ubuntu image. Boot it up.

Building and running the demo

Demo menu code walk through

Loading code

The ARM Cortex M3 chips have a built in bootloader that allows you to load code over the serial interface.


You need to boot the device with the boot0 pin grounded. Most dev boards have a switch or jumper.

This can become pretty tedious so it's worthwhile to get a JTAG programmer - you can then load your code faster, without touching the board. You can also run openocd and gdb to help debug your code.

I use and recommend a bus blaster:


OpenOCD config files are included in the JTAG directory in the Virtalbox Image.

You will also probably need a 20 pin JTAG cable.

printf debugging

gdb & JTAG debugging

Boot, FreeRTOS and the LCD - how it comes together