Talking Spirit Level Big Level Components Installed

Talking Spirit Level With Arduino, MPU6050 And The Talkie Library

Spirit levels come in several varieties. The most common contain a vial filled with a coloured spirit or alcohol which forms a bubble within the constant inner diameter at the viewing points. Bull’s eye levels hold the liquid beneath a convex glass face with a central circle and can level across a plane. Less common are electronic levels, which can measure angles using an accelerometer, magnetic sensors or an angular tilt switch and display the readings on an LCD screen.

Talking Spirit Level Big Level Front View

Levels are visual devices by nature, and few if any exist that can output auditory readings be they spoken or tones. There was a device available some years ago which could indicate level by a change in pitch and staccato beeps as you got closer to the zero point. I have one of those and it’s not especially accurate. The

Hardware

The levels are based around an MPU6050 three-axis accelerometer and gyroscope contained within a single chip, readily available as a breakout module suitable for use with common microcontrollers. THey’re often used for positional sensing in drones, robots, RC cars and tools, but have many uses besides including highly accurate angle measurement.

I wanted to use the Talkie speech library and so chose a clone of the Atmega 328-based Arduino Nano as the microcontroller for which the library is designed. Talkie is a software implementation of the Texas Instruments ‘Linear Predictive Coding’ speech synthesis architecture designed to run on the Arduino. Though it sounds quite robotic by modern standards, it is ideal for reading basic words and numbers without any additional hardware besides an amplifier and speaker.

Amplification is courtesy of an LM386 for which pre-built modules containing a simple circuit are readily available online. You could also assemble one on a piece of stripboard, or use a miniature class D amplifier like the PAM8403. Power is via a three-volt battery set with a step up supply, and miniature mylar speakers are used for sound output. Finally, a pair of pushbuttons toggle power and give access to a single-button menu system to alter various settings, discussed in the software section below.

Talking Spirit Level Speaker Side Of Level Raw

Both levels use aluminium U-Channel for their casework. The hardware is set out within to give the best horizontal balance possible when the levels are used to position a surface prone to movement as in the case of a suspended turntable. The smaller level served as the initial prototype for this project.

Talking Spirit Level Small Level Front View

Both levels use switched battery boxes, AAA batteries used in the smaller level and AAs in the larger level. The switches were removed and the wires passed through the underside of the boxes so as to be invisible from the outside.

The batteries power a 5V step-up module necessary to power the Arduino, the amplifier and the MPU6050 module. These step-up modules all seem to come with a pre-soldered USB A connector which has to be removed to solder to the output points, and in the case of the smaller level for the module to fit correctly. The same was true for the pre-soldered header pins and speaker terminals of the amplifier board.

The shell of the USB port is sufficiently large to act as a heatsink when desoldering and they can be a challenge to remove. Care is imperative to avoid damaging the board which is otherwise packed with surface-mount devices. It’s easier to snip the contacts at the sides of the port which allows you to angle the port upwards and remove the shell from the pins, which can then be de-soldered.

Talking Spirit Level Big Level Back View

The key consideration in the construction of any level is to machine a flat bottom surface and to ensure that the level board is securely fixed to that surface to get the most accurate reading possible. Small metal standoffs were used here to achieve this, with a measured accuracy within 0.01 degrees on both devices. Accuracy to within a tenth of a degree is perfectly sufficient, so achieving a hundredth is excellent.

Software And Construction

I opted for a simple latching power switch rather than using a soft button and putting the Arduino in sleep mode. This saves power and avoids potential timer conflicts with Talkie. The switch is wired in the positive line from the battery to the 5V step-up module.

The momentary pushbutton is used to access the settings menu. It is wired between digital pin two and ground, though the digital pin can be configured in code. Holding the button enters the menu, single clicks cycle through the options, and double clicks change the settings. A further hold exits the menu and returns to reading mode. This was tricky to code as running Talkie tends to interfere with button code regardless of how it is written.

