Sample altimeter C# code for Android and Wear devices with barometer

Recommended Posts

I've created two sample Visual Studio projects (in C#) that turn your Android or Wear device equipped with a pressure sensor into a simple altimeter showing current altitude above mean sea level in feet. I hope some jumpers with at least basic understanding of software development might find this interesting and poke around the code, customize it to their likes, and maybe even develop their own ideas. It's a very simple app - all the code, including the barometric formula, is in MainActivity.cs.

We now have quite a few smart devices equipped with a pressure sensor, some of them are even very affordable, for example, Moto 360 Sport was available a year or two ago at Walmart and Target for ridiculous closeout price of $50; it has an excellent transflective screen which is very readable in direct sun; GPS, barometer (with 25 measurements per second!), accelerometer, etc. ZTE Quartz, I believe, is about 80 bucks. LG G Watch R (barometer at 90Hz) can be found used for about same price. Nixon Mission is the absolute king of sensors: a mind-boggling pressure sensor at 167Hz (!!!), accelerometer, gyro, magnetometer, thermometer and humidity sensors, all in this mean-looking mens watch. ($300-450, though)

I've been using Android Wear smartwatches (LG G Watch R initially, then Moto 360 Sport and Nixon Mission) on every skydive since late 2015, and they've been performing wonderfully (running my own simple, but very precise altimeter app, Smart Altimeter). I also use them on wingsuit BASE jumps for exit altitude measurements, as a quick performance gauge by checking the altitude right after opening, for rockdrop measurements (using my Rockdrop Pro app), and for specialized lift-to-drag ratio measurements (using my L/D Vario app, see https://www.youtube.com/watch?v=9Oj8SXvs4GU).

Some Android phones (mostly high-end) also have a barometer, but the sample rate is usually not that high as in smartwatches (go figure). The highest (30Hz) numbers were reported for Google Nexus 4 and Samsung Galaxy S8.

I hope this sample code will spur interest in developing awesome apps for smart devices using their sensors and computing power. The amazing, affordable multi-purpose hardware is here; round pucks the size of an Oreo with incredible array of sensors and high level software development (very similar to desktops, unlike the low level embedded programming). It's the specialized software for jumpers that is almost nonexistent.

Steps to creating an altimeter app for your Android/Wear device:

1. Install Visual Studio Community 2017: https://visualstudio.microsoft.com/vs/
(available for both Windows and Mac)

2. When installing, make sure you select options for mobile app development.

3. Open the solution - Altimeter_Android.sln, or Altimeter_Wear.sln.

4. Make sure Packages in solution are up-to-date. Also, update Tools/SDK Manager.

5. Build the project.

6. On your device, click 7 times on system build number (System->About), you will get Developer Options, turn on USB debugging (Android) or ADB debugging (Wear).

7. Connect your device to computer, confirm debugging permission in a dialog, and choose your device in VS on top in the list of devices.

8. Click on project and in the Run menu select Upload to Device.

9. That's it! On your device, a new app "Altimeter" will appear, now you can experiment with code!

Good luck! Please share how you're using your smart device for skydiving or BASE jumping with your own app or other apps.
Android+Wear/iOS/Windows apps:
L/D Vario, Smart Altimeter, Rockdrop Pro, Wingsuit FAP
iOS only: L/D Magic
Windows only: WS Studio



Share this post

Link to post
Share on other sites

Nice one! But wouldn't this be better in GitHub or some other repository?

Maybe, for someone, but I feel no need. If anyone wants to put this up somewhere, just do it!

My goal was to possibly spark an excitement in people who have little or even no programming experience and who think that all this is kind of black belt mental kungfu; and here, they can just download the zips, follow the easy steps, and boom! they build the code and the app magically appears on their phone or even wrist! And it works, it measures altitude! "OMG OMG OMG, this is so cool and easy! Now, why this label is so small? How can I make it bigger? Oh, there's a screen in xml file, I can see this "altitude label", oh, and there's properties on the right, and I can make the text bigger! Yay! Can I make it pink? YES!!! Wow, I'm such a pro now! Now, how can I zero the altitude, how can I make it make a sound when altitude is below some threshold, how..." Github would only add unnecessary complexity to what was meant to be just a little personal experimentation.
Android+Wear/iOS/Windows apps:
L/D Vario, Smart Altimeter, Rockdrop Pro, Wingsuit FAP
iOS only: L/D Magic
Windows only: WS Studio

Share this post

Link to post
Share on other sites

I was trying something simmilar with Moto360 Sport, but the problem was the accidental push of the power button with the gloves I had on. Do you have any ideas about how to solve this?

Make a transparent case for it? Or 3D-print a case for it that protects the button?

I wear my Moto on a pillow on the cheststrap and always jump wingsuit, it works well.
Android+Wear/iOS/Windows apps:
L/D Vario, Smart Altimeter, Rockdrop Pro, Wingsuit FAP
iOS only: L/D Magic
Windows only: WS Studio

Share this post

Link to post
Share on other sites

I am a retired coder and long time skydiver. I just wanted to thank you for publishing your code. It will give me something fun to play around with.

That's a joy to hear. This is just a basic start, but you can evolve it into anything you like and make an altimeter exactly how you like it!

For those not familiar with Android development, here are the files you can start making changes to:

(for Wear, there will be two: Round and Square, for different form factors)

- open it and you will see the visual designer of the main screen; you can drag&drop controls from the Toolbox pane on the top right, change their properties in the Properties pane on the bottom right


- these are your app icons for various screen resolutions


- specifies what minimum version of Android your app supports, package name (must be unique for the app), etc.


- this is where the main code is. Also, specifies the app name as it appears on the device (Label = "Altimeter"). The formula for altitude AMSL is exact from the US Standard Atmospere 1976, you can trust it.

For Android dev't guides, see https://developer.android.com/guide/
For Wear OS, https://developer.android.com/training/wearables/apps/
For sample code for multi-platform dev't in Visual Studio, see https://developer.xamarin.com/samples-all/

For list of smartphones with barometer, see (it's in Russian, but phone names are English) https://market.yandex.ru/catalog/54726/list?hid=91491&glfilter=8547228%3A1&onstock=0&local-offers-first=0&how=aprice

For list of Wear OS devices, including which sensors they have, see https://docs.google.com/spreadsheets/d/1lbKhNnFBARrT5TVo3bkyp1UzT0S5Iahy3W9dAQf_sfc/view#gid=0

Since a new batch of Wear OS smartwatches with the new Snapdragon 3100 SoC is expected soon, I would not recommend buying a previous generation 2100 watches now, only used ones for cheap. As a starter, a used Moto 360 Sport can be found on ebay and such for about $50. It has a transflective screen that's easily visible in direct sun:

[inline Moto.jpg]

It works great as an altimeter (especially on cheststrap or mudflap, where its power button cannot be accidentally pushed), and I use it on every skydive (although I do have Viso for a backup).

Besides desirable high sample rate of barometer, it's important to be aware that some devices have water resistance and so the breathing hole for barometer/microphone can be covered by a membrane that will introduce lag to fast changes in pressure. For example, on my LG G Watch R I had to puncture this membrane with a needle. Moto 360 Sport has an excellent membrane or grille that doesn't delay pressure changes. Nixon Mission has a unique feature - a mic lock/door - that when open, allows free air access to inside.

Known to me high sample rate barometric devices currently are:

Nixon Mission - 167Hz
LG G Watch R - 90Hz
Moto 360 Sport - 25Hz
Huawei Watch - 20Hz
Google Nexus 4 - 30Hz
Samsung Galaxy S8 - 30Hz

iphone is no good - 1Hz. (and probably murdered by aggressive filtering)

Any questions are welcome!
Android+Wear/iOS/Windows apps:
L/D Vario, Smart Altimeter, Rockdrop Pro, Wingsuit FAP
iOS only: L/D Magic
Windows only: WS Studio


Share this post

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.
Note: Your post will require moderator approval before it will be visible.

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.