Wednesday, June 8, 2016

DIY Aviation Altimeter with QNH setting

Aviation use altimeters are extremely sensitive mechanical devices which use a bellows to convert pressure to displacement, and then use a clockwork mechanism to convert the displacement to dial position on the display. Since the overall displacement is quite small (a few millimeters of bellows compression for the ~20,000 ft. altitude range of the device, the mechanism must be fairly complex, precise and maintained periodically. Accurate and sensitive MEMS pressure sensors have been available since around 2005, which are a perfect replacement for the mechanical altimeters. However the early versions were analog (simple Wheatstone bridges) which meant that they were susceptible to drifts, required temperature compensation and fairly complex electronics to read the output voltage with sufficient precision to allow use as an aviation altimeter. 

DIY altimeter.


Technology to the rescue, recently these problems were solved with tiny pressure sensors which include temperature compensation, low drift, and high precision analog digital converters on-board. Simple communication protocol is sufficient to interface with them, and it is only a matter of following the datasheet to implement up to 24 bit pressure and temperature readout. Quite incredible, where the tecnology has come!

One such notable pressure sensor is Measurement Specialities MS5611 series. They have 24 bit precision and high accuracy, with factory calibrated coefficients permanently stored on-chip, which are used to convert raw measurement values to pressure reading. It is a dream come true; such a precision and accuracy is difficult to come by at such low prices, of about $8~10. Better, they come installed in many drone flight controllers. This is great because for about $25, you get a STM32F103 microcontroller with many other sensors, clock, regulator, all broken out to .1" pin headers. A great platform to experiment and develop with (see my blog on using Naze32 for development).

In this project, a full function barometric altimeter for aviation use was implemented using a Flip32 (Naze32 clone) flight controller board with installed MS5611 pressure sensor, an SSD1306 graphic OLED screen on I2C, and a rotary volume encoder. A single LiPo cell powers the system, with about 40mA current draw.

QNH adjustment is also implemented. You can learn the local QNH value of a nearby airport, dial it into the device, and obtain the MSL altitude in feet. In exactly the same way as a conventional altimeter is used. It was compared during flight with the altimeter of a Cessna 172, and the altitude is always within about 50ft, so it works quite well.




It is quite easy if you want to build one! You only need to buy a Naze32 or Flip32, or similar flight controller with a STM32F1, connect the I2C display (only 4 wires), connect the volume encoder (again 4 wires), burn the binary, and you are ready to go! It can be powered off a single LiPo cell. A small 240mAh cell completely hides behind the display, and will power the altimeter for about 6 hours.


Operation: At power up, an information screen is briefly displayed. Then it returns to normal operation where altitude in ft. is displayed in the center of the screen, measured local pressure in hPa and temperature in Deg. C. at the top, and set QNH at the bottom. To adjust QNH, press and turn the dial. The QNH set screen appears. At the center QNH value is displayed and at the top are the MSL altitude in feet and meters. If you know QNH, you can dial it while keeping the dial pressed in, or if you know the MSL altitude, you can dial that, just as in conventional altimeters. Upon releasing the dial, the device returns to the altitude display screen. Double click takes you into the information screen and back out of it.


Information screen at power up.
QNH set screen:  Enter either QNH of nearby airport or known airfield altitude. Turning the knob changes both.

Firmware: The source code of the project can be downloaded here. It uses u8glib graphics library ARM port, and was compiled with GCC ARM Embedded toolchain, easily downloadable from Launchpad. A binary is also provided, if you do not want to compile from source, for direct burning into a Naze32, Flip 32 or similar. Electrical connections are very simple: OLED display connects to the provided I2C terminals (I2C2), encoder to GPIOA: A signal to PA1, B signal to PA3, click signal to PA0. Internal pull ups of STM32 are used for simplicity so no pull up resistors are needed, no smoothing capacitors are needed either, since debounce is done in the software by a digital filter. See my blog posts for u8glib on STM32F103, and on connecting a volume encoder to the STM32F103.

The pressure altitude calculation formula can be found at several places in the Internet. There are a few sets of coefficients with a slight variation. However, the ones used here have been tested aboard a C172, and compare very well with its installed (mechanical) altimeter.

I wrote the pressure sensor communication and pressure calculation routines from the device datasheet.  I also wrote the bulk of u8g_arm.c and u8g_arm.h files using templates from u8g and several examples from around the web. One critical component is the setup of TIM2 for the delays.

So there you have it. Please build one for yourself, and make suggestions on how it should be. I have several ideas in my mind of how to make it better:
  • Implement a menu to adjust parameters (AGL or QNH display, feet or meters etc.).
  • Battery backup or   EEPROM backup for set parameters. Unfortunately flight controllers typically have the battery backup pin of the processor connected to upply voltage. Also, STM32F103 does have self programmable flash but again unfortunately, with a very small cycle count for this application of about 10,000 writes.
  • Upon power up it should default to the latest recorded altitude for best convenience.
  • I have other versions for larger STN LCD displays, for DOGM128W, and for ST7920, both connected over the SPI interface. DOGM128W is nice because it has a small form factor; only the glass panel. But it is somewhat difficult to find. ST7920 is bulkier, but abundant; it is used in the graphical interface of the Reprap Ramps 3D printer user interface, complete with a volume encoder! STN LCD is best in direct sunlight applications. Future blog posts will detail altimeters with those screens.  
Check back here for updates.

Disclaimer: Although this is an altimeter, those who build or use one accept the associated risks and are solely responsible for safe operation. Do not trust your life on it! It is not intended to be a replacement for certified or any other instrument for aircraft (but perhaps a coal stove).



21 comments:

  1. Hallo!
    Thats the Altimeter i'm looking for!
    Ist ideal for my Minimum Flyer but i'm not the specialist
    to get your files into the naze 32.
    Would you be sokind to publish a simple "how to" ?
    Regards
    Willi

    ReplyDelete
    Replies
    1. Hallo!
      Every Thing works fine now.
      I only forgott to shorten the boot pins on
      naze 32

      Delete
    2. Great to hear it works fine! You can find How-To articles in my other blog posts; see posts from April and May 2016 for details, and as usual, all source code. You don't need to compile the code, but simply burn the provided hex file (in my github account, link above) in the controller.

      Please tell me of you need extra features.

      Delete
  2. a Little follow up and a new Problem:
    i burn my naze32 clone with the blinking Code - it works.
    now i'm trying to connect my maze32 clone with the oled Display and the Rotary Encoder.
    I found a lot of Infos about the board in combination with Radio controlled things, but no advice on wich pin the GPIO Ports will be.
    i will try find out on which board Pins a can find the Prozessor Signals.

    ReplyDelete
    Replies
    1. You can lookup the schematics of NAZE32 on the web and the connections from the source code.
      Here is the information that you need:

      Encoder is connected to:
      Enc A....... PA1 .. NAZE RC CH2
      Enc B....... PA3 .. NAZE RC CH4
      Enc Click... PA0 .. NAZE RC CH1

      Of course you can modify these from the source to suit your implementation if you wish.

      For the SSD1306 OLED display, you need the I2C SDA and I2C SCL pins. They are located as test pads at the back of NAZE32, and clearly indicated as SDA and SCL.

      Connect SSD1306 OLED display as:
      NAZE 32 SDA ... SSD1306 SDA
      NAZE 32 SCL ... SSD1306 SCL
      NAZE 32 3.3V ... SSD1306 3.3V
      NAZE 32 GND ... SSD1306 GND

      The OLED display can run on 3.3V, so you can power the whole altimeter from a single LiPo cell. Please select one with an electronic controller.

      BTW, I recommend Naze32 rev5, since the new ones have a different barometric sensor, which is not supported yet. Since the new revisions are out, the rev5 are quite cheap too!

      Will incorporate this information to the main blog when I have time.

      Hope this helps.

      Delete
    2. This comment has been removed by the author.

      Delete
  3. Hello!
    With the new Version of the Flip32/Naze i have no luck :-(
    only some "grizzle" on the Display.
    I have no deeper knwoledge in prograaming, so maybe you can help.
    Regards Willi

    ReplyDelete
    Replies
    1. Hallo I have "grizzle" also on the display when I use the 3,7V battery. With 3,3V supplied from the stm32 V2 programmer the indication is normal.

      Delete
  4. Iam planning to infcorporate the new boards, but I own none at the moment. They may use the BMP280 barometric sensor, or the STM32F3 pocessor. Both are different and are not compatible. Ihave bought the barometric sensor to test, and am planning to order a STM32F3 processor. So, at the moment, your best bet is to get a Naze32 V5 board. Perhaps you can send me a copy of what you have to speed up my development process?!

    ReplyDelete
  5. Hello!
    How many ohm was the potentiometer that have you used?
    Sorry for the english, i am brazilian and a beginner in microcontrollers / programming.

    ReplyDelete
  6. Hello!
    How can i compile the code in windows? What is the program that i should use?

    ReplyDelete
  7. hello !
    I downloaded your Barometer 34 .BIN file to flash the st 32
    however can I use the "clean flight configurator" sofware used to flash the naze 32??

    this one use only an HEX. file instead of a bin. file so I have to convert your bin file
    Many thanks for your work
    Alan

    ReplyDelete
    Replies
    1. I made it
      it's working without trouble
      I used
      _ a STM32F103C8T6 ARM STM32 Minimum System Development Board Micro USB Controller For Arduino
      nicknamed blue pill 2.06 USD from Aliexpress
      _ a GY-63 6.69 USD from Ebay
      and of course SSD 1306 and an encoder

      I flashed the blue pill with" STM32 ST LINK utility " software from STM with the provided bin code by Ahmet and this programmer :
      ST LINK V2 Mini STM8 STM32 Simulator Download Programmer With Cover
      price is 2.10 USD by ALIexpress

      Electrical connections with blue pill are:
      SCL to B10
      SDA to B11
      encoder :
      A to A1
      B to A3
      click to A0
      many thanks for the code

      Delete
    2. I
      I want you demand information of this altimeter in dtn lcd monitor type schematics hex thanks

      Delete
    3. Nice project. Where the oled SCL and SDA pins goes to connect in the STM32F?

      Delete
  8. This comment has been removed by the author.

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. Bonsoir Ahmet Onat

    Je suis pilote automatique et j'étais à la recherche d'un type d'altimètre ....
    Il est possible d'intégrer des plafonds limites, d'en choisir un et d'enclencher une alarme sonore dès qu'on approche de cette limite ??

    MRCI d'avance de Votre retour

    Cordialement

    Francisbeckers64@gmail.com

    ReplyDelete
  11. hello i search the ST7920 version thanks have you a link

    ReplyDelete
  12. Hello mister Onat
    Acurracy problem ?? :
    ZT ( topo altitude ) is 64 feet
    indicated QNH is 997 hpa (QFE)
    indicated pressure 996 hpa
    if I set 996 hpa as QNH I should have indicated 000feet
    I read then 34 feet?????
    1 HPA = approximately 28 feet

    ReplyDelete
  13. Great and I have a super present: How To Become A House Renovation complete home renovation

    ReplyDelete