Jump to content

Altimeter questions.

Recommended Posts


I have been flying rc planes and helicopters for a while now, most of them I build from scratch.


I was thinking that I could slap an altimeter to the planes to see how high they go, but I would like to build it myself.


I would like to ask if anyone here thinks that this is a project that could be done with a cheap g2553 or equivalent,


I have a BMP180 barometer, this could be used to measure the air pressure and thus we could get the altitude of the plane.

Also, I would like to add some kind of memory like an SD card to log the altitude and time.


Anyone have any comments, suggestions, or other MCU's that may be up to the challenge?


Link to post
Share on other sites

The main challenge for the MSP430 will be the somewhat complex math to convert barometer readings into altitude, particularly for the resource constrained G2553. The MSP430F series might better suited for the task.


The G2553 should be able to handle in-flight logging of barometer readings and timestamp to an SD card. Then process the collected data after the flight on your PC, e.g with a Python script.

Link to post
Share on other sites

Normally you should factor in the air temperature too but the BMP180 does feature temperature sensing already so you're fine on that front, just needs a slight code alteration. But for your purposes the formula given within the datasheet (which only uses current pressure and a pre-recorded pressure at sea level) should suffice.

Looking at it, the maths is indeed pretty complex to go from raw pressure data to an altitude.

Altitude = 44330 * ( 1 - (p/p0) ^ (1 / 5.255))

Altitude in meters. p = current pressure in hPa (which the sensor returns). p0 = pressure at sea level in hPa.


As it stands right there you have 2 divisions, a multiplication, a subtraction and raising a number to a power, and all in floating point. The G2553 isn't great at maths, it cannot do floating point and instead does it in a much slower software implementation. You can define a constant in your program for 1/ 5.255, then it will only need calculating once and in future the code can fall back on this precalculated value to save time, I'd highly advise that if you were to go down the route of calculating the altitude on the aircraft instead of @@chicken's method.


It apparently takes 7.5ms for the sensor itself to get a reading, so your MSP430 does have that long to calculate an altitude if you really want to and you probably don't need to retrieve the altitude at much more than 1 or 2Hz anyway. The maths will be slow, but you don't need it to be executed particularly fast.

There is this thing in embedded electronics on whether or not you need to optimise your code for fastest performance, smallest memory footprint or "pure accuracy" (or a better way of saying neither). All depends on the application. I'd say the memory footprint of this thing will be small anyway leaving you with speed vs accuracy. Upto you.


Oh, very good writeup on maths on microcontrollers and processors in general here: http://letsmakerobots.com/content/help-your-robot-do-its-math-homework

Link to post
Share on other sites

I had an MPX4250A sensor being sampled by a G2553, running the transfer function to convert the sample to pressure, then running two transfer functions to change the pressure to the voltage two other different pressure sensors should be outputting at that pressure, all in floats, while displaying text on an I2C LCD and it could update many, many times per second.


Could probably take advantage of low-power modes and have the G wake up 1-4 times per second to do the work, and get some performance using the TI math library.

Link to post
Share on other sites
  • 4 weeks later...

For the Arduino I built a RC sailplane variometer based on the BMP180 sensor.


In my code I use this algorithm to have the variometer tell me the altitude.


  altitude = (float)44330 * (1 - pow(((float) flpressure/p0), 0.190295));


I think that is the same formula as above. However I do not see raising to a power in that formula while it is mentioned. In general it works quite nice as when we tested with a GPS logger at 300 meters we observed only 10 meters difference.

p0 stands for pressure at groundlevel, when switching on the vario meter

flpressure stands for the pressure measured at altitude

all pressure in hectopascal.


As I am a complete newbie (got my launchpad last week) to MSP430 I will need to give it a go first if I can get the variometer to work with the M430G2553 via Energia


For now my whole sketch compiles in Energia EXCEPT for the above formula. I get an "undefined reference to pow" error


EDIT: after some googling I found I have to use "powf" instead of "pow" now at least it compiles.

Link to post
Share on other sites

If you want to avoid all the crazy math then you could change out the BMP180 sensor and go old school with MPX2100AP

for the altitude and, for kicks, add in the MPX5010DP to measure the airspeed.


These sensors linearize the output so that the calculations are just a lookup table away.


I did this back in 1996 and I still have my project report available on my website.


Check it out and tell me what you think.

Link to post
Share on other sites

I too considered using a GPS on my logger project but I realized that the GPS update speed would be inadequate for the rate of change of altitude on my RC airplane. I could dive my plane 500 feet in about 2 seconds. The plot of that would look like a staircase if you had to wait one second between updates. 


But, that MTK3339 GPS module has a 10Hz update rate and that would work great on an RC airplane!


A GPS would be great if you wanted to do autonomous flight control (aka autopilot).


Maybe @@Apaseo might want to put on both sensors?


@@RobG, thanks for the reminder about the GPS group buy. I forgot that I participated. I have four of them and two of your pcb's.

Link to post
Share on other sites
Altitude = 44330 * ( 1 - (p/p0) ^ (1 / 5.255))

Altitude in meters. p = current pressure in hPa (which the sensor returns). p0 = pressure at sea level in hPa.

This can be optimised in several ways.

First off is precalculating 1/5.255, which should be done by the compiler anyway (constant / constant = constant)


Second off is breaking the division p/p0 out of the power.

Altitude = 44330 * ( 1 - p^(1/5.255) / p0^(1/5.255))


This will result in p0^(1/5.255)  being a constant as well and this enables moving the multiplication inside too

Altitude = 44330 - 44330 * p^(1/5.255) / p0^(1/5.255))


Which can be written as

Altitude = 44330 - p^(1/5.255) / (p0^(1/5.255)) / 44330)

Where (p0^(1/5.255)) / 44330) is again a constant which can be calculated at compile time.


This reduces calculations to a subtraction, a power and a division.


Then again, a much faster way would be to make a look-up table with the desired resolution for your altitude and just look up index p.


Altitude = pressure2altitude[p]


such a table would take 128kb for the case that every pressure is a 16 bits value that yields a 16 bit altitude. In most cases, a much smaller table would be sufficient.

Link to post
Share on other sites

I've been using the libfixmath library (I posted an energia port in the Libraries sub forum), which compiles considerably smaller than the gcc floating point library, and yields accurate results. The 2553 has plenty of grunt to calculate altitudes from pressure and log and/or display them.



If all you are doing is logging altitude during the flight for later viewing, I'd just be logging the raw pressure readings. Then you can do all the funky maths on the computer that you use to view the results.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...