{"id":642,"date":"2016-03-11T01:52:32","date_gmt":"2016-03-11T00:52:32","guid":{"rendered":"http:\/\/wildlab.org\/?p=642"},"modified":"2019-03-11T17:03:24","modified_gmt":"2019-03-11T16:03:24","slug":"arduino-altimeter","status":"publish","type":"post","link":"https:\/\/wildlab.org\/index.php\/2016\/03\/11\/arduino-altimeter\/","title":{"rendered":"Arduino altimeter"},"content":{"rendered":"<h1>Altimeter: Another problem with losing data during lost signal:<\/h1>\n<p style=\"text-align: justify;\">Altimeter sketch, Tried to change library from VirtualWire.h to RadioHead.h, but memory on <a href=\"https:\/\/www.banggood.com\/ATmega328P-Nano-V3-Controller-Board-Compatible-Arduino-p-940937.html?p=EH10221611330201505Q\">Arduino nano<\/a> is already too much populated, working memory for variables. So&#8230; Don&#8217;t know what to do&#8230; OLED display take 1024 bytes (1 kB), maybe I should to consider different display?<\/p>\n<h1>Altimeter programming problems<a href=\"https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/NotEnoughMemory.jpg\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" class=\"aligncenter wp-image-851 size-large\" src=\"https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/NotEnoughMemory-1024x576.jpg\" alt=\"altimeter\" width=\"474\" height=\"267\" srcset=\"https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/NotEnoughMemory-1024x576.jpg 1024w, https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/NotEnoughMemory-300x169.jpg 300w, https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/NotEnoughMemory.jpg 1920w\" sizes=\"(max-width: 474px) 100vw, 474px\" \/><\/a><\/h1>\n<h1>Altimeter: some outdoor test is done with one big mistake&#8230;<\/h1>\n<p><iframe loading=\"lazy\" width=\"474\" height=\"267\" src=\"https:\/\/www.youtube.com\/embed\/j_APEOM3vRE?feature=oembed\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p style=\"text-align: justify;\">This video is made before utilizing &#8220;second order temperature compensation&#8221; 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). \ud83d\ude00 <strong>What happens is that I set zero indoor where temperature is close to 20\u00b0C, but outdoor in early morning was just 7\u00b0C, which gives me error of about -6 meters.<\/strong> Now things are better, error is still present but no more than say &#8211; 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 &#8220;warm&#8221; quad with sensor at say 20\u00b0C, then begins to fly &#8211; 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.\u00a0Sensor is temperature dependent, and between 20\u00b0C and maximum operating temperature of 85\u00b0C it has pretty linear reading. The problem begins below 20\u00b0C, 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\u00b0C and -40\u00b0C 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. \ud83d\ude00<\/p>\n<h1>Altimeter: transmitter under 3 grams! (2.75 g with antenna)<\/h1>\n<p><a href=\"https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/Sequence-01.Still001.jpg\"><img loading=\"lazy\" class=\"aligncenter size-large wp-image-830\" src=\"https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/Sequence-01.Still001-1024x576.jpg\" alt=\"altimeter\" width=\"474\" height=\"267\" srcset=\"https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/Sequence-01.Still001-1024x576.jpg 1024w, https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/Sequence-01.Still001-300x169.jpg 300w, https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/Sequence-01.Still001.jpg 1920w\" sizes=\"(max-width: 474px) 100vw, 474px\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">On this &#8216;remote&#8217; altimeter, still need to add ISP connector with 6 wires for re-programming firmware.\u00a0Just in case that something need to be changed. Else, it is under 3 grams, but as &#8216;features&#8217; 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 &#8211; 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&#8230; don&#8217;t know&#8230; For quadcopters, it is good to monitor altitude dynamicaly &#8211; in flight, but for rockets&#8230; eh, it goes hight as it goes &#8211; no way to monitor it in real time.<\/p>\n<p><iframe loading=\"lazy\" width=\"474\" height=\"267\" src=\"https:\/\/www.youtube.com\/embed\/Kc_ErPZ0KT4?feature=oembed\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<h1>Arduino Altimeter &#8211; first steps are done<\/h1>\n<p>Altimeter &#8211; Beta version works on 433 MHz, base station should be pressed &#8220;zero&#8221; to set zero of the vehicle (airplane, quadcopter&#8230;), 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&#8217;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&#8230;<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-780\" src=\"https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/Altimeter.jpg\" alt=\"Altimeter\" width=\"474\" height=\"267\" srcset=\"https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/Altimeter.jpg 474w, https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/Altimeter-300x169.jpg 300w\" sizes=\"(max-width: 474px) 100vw, 474px\" \/><\/p>\n<p>[gview file=&#8221;https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/ArduinoAltimeter3.pdf&#8221;]<\/p>\n<p style=\"text-align: justify;\">Working day and night&#8230; not only this project, but other things as well. Just some short video:<\/p>\n<p><iframe loading=\"lazy\" width=\"474\" height=\"267\" src=\"https:\/\/www.youtube.com\/embed\/UbrJFCluapo?feature=oembed\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p>On this video, pressure sensor <a href=\"https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/MS5611-01BA01.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">MS5611-01BA01<\/a>\u00a0is used. By clicking on this link, you will get datasheet if you are interested.<\/p>\n<p>Another PDF file\u00a0<a href=\"https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/MS5611-01BA03.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">MS5611-01BA03<\/a>, much detailed, where at pages 17, 18 and 19 &#8211; diagrams showing error in pressure and temperature measurements without applying &#8220;Second order temperature compensation&#8221;, where sensor below 20\u00b0C 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\u00b0C and -40\u00b0C. Without this, additional math, error at such temperatures are up to 28 mBar at -40\u00b0C. At some &#8220;normal&#8221; 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 &#8211; error becomes less important. I will be more worried about LiPo battery, than about sensor.<\/p>\n<h2>Another changes<\/h2>\n<p>Changed way of displaying Actual altitude, and Maximum altitude reached, shown as A: and M: respectively. Both in feet and meters.<\/p>\n<p><a href=\"https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/alt1.jpg\" rel=\"attachment wp-att-807\"><img loading=\"lazy\" class=\"aligncenter size-large wp-image-807\" src=\"https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/alt1-1024x576.jpg\" alt=\"altimeter\" width=\"474\" height=\"267\" srcset=\"https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/alt1-1024x576.jpg 1024w, https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/alt1-300x169.jpg 300w, https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/alt1.jpg 1920w\" sizes=\"(max-width: 474px) 100vw, 474px\" \/><\/a><\/p>\n<p>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 &#8211; it looks much better and more &#8220;rich&#8221; than before. \ud83d\ude00 To read meteo-data, just switch into second position, while altimeter continues to measure altitude and &#8220;remember&#8221; maximum reached. MaxAlt is done by simple code:<\/p>\n<pre class=\"theme:classic lang:c++ decode:true\">if (maxAltitude&lt;=altitude) {maxAltitude=altitude;}<\/pre>\n<p><a href=\"https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/alt2.jpg\" rel=\"attachment wp-att-808\"><img loading=\"lazy\" class=\"aligncenter size-large wp-image-808\" src=\"https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/alt2-1024x576.jpg\" alt=\"altimeter\" width=\"474\" height=\"267\" srcset=\"https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/alt2-1024x576.jpg 1024w, https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/alt2-300x169.jpg 300w, https:\/\/wildlab.org\/wp-content\/uploads\/2016\/03\/alt2.jpg 1920w\" sizes=\"(max-width: 474px) 100vw, 474px\" \/><\/a><\/p>\n<p>I wish to have better and bigger display in order to show all data at once instead changing &#8220;pages&#8221; on OLED, but here it is, what it is&#8230; New Nextion display ordered, just waiting to arrive.<\/p>\n<h1>First codes for TX, test phase<\/h1>\n<p>So far it works as a &#8220;Packet Radio&#8221; on 433 MHz, the ISM frequency. Transmitter and sensor + Attiny85 is chosen so that whole sending device will be under 3 grams &#8211; good for any vehicles. Unfortunately, it can&#8217;t work as altimeter not as vario + altimeter as planed.\u00a0The 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).<\/p>\n<h2>Some errors corrected<\/h2>\n<p>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 &#8211; 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 &#8216;safety margins&#8217;, he uses 10 ms delay for pressure reading, since ADC need this time in OSR mode 4096.\u00a0But, he uses OSR for temperature of just 256, which is equivalent of RMS of 0.012 \u00b0C, which is okay for vario, but not for altimeter &#8211; 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 &#8211; the faster the response.<\/p>\n<h2>Vario is one thing, altimeter another<\/h2>\n<p>For this reason, I changed call function from &#8220;D2 = getData(0x50, 1);&#8221; to &#8220;D2 = getData(0x58, 10);&#8221;, which has RMS of 0.002 \u00b0C &#8211; much better temperature correction data (six time better temperature correction than in the case of OSR 256, which gives RMS of 0.012 \u00b0C), 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 &#8211; terrible error occur, instead some &#8216;reasonable&#8217; pressure of say 1010 mbar, there is nonsense, something like -2.5 mbar. ADC converter just can&#8217;t cope with that speed, and reading sensor ends in big, really big error.<\/p>\n<h2>Why then in Attiny85 code is 1000 instead 10 ms?!<\/h2>\n<p>This is mystery to\u00a0me. I had no time to investigate, but I suspect that library &#8216;VirtualWire&#8217; resulting in such strange thing. It is actually good to have tens of microseconds (!) instead of thousands, or 1 ms (1000 \u00b5s = 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 &#8216;delay(1000)&#8217; usually means 1 second, but in example below, it will be delayed just 10 ms. So, for whole second, it should be &#8216;delay(100000)&#8217;. There is some limit, where delay can&#8217;t be set to high value, but instead should be used &#8216;for\/to\/next&#8217; loop for more delay, if needed. For example 12 seconds: &#8220;for (i=1;i&lt;=12;i++) {delay(100000)}&#8221;. This will be delay of 1 second repeated 12 times &#8211; 12 seconds. But, this is out of scope for this altimeter.<\/p>\n<pre class=\"theme:classic h-align:2 lang:c++ decode:true \">\/\/ Altimeter code by Milan Karaka\u0161 2016\r\n\/\/ Revision 2 - some precission errors corrected\r\n\/\/ Revision 3 - added \"second order temperature compensation\",\r\n\/\/ which corrects pressure error when temperature goes below 20\u00b0C.\r\n\/\/ 315 MHZ or 433 MHz ASK (OOK) transmitter\r\n\/\/ MS5611 sensor - just altimeter for now \r\n\/\/ Vehicle ID or just ID - set as you wish\r\n\/\/ WARNING!!! delay 1000 ms -&gt; delay 100000, \r\n\/\/ or two zerros to add, or multiply by 100\r\n\/\/ don't know why it happens, so 1 ms should be\r\n\/\/ writen as 100, not 1 as usually...\r\n\/\/ Note that this is still beta version, need testing!\r\n\r\n#include &lt;TinyWireM.h&gt;\r\n#include &lt;VirtualWire.h&gt;\r\n#include &lt;Average.h&gt;\r\n\r\n#define n 4 \/\/define number of average \r\n\/\/ the biger number n, the longer pause between two transmissions\r\nAverage&lt;long&gt;ave(n);\r\nunsigned int calibrationData[7];\r\nunsigned long time = 0;\r\nlong pressure, D1, D2, dT, P, Pa, TEMP, T2;\r\nint ddsAcc, volt;\r\nint64_t OFF, OFF2, SENS, SENS2;\r\nbyte data[7]; \/\/number of data in array - 1 byte fir ID and 4 bytes for pressure\r\nbyte ID=0x2A; \/\/\"Vehicle ID\" - set different value for each vehicle, also on RX side \"myTX=0x2A\"\r\nfloat vref=5.07;\r\n\r\nvoid setup()\r\n{\r\n TinyWireM.begin(); \/\/begins to comunicate with pressure sensor\r\n vw_set_tx_pin(1);  \/\/set pin 4 (physical pin 3) on Attiny 85\r\n vw_setup(4800);    \/\/ Bits per sec\r\n setupSensor();     \/\/call function for setup of the MS5611 sensor\r\n\/\/ pinMode(4,INPUT);  \/\/voltage measurement input\r\n\/\/vw_set_ptt_pin(3);  \/\/depends of type of the transmitter \r\n                    \/\/some no needs this, so use LED instead :)\r\n                    \/\/is is better to disable this pin, because\r\n                    \/\/some boards as is USB version of Attiny85\r\n                    \/\/uses this pins for something else\r\n}\r\n\r\nvoid loop()\r\n{\r\n\r\nfor (int i=0;i&lt;n;i++) \/\/\r\n  {\r\n getPressure();\r\n ave.push(P);\r\n  }\r\nPa=(ave.mean()); \/\/mean value of ave number (for example ave(10) is ten samples averaged)\r\nvolt=((analogRead(2)*vref)\/1024)*100;\r\n\r\ndata[0]=ID;     \/\/sending ID to array\r\ndata[1] = Pa;          \/\/split long into first byte\r\ndata[2] = (Pa &gt;&gt; 8);   \/\/split long into second byte\r\ndata[3] = (Pa &gt;&gt; 16);  \/\/split long into third byte\r\ndata[4] = (Pa &gt;&gt; 24);  \/\/split long into fourth and last byte\r\ndata[5] = volt;\r\ndata[6] = (volt &gt;&gt;8);\r\n\r\nvw_send(data,7);       \/\/now sending ID and four bytes to the receiver\r\nvw_wait_tx();          \/\/waiting until transmitter ends whole packet\r\ndelay(1000);\/\/ WARNING!!! delay 1000 ms -&gt; delay 100000, two zerros add, or multiply by 100\r\n\/*This delay should be changed together with \"Vehicle ID\" in the case that multiple users \r\n * fly at the same time to avoid overlaping and too much interferences. Receiver side has\r\n * CRC error checking, and in the case of interferences, it will just drop wrong packet and\r\n * continue listening until valid packet(s) is\/are received. ID is single byte, and can be \r\n * anything from 0 to 255 or in hexadecimal from 0x00 to 0xFF. In this case above of 1 mS \r\n * delay, together with averaging of 4 samples from the MS5611 sensor, it gives 5 packets \r\n * per second at 4800 bits per second. Sufficiently good for \"normal\" flight of quadcopter.\r\n *\/\r\n}\r\n\r\n\/\/subfunction to get pressure\r\nlong getPressure()\r\n{\r\n\/\/long D1, D2, dT, P, T2;\r\n\/\/long TEMP;\r\n\/\/int64_t OFF, SENS;\r\n\r\nD1 = getData(0x48, 1000);\r\nD2 = getData(0x58, 1000);\r\n\r\ndT = D2 - ((long)calibrationData[5] &lt;&lt; 8);\r\nTEMP = (2000 + (((int64_t)dT * (int64_t)calibrationData[6]) &gt;&gt; 23)); \/\/temperature before second order compensation\r\nif (TEMP&lt;2000)  \/\/if temperature of the sensor goes below 20\u00b0C, it activates \"second order temperature compensation\"\r\n{\r\n  T2=pow(dT,2)\/2147483648;\r\n  OFF2=5*pow((TEMP-2000),2)\/2;\r\n  SENS2=5*pow((TEMP-2000),2)\/4;\r\n  if (TEMP&lt;-1500) \/\/if temperature of the sensor goes even lower, below -15\u00b0C, then additional math is utilized\r\n  {\r\n    OFF2=OFF2+7*pow((TEMP+1500),2);\r\n    SENS2=SENS2+11*pow((TEMP+1500),2)\/2;\r\n  }\r\n}\r\nelse \r\n{\r\nT2=0;\r\nOFF2=0;\r\nSENS2=0;\r\n}\r\nTEMP = ((2000 + (((int64_t)dT * (int64_t)calibrationData[6]) &gt;&gt; 23))-T2); \/\/second order compensation included\r\nOFF = (((unsigned long)calibrationData[2] &lt;&lt; 16) + (((int64_t)calibrationData[4] * dT) &gt;&gt; 7)-OFF2); \/\/second order compensation included\r\nSENS = (((unsigned long)calibrationData[1] &lt;&lt; 15) + (((int64_t)calibrationData[3] * dT) &gt;&gt; 8)-SENS2); \/\/second order compensation included\r\nP = (((D1 * SENS) &gt;&gt; 21) - OFF) &gt;&gt; 15; \r\nreturn P; \/\/returns back into main loop data about pressure P\r\n}\r\n\r\nlong getData(byte command, int del) \/\/function to getting data from the sensor\r\n{\r\nlong result = 0;\r\ntwiSendCommand(0x77, command);\r\ndelay(del);\r\ntwiSendCommand(0x77, 0x00);\r\nTinyWireM.requestFrom(0x77, 3);\r\nif(TinyWireM.available()!=3);  \/\/ serial print je bio ovdje\r\n\r\nfor (int i = 0; i &lt;= 2; i++)\r\n{\r\nresult = (result&lt;&lt;8) | TinyWireM.read(); \/\/read\r\n}\r\nreturn result;\r\n}\r\n\r\n\/\/lets setup darn sensor :)\r\nvoid setupSensor()\r\n{\r\n\r\ntwiSendCommand(0x77, 0x1e);\r\ndelay(1000); \/\/timing important - 1 ms = 1 ms * 100\r\n\r\nfor (byte i = 1; i &lt;=6; i++)\r\n{\r\nunsigned int low, high;\r\n\r\ntwiSendCommand(0x77, 0xa0 + i * 2);\r\nTinyWireM.requestFrom(0x77, 2);\r\nif(TinyWireM.available()!=2);\/\/ Serial.println(\"Error: calibration data not available\"); *\/\r\nhigh = TinyWireM.read();\r\nlow = TinyWireM.read(); \/\/read\r\ncalibrationData[i] = high&lt;&lt;8 | low;\r\n}\r\n}\r\n\r\n\/\/twi, whatsoever this means\r\nvoid twiSendCommand(byte address, byte command)\r\n{\r\n  TinyWireM.beginTransmission(address);\r\n  TinyWireM.write(command); \/\/write\r\n  TinyWireM.endTransmission();\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<h2>Base station<\/h2>\n<p>Base station has OLED display for now, because found only this one. Later will consider make various options; OLED, TFT, numeric LCD, graphic LCD&#8230;<\/p>\n<p>Just need time&#8230; First code for base station is here (sorry, no diagram yet, working whole night &#8211; for those who found this page in the meanwhile)<\/p>\n<h2>EDITED, forgot to assign Arduino Pin 9 and Pin 10 to the button and switch.<\/h2>\n<p>It is used later in program, but somehow forgot to set it in setup() function. It is &#8216;pinMode(9,INPUT);&#8217; , as well as &#8216;pinMode(10,INPUT);&#8217;, also internal pull-up resistor &#8216;digitalWrite(9,HIGH);&#8217; and &#8216;digitalWrite(10,HIGH);&#8217;\u00a0 :<\/p>\n<pre class=\"theme:classic h-align:2 lang:c++ decode:true \">\/\/ Altimeter code by Milan Karaka\u0161 2016\r\n\/\/ Revision 2 - some precission errors corrected\r\n\/\/ Revision 3 - sorted OLED screen; first screen showing Actual Altitude\r\n\/\/ and Maximum reached Altitude, second screen showing barometric pressure\r\n\/\/ Humidity and temperature sensors showing humidity and temperature on \r\n\/\/ the base station - very important is to know humidity, because every \r\n\/\/ flying object 'float' better when humidity is low (!)\r\n\r\n#include &lt;VirtualWire.h&gt;\r\n#include &lt;SPI.h&gt;\r\n#include &lt;Wire.h&gt;\r\n#include &lt;Adafruit_SSD1306.h&gt;\r\n#include &lt;DHT.h&gt;\r\n\r\n#define DHTPIN 2\r\n#define DHTTYPE DHT22\r\n#define OLED_RESET 4\r\nAdafruit_SSD1306 display(OLED_RESET);\r\n#define degree_GLCD_HEIGHT 8\r\n#define degree_GLCD_WIDTH 8\r\nDHT dht(DHTPIN, DHTTYPE);\r\nstatic const unsigned char PROGMEM degree_glcd_bmp[]=\r\n{0x60, 0x90, 0x90, 0x60, 0x0,};\r\nfloat altitude, maxAltitude,setpress,t,h;\r\n\r\nuint8_t buf[7];\r\nuint8_t buflen = 7;\r\nlong P;\r\nbyte ID, myTX=0x2A; \/\/be sure that on your TX, the same ID \"myTX is the same\", here 0x2A hexacecmal\r\nfloat volt;\r\nfloat battOK=3.7; \/\/minimum desired voltage for safe flight\r\n\r\nvoid setup()\r\n{\r\npinMode(9,INPUT); \/\/this pin I forgot to include! Sorry people. \r\ndigitalWrite(9,HIGH); \/\/this one serves instead external 'pull-up' resistor - every time you have INPUT and provide HIGH to the output, it internally enable that resistor.\r\npinMode(10,INPUT); \/\/also this one for switching display for various data sets.\r\ndigitalWrite(10,HIGH);\/\/I think that one needs to, but actually this is switch, pin 10 goes to GND for one display option, or to +5V (or 3.3V) for another display option. Will turn pull-up resistor just in case.\r\ndisplay.begin(SSD1306_SWITCHCAPVCC, 0x3c);  \/\/ initialize with the I2C addr 0x3C (for the 128x32)\r\ndisplay.clearDisplay();\r\nvw_set_rx_pin(7);\r\nvw_setup(4800);\r\nvw_rx_start();\r\ndht.begin();\r\n}\r\n\r\nvoid loop()\r\n{\r\n  if (vw_get_message(buf,&amp;buflen)) \r\n   {\r\n     byte ID=buf[0];\r\n   if (ID==myTX) \r\n   \/\/ if vehicle ID is wrong, it will just freeze last result, and do nothing\r\n   \/\/ until \"proper\" connection is established, or proper ID is read - in the\r\n   \/\/ case of more than one vehicle, each other will NOT listen (no 'crosstalk', \r\n   \/\/ so it will not showing wrong data - just vehicle which has proper ID\r\n   {\r\n     long P=((long)buf[1])+((long)buf[2]&lt;&lt;8)+((long)buf[3]&lt;&lt;16)+((long)buf[4]&lt;&lt;24);\r\n     float volt=((buf[5])+(buf[6]&lt;&lt;8))\/(float)100;\r\n     if (volt&lt;battOK) \r\n      {\r\n      tone(3,800); \r\n      delay(50);\r\n      noTone(3);\r\n      }\r\n     int line = (64-((volt-3.3)*71));\r\n     altitude=145366.45*(1-pow(((P\/(float)100)\/(setpress\/(float)100)),0.190284));\r\n    \r\n  \/\/ Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)\r\n  float h = dht.readHumidity();\r\n  \/\/ Read temperature as Celsius\r\n  float t = dht.readTemperature();\r\n\r\n     if (maxAltitude&lt;=altitude) {maxAltitude=altitude;}\r\n\r\n     if (digitalRead(9)==1)\r\n      { delay(100);\r\n      \/\/by pressing button, Actual Altitude, and Maximum or Memorized Altitude\r\n      \/\/is set to zero as well\r\n      \/\/In the case of some major error, please press reset button on your Arduino\r\n       setpress=P; \r\n       maxAltitude=altitude;\r\n      }\r\n\r\n     if (digitalRead(10)==1)\r\n      {\r\n        \/\/write results, A: stands for Actual Altitude, \r\n        \/\/M: stands for Maximum or Memorized Altitude\r\n        display.clearDisplay();\r\n        display.setTextSize(2);\r\n        display.setTextColor(1);\r\n        display.setCursor(0,0);\r\n        display.print(\"A:\");\r\n        display.print(altitude,1);\r\n        display.setCursor(0,16);\r\n        display.setTextSize(2);\r\n        display.print(\"A:\");\r\n        display.print(altitude*0.3048,1);\r\n        display.setTextSize(2);\r\n        display.setCursor(0,32);\r\n        display.print(\"M:\");\r\n        display.println(maxAltitude,1);\r\n        display.print(\"M:\");\r\n        display.print(maxAltitude*0.3048,1);\r\n        \/\/write designations as is feet and meters (ft, m)\r\n        display.setTextSize(1);\r\n        display.setCursor(113,3);\r\n        display.println(\"ft\");\r\n        display.setCursor(118,19);\r\n        display.setTextSize(1);\r\n        display.print(\"m\");\r\n        display.setCursor(113,36);\r\n        display.print(\"ft\");\r\n        display.setCursor(118,51);\r\n        display.print(\"m\");\r\n        display.drawLine(127,64,127,line,1);\r\n        display.display();\r\n      }\r\n      else \r\n      {\r\n        \/\/if switch is in different postion, show Actual Pressure,\r\n        \/\/humidity and temperature for weather station + battery status\r\n        display.clearDisplay();\r\n        display.setTextSize(2);\r\n        display.setTextColor(1);\r\n        display.setCursor(0,0);\r\n        display.print(\"P:\");\r\n        display.print((float)P\/100,2);\r\n        display.setCursor(0,48);\r\n        display.print(\"Bat: \");\r\n        display.print((float)volt,2);\r\n\r\n        display.setTextSize(2);\r\n        display.setCursor(0,16);\r\n        display.print(\"H:  \");\r\n        display.println(h,2);\r\n        display.print(\"T:  \");\r\n        display.print(t,2);\r\n        \/\/lets make some symbols\r\n        display.setTextSize(1);\r\n        display.setCursor(108,03);\r\n        display.println(\" mb\");\r\n        display.setCursor(117,18);\r\n        display.print(\"%\");\r\n        \/\/Bitmap for symbol for degrees \r\n        display.drawBitmap(110,31,degree_glcd_bmp,8,8,1);\r\n        display.setCursor(115,31);\r\n        display.setTextSize(2);\r\n        display.print(\"C\");\r\n        display.setCursor(115,48);\r\n        display.print(\"V\");\r\n                display.setCursor(118,51);\r\n        display.print(\"m\");\r\n        display.drawLine(127,64,127,line,1);\r\n        display.display();\r\n      }\r\n   }\r\n   \/\/ if this point is reached, probably ID is wrong, and it will back into loop again\r\n   \/\/else if (ID!=myTX) {tone(3,3000);delay(50);noTone(3);} \r\n   \/\/do not apply code above - too loud, headache :D just leave it \"open\" to back into loop\r\n   \r\n   }\r\n\r\n }\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>The same <a href=\"https:\/\/www.banggood.com\/MS5611-GY-63-Atmospheric-Pressure-Sensor-Module-IICSPI-Communication-p-965980.html?p=EH10221611330201505Q\">MS5611<\/a> sensor is used in <a href=\"https:\/\/wildlab.org\/index.php\/2015\/07\/07\/arduino-variometer\/\">Arduino variometer<\/a>. And it is cheaper than ever on Banggood.com<\/p>\n<h2>This is all for now<\/h2>\n<p>Come back soon, will be updated&#8230; Escpecially diagram and videos&#8230; 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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230; Don&#8217;t know what to do&#8230; OLED display take 1024 bytes (1 kB), maybe I should to consider different display? Altimeter programming &hellip; <a href=\"https:\/\/wildlab.org\/index.php\/2016\/03\/11\/arduino-altimeter\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Arduino altimeter<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18,29,1],"tags":[87,5,89,91,88,6,7,90,67],"_links":{"self":[{"href":"https:\/\/wildlab.org\/index.php\/wp-json\/wp\/v2\/posts\/642"}],"collection":[{"href":"https:\/\/wildlab.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wildlab.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wildlab.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wildlab.org\/index.php\/wp-json\/wp\/v2\/comments?post=642"}],"version-history":[{"count":48,"href":"https:\/\/wildlab.org\/index.php\/wp-json\/wp\/v2\/posts\/642\/revisions"}],"predecessor-version":[{"id":1905,"href":"https:\/\/wildlab.org\/index.php\/wp-json\/wp\/v2\/posts\/642\/revisions\/1905"}],"wp:attachment":[{"href":"https:\/\/wildlab.org\/index.php\/wp-json\/wp\/v2\/media?parent=642"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wildlab.org\/index.php\/wp-json\/wp\/v2\/categories?post=642"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wildlab.org\/index.php\/wp-json\/wp\/v2\/tags?post=642"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}