In fact, getting Talkie to cooperate with a pushbutton is so troublesome that it’s easier to use a suitable library than it is to hardcode the button in each project. The only library I’ve found to work reliably is the OneButton library, which handles short and long presses as well as double clicks and so is perfect for our application. Minimal code can handle further button press actions like triple-clicks if you want to go that far.

The MPU6050 communicates over the I2C bus and is connected to Arduino analogue pin four (SDA) and five (SCL). VCC is fed via the Arduino’s 5V output as I have found it to operate more reliably when set up in this way as opposed to taking power directly from the power supply. The ground can however be connected anywhere within the circuit ground.

Talking Spirit Level Big Level Components Wired

Talkie operates at a high PWM frequency and can directly drive a speaker from the Arduino’s digital pin, albeit at limited volume. We use the LM386 amplifier module to boost the output, connected directly between the Arduino’s digital pin and ground. Talkie outputs on Arduino digital pin three.

The bitstreams for the words and numbers were pulled directly from the Talkie example libraries. They are spoken in a US male voice at an easily understandable pitch and rate. The software contains numbers sufficient to speak any number between -999999 and +999999, along with words like “degrees”, “set” (for the settings menu) and the ability to speak the X, Y and Z axes.

The software supports configurable axes readings. By default, only the X-axis is spoken as it is the axis used here for linear horizontal measurements. These options can be toggled within the settings menu, and if multiple axes are to be spoken the software will announce the denoting letter prior to the measurement. The software also incorporates tare functions for each axis, enabling the ability to measure angles in relation to one another. If you see a use for these functions you may wish to add additional buttons for them which would be simple to implement in this code, and may become a standard feature in future versions. I also plan to store the configuration variables in EEPROM, as any changes to the settings are presently lost when the power is switched off.

The software and libraries are available for download Here.

Wiring

  • Battery:
  • In+ > power switch > battery +
  • In- > battery –
  • 5V (diagonally opposite In+) > 5V Bus
  • GND (diagonally opposite In-) > GND Bus
  • LM386 Amplifier:
  • VCC > 5V Bus
  • IN > Arduino D3
  • GND > Arduino Ground
  • GND > GND Bus
  • Speaker + > Speaker positive (usually red)
  • Speaker – > Speaker negative (usually black)
  • MPU6050:
  • VCC > 5V Bus
  • GND > GND Bus
  • SDA > Arduino A4
  • SCL > Arduino A5
  • Menu Switch:
  • Arduino D2 > GND Bus

Settings Menu Default Values

As of software version 1.0.

  • “X ‘On’” – Toggles reading of the X -axis..
  • “Y ‘Off’” – Toggles reading of the Y-axis.
  • “Z ‘Off’” – Toggles reading of the Z-axis.
  • “Point ‘2’” – Set the number of decimal places to be read. Options are 1 (speak hole number only), 2 (a tenth of a degree) or 3 (a hundredth of a degree).
  • “X ‘Zero’” – Tare the X-axis.
  • “Y ‘Zero’” – Tare the Y-axis.
  • “Z ‘Zero’” – Tare the Z-axis.
  • “Set ‘X’” – Subtracts the current measurement of the X-axis from future readings, Allowing angles to be measured in relation to one another.
  • “Set ‘Y’” – Subtracts the current measurement of the Y-axis from future readings.
  • Set ‘Z’ – Subtracts the current measurement of the Z-axis from future readings.

Future Plans

Though the aim here was to develop a talking level, adding an LCD display shouldn’t be difficult providing the LCD library doesn’t interfere with Talkie. This I haven’t tested, but I will consider adding screen support as a feature in a future version if there is enough interest. Plans for software version 2 include retaining settings values in EEPROM. I may also add code for multiple buttons for frequently accessed functions such as the switching of axes or the tare function. Or as an alternative, could perhaps have multiple user-configurable buttons, the function of which could be set in the level settings.

Check out the Project Page for more photos and a video of the level in operation. Until next time…


Comments

Share Your Thoughts

Discover more from The Blind Man's Workshop

Subscribe now to keep reading and get access to the full archive.

Continue reading