Arduino altimeter

Altimeter: Another problem with losing data during lost signal:

Altimeter sketch, Tried to change library from VirtualWire.h to RadioHead.h, but memory on Arduino nano is already too much populated, working memory for variables. So… Don’t know what to do… OLED display take 1024 bytes (1 kB), maybe I should to consider different display?

Altimeter programming problemsaltimeter

Explanation about mistake in my test flight with altimeter.

Altimeter: some outdoor test is done with one big mistake…

This video is made before utilizing “second order temperature compensation” in sketch of the transmitter. It looks complicated, but it turns out that is actually simple to apply (or I become somewhat good in programming). 😀 What happens is that I set zero indoor where temperature is close to 20°C, but outdoor in early morning was just 7°C, which gives me error of about -6 meters. Now things are better, error is still present but no more than say – 3 meters. BUT (!), now this error is within ballpark of maximum -3 meters error if temperature changes dramatically, which in most situations is not the case. Problem may occur during winter time, when someone want to fly briefly, and bring outside “warm” quad with sensor at say 20°C, then begins to fly – when set zero on ground, fly, and back, on ground should be again zero. For this reason, give quad and sensor some time to accommodate to whatsoever temperature outdoor is. Sensor is temperature dependent, and between 20°C and maximum operating temperature of 85°C it has pretty linear reading. The problem begins below 20°C, and exponentially rise with lowering temperature. But, since we are not interested in correct atmospheric pressure, but rather correct measured altitude, such error of -3 meters (which is about 0.5 mb, or 0.5 hPa), is next to nothing if quad fly very high AND (!) in meanwhile temperatures drops drastically. Down below is sketch for Attiny85, which is now corrected with added additional math. In the worst case of temperature drop, error is no more than -16 meters at temperatures between -15°C and -40°C DIFFERENCE (!) between starting temperature and temperatured during flight. And, I doubt that anyone has actual will to fly on such cold and freezing butt temperature. 😀

Altimeter: transmitter under 3 grams! (2.75 g with antenna)

altimeter

On this ‘remote’ altimeter, still need to add ISP connector with 6 wires for re-programming firmware. Just in case that something need to be changed. Else, it is under 3 grams, but as ‘features’ growing, it will be slightly above 3 grams. For example, this 1/4 lambda antenna is okay, but full dipole (1/2 lambda) is better for more range. Just need to finish receiver end, post it on this page, and test maximum possible range. I am hoping for 1 km or more, but will see. Also, not sure how it will looks like on the quadcopter. For rockets, there will be different version – one without transmitter, just recording max altitude in EEPROM, then red with some base station, but that is future plan. Or, maybe I will find some good and lightweight LCD display… don’t know… For quadcopters, it is good to monitor altitude dynamicaly – in flight, but for rockets… eh, it goes hight as it goes – no way to monitor it in real time.

Arduino Altimeter – first steps are done

Altimeter – Beta version works on 433 MHz, base station should be pressed “zero” to set zero of the vehicle (airplane, quadcopter…), and then it will calculate altitude by receiving data from vehicle to the base station. So far, I have some problem with OLED display and it’s library: it uses too much memory and some instability occurs when it is out of range and not used for longer period. Just need to see what may be done…

Altimeter

Download (PDF, Unknown)

Working day and night… not only this project, but other things as well. Just some short video:

On this video, pressure sensor MS5611-01BA01 is used. By clicking on this link, you will get datasheet if you are interested.

Another PDF file MS5611-01BA03, much detailed, where at pages 17, 18 and 19 – diagrams showing error in pressure and temperature measurements without applying “Second order temperature compensation”, where sensor below 20°C increasing interpreting pressure reading exponentially as temperature goes really low. This math correcting it as much as possible. Still some error remains, but with peak of about 1.8 mBar at temperatures between -15°C and -40°C. Without this, additional math, error at such temperatures are up to 28 mBar at -40°C. At some “normal” local atmospheric pressures of say 1000 mBar, error of 1 mBar equals 8.426 meters. As pressure goes down, this error goes down. So at very high altitude, where temperatures are low – error becomes less important. I will be more worried about LiPo battery, than about sensor.

Another changes

Changed way of displaying Actual altitude, and Maximum altitude reached, shown as A: and M: respectively. Both in feet and meters.

altimeter

