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
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.
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.
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.
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:
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.
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).
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:
Please click the following link to download the program for the PICAXE 28X: www.hexoc.com/media/LCD_DUAL_AXIS_2.6MUX-AVCYC.zip