{"id":10,"date":"2015-07-07T03:25:17","date_gmt":"2015-07-07T01:25:17","guid":{"rendered":"http:\/\/wildlab.org\/?p=10"},"modified":"2019-03-25T06:39:40","modified_gmt":"2019-03-25T05:39:40","slug":"arduino-variometer","status":"publish","type":"post","link":"https:\/\/wildlab.org\/index.php\/2015\/07\/07\/arduino-variometer\/","title":{"rendered":"Arduino Variometer"},"content":{"rendered":"<h2>Notification for paragliders<\/h2>\n<p>Sorry for waiting that long. I found how to change Arduino code for paragliders. But I have no way to test it. If you need that for your paraglider or whatever flying thing, please leave me comment below. We need first test it, so that I can be sure that it works, then will upload this post. Thanks. Sensitivity can be changed in next line (original value is 50). line 31:<\/p>\n<pre class=\"lang:c++ decode:true \">toneFreq = (lowpassSlow \u2013 lowpassFast) * 10;<\/pre>\n<p>The main part is with silencing vario when no much ressure\/altitude change (now it is silent between certain points, experiment with those values -50 and 50, maybe -30\/30, or -70\/70, this is how much frequency will change with pressure change in time):<br \/>\nline 39:<\/p>\n<pre class=\"lang:c++ decode:true\">if (toneFreq &lt; -50 || toneFreq &gt; 50 &amp;&amp; ddsAcc &gt;0 )<\/pre>\n<p>Sorry, previous change on this web page was wrong for same reason. This one should work. I am not sure what happened, perhaps forgot to update.<\/p>\n<p>Please notify me after you confirm that it is useful for paragliders.<\/p>\n<p><!--more--><\/p>\n<p>Arduino variometer for those who fly RC <a href=\"http:\/\/www.hobbyking.com\/hobbyking\/store\/uh_viewitem.asp?idproduct=24654&amp;aff=1379661\" target=\"_blank\" rel=\"noopener noreferrer\">Gliders<\/a>, <a href=\"http:\/\/www.hobbyking.com\/hobbyking\/store\/uh_viewitem.asp?idproduct=44321&amp;aff=1379661\" target=\"_blank\" rel=\"noopener noreferrer\">DLGs<\/a>, and other motorized and non-motorized RC sailplanes, as well as &#8216;big brothers&#8217; &#8211; &#8216;manned&#8217; gliders and parachutes, indicating whether there is thermal or not, or better known as &#8220;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Rate_of_climb\" target=\"_blank\" rel=\"noopener noreferrer\">vertical speed indicator<\/a>&#8220;, or simple <a href=\"https:\/\/en.wikipedia.org\/wiki\/Variometer\" target=\"_blank\" rel=\"noopener noreferrer\">Vario <\/a>(this one is simplified version, without any display):<\/p>\n<p><iframe loading=\"lazy\" width=\"474\" height=\"267\" src=\"https:\/\/www.youtube.com\/embed\/xi1J3yifrDM?feature=oembed\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<h2>No radio? Direct audio mode:<\/h2>\n<p>Someone contacted me and asked if it is possible to use this vario without need for RF chip &#8211; for direct use. Answer is yes. Simply by adding crude audio amplifier to passive buzzer, which is actually speaker (loudspeaker). Sorry for ugly drawing.<\/p>\n<p><a href=\"https:\/\/wildlab.org\/wp-content\/uploads\/2015\/07\/Speaker.jpg\"><img loading=\"lazy\" class=\"aligncenter wp-image-927 size-large\" src=\"https:\/\/wildlab.org\/wp-content\/uploads\/2015\/07\/Speaker-1024x652.jpg\" alt=\"variometer\" width=\"474\" height=\"302\" srcset=\"https:\/\/wildlab.org\/wp-content\/uploads\/2015\/07\/Speaker.jpg 1024w, https:\/\/wildlab.org\/wp-content\/uploads\/2015\/07\/Speaker-300x191.jpg 300w\" sizes=\"(max-width: 474px) 100vw, 474px\" \/><\/a><\/p>\n<p>If you have small &#8220;magnetic&#8221; buzzer, as Banggood describes, and if it is passive, then capacitor is 100 nF (0.1 uF), because low frequency sounds will reproduce badly anyway of such small membrane of the speaker. If you use some bigger speaker, then consider to use 1 uF or more, the best value is 100 uF, but it is maybe overkill because any small loudspeaker that can fit in your hand has actually bad low tone reproduction. Passive buzzer on Banggood: <a href=\"http:\/\/www.banggood.com\/DC-1-30V-2-Pins-Passive-Electronic-Piezoelectric-Piezo-Buzzer-p-978657.html?p=EH10221611330201505Q\">BUZZER 1-5V<\/a><\/p>\n<p>Alternative option is to use 1W GPS (General Purpose Speaker) on eBay: <a href=\"http:\/\/www.ebay.com\/itm\/GPS-Loudspeaker-1W-8ohm-14x20mm-Small-Trumpet-14x20mm-Loud-Speaker-\/311512775871?hash=item48879bbcbf:g:ETgAAOSwfC9XOtqY\">1W GPS loudspeaker<\/a><\/p>\n<h2>Sidenote:<\/h2>\n<p>If you are sure that output on pin PD2 (or just 2 on Arudino pro mini V3) will not remain HIGH or digital 1, then you can omit this capacitor. DO NOT attach directly loudspeaker on the PD2 pin, because it has very low impedance and can ruin your Arduino. Although there is overcurent protection, I will not gamble with that. If sound is too loud, then add 1-500 Ohm resistor in series with loudspeaker. This way it will save power if you have battery powered device.<\/p>\n<p><a href=\"http:\/\/www.rcgroups.com\/forums\/showthread.php?t=1749208\" target=\"_blank\" rel=\"noopener noreferrer\">Schematic, for those who are lazy to visit <\/a><a href=\"http:\/\/www.rcgroups.com\/forums\/showthread.php?t=1749208\" target=\"_blank\" rel=\"noopener noreferrer\">RCgroups f<\/a><a href=\"http:\/\/www.rcgroups.com\/forums\/showthread.php?t=1749208\" target=\"_blank\" rel=\"noopener noreferrer\">orum<\/a>: <a href=\"https:\/\/wildlab.org\/wp-content\/uploads\/2015\/07\/Arduino-Vario.jpg\"><img loading=\"lazy\" class=\"aligncenter wp-image-130 size-large\" src=\"https:\/\/wildlab.org\/wp-content\/uploads\/2015\/07\/Arduino-Vario-1024x577.jpg\" alt=\"variometer\" width=\"474\" height=\"267\" srcset=\"https:\/\/wildlab.org\/wp-content\/uploads\/2015\/07\/Arduino-Vario-1024x577.jpg 1024w, https:\/\/wildlab.org\/wp-content\/uploads\/2015\/07\/Arduino-Vario-300x169.jpg 300w, https:\/\/wildlab.org\/wp-content\/uploads\/2015\/07\/Arduino-Vario.jpg 1598w\" sizes=\"(max-width: 474px) 100vw, 474px\" \/><\/a> Note that on <a href=\"http:\/\/www.banggood.com\/MS5611-GY-63-Atmospheric-Pressure-Sensor-Module-IICSPI-Communication-p-965980.html?p=EH10221611330201505Q\" target=\"_blank\" rel=\"noopener noreferrer\">MS5611<\/a>, there are used only four wires of seven. That is because other three wires are used in the case of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Serial_Peripheral_Interface_Bus\" target=\"_blank\" rel=\"noopener noreferrer\">SPI<\/a> connection instead <a href=\"https:\/\/en.wikipedia.org\/wiki\/I%C2%B2C\" target=\"_blank\" rel=\"noopener noreferrer\">I<sup>2<\/sup>C<\/a> as is on this schematic. Those &#8216;extra&#8217; three wires leave not connected (NC). Arduino sketch, hover with mouse over the top of the code, click on &#8220;copy&#8221;, then CTRL+C for copy to buffer, and CTRL+V to paste into your <a href=\"https:\/\/www.arduino.cc\/en\/Main\/Software\" target=\"_blank\" rel=\"noopener noreferrer\">Arduino IDE<\/a>:<\/p>\n<pre class=\"theme:classic h-align:2 lang:c++ decode:true \">\/\/ All code by Rolf R Bakke, Oct 2012\r\n\r\n#include &lt;Wire.h&gt;\r\n\r\nconst byte led = 13;\r\n\r\nunsigned int calibrationData[7];\r\nunsigned long time = 0;\r\n\r\nfloat toneFreq, toneFreqLowpass, pressure, lowpassFast, lowpassSlow ;\r\n\r\nint ddsAcc;\r\n\r\nvoid setup()\r\n{\r\nWire.begin();\r\nSerial.begin(115200);\r\nsetupSensor();\r\n\r\npressure = getPressure();\r\nlowpassFast = lowpassSlow = pressure;\r\n}\r\n\r\nvoid loop()\r\n{\r\npressure = getPressure();\r\n\r\nlowpassFast = lowpassFast + (pressure - lowpassFast) * 0.1;\r\nlowpassSlow = lowpassSlow + (pressure - lowpassSlow) * 0.05;\r\n\r\ntoneFreq = (lowpassSlow - lowpassFast) * 50;\r\n\r\ntoneFreqLowpass = toneFreqLowpass + (toneFreq - toneFreqLowpass) * 0.1;\r\n\r\ntoneFreq = constrain(toneFreqLowpass, -500, 500);\r\n\r\nddsAcc += toneFreq * 100 + 2000;\r\n\r\nif (toneFreq &lt; 0 || ddsAcc &gt; 0)\r\n{\r\ntone(2, toneFreq + 510);\r\n}\r\nelse\r\n{\r\nnoTone(2);\r\n}\r\n\r\nledOff();\r\nwhile (millis() &lt; time); \/\/loop frequency timer\r\ntime += 20;\r\nledOn();\r\n}\r\n\r\nlong getPressure()\r\n{\r\nlong D1, D2, dT, P;\r\nfloat TEMP;\r\nint64_t OFF, SENS;\r\n\r\nD1 = getData(0x48, 10);\r\nD2 = getData(0x50, 1);\r\n\r\ndT = D2 - ((long)calibrationData[5] &lt;&lt; 8);\r\nTEMP = (2000 + (((int64_t)dT * (int64_t)calibrationData[6]) &gt;&gt; 23)) \/ (float)100;\r\nOFF = ((unsigned long)calibrationData[2] &lt;&lt; 16) + (((int64_t)calibrationData[4] * dT) &gt;&gt; 7);\r\nSENS = ((unsigned long)calibrationData[1] &lt;&lt; 15) + (((int64_t)calibrationData[3] * dT) &gt;&gt; 8);\r\nP = (((D1 * SENS) &gt;&gt; 21) - OFF) &gt;&gt; 15;\r\n\r\n\/\/Serial.println(TEMP);\r\n\/\/Serial.println(P);\r\n\r\nreturn P;\r\n}\r\n\r\nlong getData(byte command, byte del)\r\n{\r\nlong result = 0;\r\ntwiSendCommand(0x77, command);\r\ndelay(del);\r\ntwiSendCommand(0x77, 0x00);\r\nWire.requestFrom(0x77, 3);\r\nif(Wire.available()!=3) Serial.println(\"Error: raw data not available\");\r\nfor (int i = 0; i &lt;= 2; i++)\r\n{\r\nresult = (result&lt;&lt;8) | Wire.read();\r\n}\r\nreturn result;\r\n}\r\n\r\nvoid setupSensor()\r\n{\r\ntwiSendCommand(0x77, 0x1e);\r\ndelay(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\nWire.requestFrom(0x77, 2);\r\nif(Wire.available()!=2) Serial.println(\"Error: calibration data not available\");\r\nhigh = Wire.read();\r\nlow = Wire.read();\r\ncalibrationData[i] = high&lt;&lt;8 | low;\r\nSerial.print(\"calibration data #\");\r\nSerial.print(i);\r\nSerial.print(\" = \");\r\nSerial.println( calibrationData[i] );\r\n}\r\n}\r\n\r\nvoid twiSendCommand(byte address, byte command)\r\n{\r\nWire.beginTransmission(address);\r\nif (!Wire.write(command)) Serial.println(\"Error: write()\");\r\nif (Wire.endTransmission())\r\n{\r\nSerial.print(\"Error when sending command: \");\r\nSerial.println(command, HEX);\r\n}\r\n}\r\n\r\nvoid ledOn()\r\n{\r\ndigitalWrite(led,1);\r\n}\r\n\r\nvoid ledOff()\r\n{\r\ndigitalWrite(led,0);\r\n}<\/pre>\n<h2>Debug option: &#8216;Serial.println&#8217;<\/h2>\n<p>This code by default has excluded serial print of temperature and pressure. For testing and debug of variometer &#8211; your circuit on serial monitor, remove &#8216;\/\/&#8217; tags before command lines, highlighted yellow on this picture: <a href=\"https:\/\/wildlab.org\/wp-content\/uploads\/2015\/07\/Arduino-sketch-vario.jpg\"><img loading=\"lazy\" class=\"aligncenter wp-image-134 size-full\" src=\"https:\/\/wildlab.org\/wp-content\/uploads\/2015\/07\/Arduino-sketch-vario.jpg\" alt=\"Arduino sketch variometer\" width=\"500\" height=\"600\" srcset=\"https:\/\/wildlab.org\/wp-content\/uploads\/2015\/07\/Arduino-sketch-vario.jpg 500w, https:\/\/wildlab.org\/wp-content\/uploads\/2015\/07\/Arduino-sketch-vario-250x300.jpg 250w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a> This Variometer is intended for RC models, as is <a href=\"http:\/\/www.hobbyking.com\/hobbyking\/store\/uh_viewitem.asp?idproduct=44321&amp;aff=1379661\" target=\"_blank\" rel=\"noopener noreferrer\">DLGs<\/a>, where &#8216;downlink&#8217; is provided by TX and RX on <a href=\"http:\/\/www.banggood.com\/433Mhz-RF-Transmitter-With-Receiver-Kit-For-Arduino-ARM-MCU-Wireless-p-74102.html?p=EH10221611330201505Q\" target=\"_blank\" rel=\"noopener noreferrer\">433 MHz<\/a>, but if you wish to hear sound directly &#8211; without the need to &#8216;broadcast&#8217; radio signal on 433 MHz, you may add capacitor of say 100 nF (or more for better low frequency reproduction) between pin &#8216;D2&#8217; on <a href=\"http:\/\/www.banggood.com\/ATmega328P-Nano-V3-Controller-Board-Compatible-Arduino-p-940937.html?p=EH10221611330201505Q\" target=\"_blank\" rel=\"noopener noreferrer\">Arduino nano<\/a> and the audio amplifier. This capacitor serve for galvanic deoupling for protection of Arduino and amplifier. Use small audio amlifier, something like this one: <a href=\"https:\/\/wildlab.org\/wp-content\/uploads\/2015\/07\/LM386-audio-amplifier.jpg\"><img loading=\"lazy\" class=\"size-full wp-image-135 aligncenter\" src=\"https:\/\/wildlab.org\/wp-content\/uploads\/2015\/07\/LM386-audio-amplifier.jpg\" alt=\"LM386 audio amplifier\" width=\"500\" height=\"168\" srcset=\"https:\/\/wildlab.org\/wp-content\/uploads\/2015\/07\/LM386-audio-amplifier.jpg 500w, https:\/\/wildlab.org\/wp-content\/uploads\/2015\/07\/LM386-audio-amplifier-300x101.jpg 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a> This amplifier is proven to work on low voltage, ranging from 4 to 12 Volts. The amplifier ($2.11 US): <a href=\"http:\/\/www.banggood.com\/LM386-Audio-Amplifier-Module-200-Times-Input-10K-Adjustable-Resistance-p-917571.html?p=EH10221611330201505Q\" target=\"_blank\" rel=\"noopener noreferrer\">LM386 audio amplifier on Banggood<\/a> Also, aside <a href=\"http:\/\/www.ebay.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">eBay<\/a> -you may find other parts on <a href=\"https:\/\/www.banggood.com\/?p=EH10221611330201505Q\" target=\"_blank\" rel=\"noopener noreferrer\">Banggood<\/a>. What is the difference &#8211; Banggood is more secure and reliable seller, unlike uncertain sellers on <a href=\"http:\/\/www.ebay.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">eBay<\/a> (many sellers are okay, but this is a &#8216;gamble&#8217; &#8211; sometimes frustrating and wasting time).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Notification for paragliders Sorry for waiting that long. I found how to change Arduino code for paragliders. But I have no way to test it. If you need that for your paraglider or whatever flying thing, please leave me comment below. We need first test it, so that I can be sure that it works, &hellip; <a href=\"https:\/\/wildlab.org\/index.php\/2015\/07\/07\/arduino-variometer\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Arduino Variometer<\/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":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/wildlab.org\/index.php\/wp-json\/wp\/v2\/posts\/10"}],"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=10"}],"version-history":[{"count":31,"href":"https:\/\/wildlab.org\/index.php\/wp-json\/wp\/v2\/posts\/10\/revisions"}],"predecessor-version":[{"id":2036,"href":"https:\/\/wildlab.org\/index.php\/wp-json\/wp\/v2\/posts\/10\/revisions\/2036"}],"wp:attachment":[{"href":"https:\/\/wildlab.org\/index.php\/wp-json\/wp\/v2\/media?parent=10"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wildlab.org\/index.php\/wp-json\/wp\/v2\/categories?post=10"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wildlab.org\/index.php\/wp-json\/wp\/v2\/tags?post=10"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}