And got idea about barometric pressure (for altitude calculation), humidity and temperature of the base station. Later will be added another barometric sensor in the case of rapid change in weather, as is case past few days prior to rain. This second sensor together with humidity and temperature will make it almost complete meteorologic station, mobile one. Just missing wind speed, and few other parameters, but so far – it looks much better and more “rich” than before. 😀 To read meteo-data, just switch into second position, while altimeter continues to measure altitude and “remember” maximum reached. MaxAlt is done by simple code:

altimeter

I wish to have better and bigger display in order to show all data at once instead changing “pages” on OLED, but here it is, what it is… New Nextion display ordered, just waiting to arrive.

Some old rant

Rant about altimeter, old video, scroll down for more info.

Work on Altimeter. Just need to add some display on receiver side, check again everything, test range and add something.

First codes for TX, test phase

So far it works as a “Packet Radio” on 433 MHz, the ISM frequency. Transmitter and sensor + Attiny85 is chosen so that whole sending device will be under 3 grams – good for any vehicles. Unfortunately, it can’t work as altimeter not as vario + altimeter as planed. The main problem is in receiver side; if I combine relative slow transmission, some 24 packets maximum, tone sounds crazy and has delay. So, later version of the Arduino altimeter will has switch to chose altimeter or vario with the same circuit. For now, I did only altimeter, everything else will be added later (for those who found this page before end of test or beta phase of developing).

Some errors corrected

In the example below, initial idea is used from Arduino Vario by Rolf R. Bakke. He made initial code in such way that pressure is with OSR (OverSampling Ratio) for pressure, which is 4096 , so that resulting RMS (Root Mean Square) is 0.012 mBar (the lower number – the more precision). But (!), because higher OSR requires longer conversion inside MS5611 sensor chip, this value requires delay of 9.04 ms (minimum 7.40 ms, typical value is 8.22 ms and maximum value is 9.04 ms), So, for sake of ‘safety margins’, he uses 10 ms delay for pressure reading, since ADC need this time in OSR mode 4096. But, he uses OSR for temperature of just 256, which is equivalent of RMS of 0.012 °C, which is okay for vario, but not for altimeter – numbers jumping up and down too much. He probably made this decision because vario should be very fast, and already present delay of 10 ms + 1 ms at another command, adding more delay may result in too slow vario to be useful for sailplanes or gliders. The more samples per second – the faster the response.

Vario is one thing, altimeter another

For this reason, I changed call function from “D2 = getData(0x50, 1);” to “D2 = getData(0x58, 10);”, which has RMS of 0.002 °C – much better temperature correction data (six time better temperature correction than in the case of OSR 256, which gives RMS of 0.012 °C), but ten times longer to read (instead 1 ms, it needs over 9 ms to complete oversampling). The same as above for pressure, I am using 10 ms for good measure to prevent error(s). Anyone who want to experiment, try change from 10 ms to 1 – terrible error occur, instead some ‘reasonable’ pressure of say 1010 mbar, there is nonsense, something like -2.5 mbar. ADC converter just can’t cope with that speed, and reading sensor ends in big, really big error.

Why then in Attiny85 code is 1000 instead 10 ms?!

This is mystery to me. I had no time to investigate, but I suspect that library ‘VirtualWire’ resulting in such strange thing. It is actually good to have tens of microseconds (!) instead of thousands, or 1 ms (1000 µs = 1 ms). Since this strange thing is there, anyone who want to change some delay should multiply wanted value by factor of 100 to get proper delay in milliseconds. For example ‘delay(1000)’ usually means 1 second, but in example below, it will be delayed just 10 ms. So, for whole second, it should be ‘delay(100000)’. There is some limit, where delay can’t be set to high value, but instead should be used ‘for/to/next’ loop for more delay, if needed. For example 12 seconds: “for (i=1;i<=12;i++) {delay(100000)}”. This will be delay of 1 second repeated 12 times – 12 seconds. But, this is out of scope for this altimeter.

 

Base station

Base station has OLED display for now, because found only this one. Later will consider make various options; OLED, TFT, numeric LCD, graphic LCD…

Just need time… First code for base station is here (sorry, no diagram yet, working whole night – for those who found this page in the meanwhile):

 

The same MS5611 sensor is used in Arduino variometer. And it is cheaper than ever on Banggood.com

This is all for now

Come back soon, will be updated… Escpecially diagram and videos… Spring time requires hard work in my backyard, but also I did now and then some job for money, and this is main reason of delay of everything.

