Digital Spirit Level


The digital spirit level was an A-Level Electronics project. It came from playing with accelerometers and wondering how accurately they could be used to sense orientation of a stationary object.

The project was designed to

  • Determine the angle of tilt of the device to ±0.1°
  • Be able to be calibrated to measure relative to a given surface.
  • Be accurate up to 30°
  • At power on, be automatically calibrated to a true flat surface

The system basically consisted of a three-axis accelerometer from Freescale, the MMA7260QT. This accel has sensitivity select pins allowing selection of 1.5g/2g/4g/6g sensitivity, but since this application is for a stationary system, the pins were hard-wired in the 1.5g setting, giving analogue outputs corresponding to 800mV/g.

I originally had two free samples from Freescale of this unit but unfortunately they turned out to be extremely heat sensitive, and as careful and cautious as I tried to be in soldering them, I ended up damaging them both slightly. The solution was a cheap breakout board that you can see in the images below (green PCB).

These outputs were fed through voltage buffers and then into a Maxim MAX187 12-bit SPI ADC through a 4-way analogue multiplexer (MAX4617/8/9) controlled by a PICAXE 28X microcontroller.

Power

In the image below, the top left PCB is the power regulation board. It takes 9V PP3 battery power and converts it to 5V and 3V3 levels via MAX882 and MAX883 linear regulators. Two ports are provided for supplying both voltages to the accelerometer board and the control board.

 

DSC04768

Accelerometer

The accelerometer on its breakout board can be seen at the bottom of the picture below (green PCB). The onboard regulator and onboard signal conditioning hardware have been disabled or bypassed, since these important functions were already being carried out by the main PCB that I designed (large white PCB at the top of the image below) as the circuit was originally designed to use a straight accel without the breakout.

 

DSC04790

 

Control

The main processing IC was a PICAXE 28X. The PICAXE was programmed to select each of the accelerometer's outputs in turn through the multiplexer and then use bit-banged SPI routines to initiate a conversion in the ADC and then read the results before switching accel outputs (mux inputs) and repeating.

Since the PICAXE in incapable of anything except basic integer arithmetic, a uM-FPU was employed to carry out the (still fairly basic) trigonometry. This was addressed via I2C and is rather irritating to get to work. The definitions provided only make the task marginally easier.

The programming socket for the PICAXE was included on the PCB so as to ease debugging and fault fixing. The image below shows the PICAXE being programmed:

 

DSC04761

Liquid Display Crystal Screen

The results of the processing (the angles in the X and Y directions of tilt) were to be displayed on an LCD screen. Luckily I had a nice backlit LCD lying around with included firmware that allowed any microcontroller to talk to it at 4800 baud serial.

In the image below the top line of the display shows an arrow indicating direction of tilt, an X to show the axis, and the angle of tilt in degrees. The second line displays similar information for the Y axis.

 

DSC04773

LED Direction Indicators

The four red LEDs are direction indicators that would light up if the device was tilted in that direction. For example, if the spirit level was tilted in the positive-Y direction, the LED at the positive-Y edge would light.

When the device was not inclined in a given axis (angle of tilt <= 1.0°) both LEDs would light for that axis. As such, when sitting on a flat surface, all four LEDs would be lit (see images below).

Buttons

The user inputs to this device are very simple. One button (green) turns power to the device on/off. The calibration button (blue) runs the calibration routine so the device measures everything subsequently relative to the position in which it was calibrated. The picture below displays the two buttons:

DSC04776

 

Finished Project

 DSC04774

DSC04784

DSC04782

DSC04764

PICAXE Program

Please click the following link to download the program for the PICAXE 28X: www.hexoc.com/media/LCD_DUAL_AXIS_2.6MUX-AVCYC.zip