12 thoughts on “Arduino altimeter”

  1. Hello, Thank-you for this great job. I can find the references of the radio module you use. Can you give the refeences ? where i can buy it, and maybe what is is communication distance ?

    Thank-you in advance.

    Best regard,
    Daniel ROBERT

    1. Here is the similar module I use: http://www.banggood.com/433Mhz-RF-Transmitter-With-Receiver-Kit-For-Arduino-ARM-MCU-Wireless-p-74102.html?p=EH10221611330201505Q
      It has 1 mW output, not much, but with good antenna it may reach at least 200 m in altitude, depend how anenna is oriented. I prefer vertical polarization if possible. No much references out there, just connect + and GND of the transmitter to 1S battery, and data signal to pin 6 on Attiny85. Oh, snap… now I see that I forgot to make diagram for receiver part. Demodulated signal goes to pin 7 on Arduino nano. I will work soon on much better system with Si4432 or maybe better with HC-12 modules – to get better range. Thank you for reminder – I did not worked on it for long time.

  2. hello
    i have been trying to compile the altimeter sketch posted on your website, i am using arduino ide-1.6.7 i keep getting this error
    TCCR1B = _BV(WCM12); // Turn on CTC mode , was not declared in this scope. Could you please let me know how i can fix this problem

    regards
    rodrigo

    1. Seems that one of three libraries are bad. I suspect that VirutalWire.h may be problematic. Found exactly this one: https://github.com/sparkfun/RF_Links/blob/master/Firmware/Arduino/libraries/VirtualWire/VirtualWire.cpp
      Where lines 400 and 401: TCCR1A = 0; // Output Compare pins disconnected
      TCCR1B = _BV(WGM12); // Turn on CTC mode

      Probably have some dependences – some include files missing. If you can, please copy paste whole error message – there are probably other data what may be wrong. Also, in past time, Aruino have some issue with Attiny85 – there are two kind of Attiny board libraties – one work fine, another one has some problems. Currently, I haven’t any Attiny board installed, because new version of Arduino IDE just ignored this and now I am forced to use Atmel stuio, but can’t program it with Avrdude.exe anymore. Please search for different kind of support for Attiny85 – this will solve the proble, I hope.

      milan

      1. hello milan
        thank you for your prompt reply to my question. I did what you suggested and found the solution to my problem, i needed to get the proper core libraries, and after installing them i ran the sketch again and it compiled.
        so now i have to make the circuit and put it on quadcopter.
        Thank you very much for the code and all the info on your videos.
        Regards
        rodrigo

  3. Hello Milan
    Do you have a diagram for the receiver part of this project? If you do could you please email it to me.
    Regards
    Rodrigo

  4. hello Milan
    i would like to know why the led connected to transmitter does not blink. I have changed line 65 from 1000 to 100000 and line 133 from 1000 to 100000. Are there other changes that i need to make?

    regards
    rodrigo

    1. For some reason, one of library is wrong and there should be multiplication by factor of 100. Just not sure which one, and at which frequency of the MCU clock. I set it to 8 MHz for Attiny85 – use “burn bootloader”, which actually does not burn anything on the MCU, but just set some ‘fuses’, so that MCU works on 8 MHz. The bad thing is that I have no more proper library nor boards for Attiny85 because started to work in Atmel studio. There is even worst problem because Avrdude.exe seems not support Attiny85, or I don’t know how to set it. So I am using ‘Kazama programmer’ instead. I don’t know how soon I will be back to this topic, because I need working altimeter as well. Stay tuned, and sorry for late answer. Just damn time… I have none…

  5. Hello Milan
    Maybe you are not getting the comments, I will try again. I would like to know if you have a diagram of the altimeter receiver , I need to see one to make sure I am connecting everything how it should be, as my Oled display only shows a bunch of pixels. I have changed the myTX address, still no luck.
    Regards
    Rodrigo Calvo

    1. Sorry, past few days just too busy and little bit sick (stomach problems). Later I will add diagram of receiver part, but should to re-do everything, from receiver to transmitter part. Since manchester mode has some problems at reception if signal is lost for more than 5 seconds. Just, give me some time. Thanks.

      1. Thank you for the quick answer, I hope your health will get better soon, i will wait for your answer, thank you.
        Regards
        Rodrigo

Leave a Reply

Your email address will not be published. Required fields are marked *