{"id":808,"date":"2021-04-24T09:35:06","date_gmt":"2021-04-24T07:35:06","guid":{"rendered":"https:\/\/outpost.garf.de\/wordpress\/?p=808"},"modified":"2021-04-25T10:44:46","modified_gmt":"2021-04-25T08:44:46","slug":"building-an-anemometer-part-2","status":"publish","type":"post","link":"https:\/\/outpost.garf.de\/wordpress\/index.php\/2021\/04\/24\/building-an-anemometer-part-2\/","title":{"rendered":"Building an Anemometer &#8211; Part 2"},"content":{"rendered":"<p>In this part I write about the microcontroller I am using and the code. Recently the Raspberry Pi Foundation <a href=\"https:\/\/www.raspberrypi.org\/products\/raspberry-pi-pico\/\">released a completely new designed microcontroller<\/a> which can be programmed with <a href=\"https:\/\/micropython.org\">MicroPython<\/a>. Named the <a href=\"https:\/\/en.wikipedia.org\/wiki\/RP2040\">RP2040<\/a>, it is somewhat limited as it does not have Wifi or any other means of wireless communication on board, but it has plenty of ports and is actually even a dual-core controller! So I needed to find a project where I can use it and the Anemometer is a perfect fit.<\/p>\n\n\n\n<p>In fact, the Microcontroller does not have much to do here, its tasks are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Count the revolutions of the rotating part<\/li><li>Report that count every minute<\/li><\/ul>\n\n\n\n<p>This is really not much. For a sensor I decided to try an Hall sensor (lots of cheap devices use reed relay instead, but a) it has moving parts and b) there is a risk that it bounces and delivers false measurements). If you look at the photo on top you can see the sensor on the right. <\/p>\n\n\n\n<p>So I just wired the sensor to the controller and wrote a (very small) Python program to do the count and reporting:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import time\nfrom machine import Pin\n\nhall = Pin(0,Pin.IN,Pin.PULL_UP)\nled = Pin(25,Pin.OUT)\n\ntopic = \"\/Chattenweg5\/2OG-Loggia\/wind\"\nprev = 0\ncount = 0\ninterval = 60\n\nlastRead = time.time()\n\nwhile True:\n    v = hall.value()\n    if v != prev:\n        if v == 0:\n            count += 1\n            led.high()\n            # print(count)\n        else:\n            led.low()\n        prev = v\n    if (time.time() &gt;= lastRead + interval):\n        print(topic,count)\n        lastRead = time.time()\n        count = 0<\/code><\/pre>\n\n\n\n<p>I actually just started to learn Python. Weird language if you know C and Perl. But quite capable. The code should be pretty self-explaining, I check if the input value of the sensor has changed, if yes, I do something (count, LED on\/off), and every minute I report the count (with maximum about 200 events per minute it is not really worth it doing this multi-threaded.<\/p>\n\n\n\n<p>I glued the sensor into the anemometer, for the controller I included a clip into the print. See below how it looks like.<\/p>\n\n\n\r\n\t\t\t\t<div\r\n\t\t\t\t\tid=\"wppa-container-wrapper-1\"\r\n\t\t\t\t\tclass=\"alignleft wppa-container-wrapper \"\r\n\t\t\t\t\tstyle=\"clear:left; width:350px;float:left;margin-right:10px;padding:0;position:relative;\"\r\n\t\t\t\t\t>\r\n\t\t<div\r\n\t\t\tid=\"wppa-container-1\"\r\n\t\t\tstyle=\"width:100%;\"\r\n\t\t\tclass=\"wppa-container alignleft wp-caption\"\r\n\t\t\t><div style=\"font-size:0;line-height:0\"><img decoding=\"async\" id=\"ph-401-1\" title=\"IMG_1986_jpg.jpg\" style=\"width:100%;margin:0;padding:0;border:none;\" src=\"https:\/\/outpost.garf.de\/wordpress\/wp-content\/uploads\/wppa\/401.jpg?ver=1\" alt=\"IMG_1986_jpg.jpg\" class=\"size-medium wppa-xphoto\"><\/div><div class=\"wp-caption-text\"><\/div><svg id=\"wppa-ajax-spin-1\" class=\"wppa-ajax-spin uil-default\" width=\"120px\" height=\"120px\" viewBox=\"0 0 100 100\" preserveAspectRatio=\"xMidYMid\" stroke=\"\" style=\"\n\t\t\t\twidth:120px;\n\t\t\t\theight:120px;\n\t\t\t\tposition:fixed;\n\t\t\t\ttop:50%;\n\t\t\t\tmargin-top:-60px;\n\t\t\t\tleft:50%;\n\t\t\t\tmargin-left:-60px;\n\t\t\t\topacity:1;\n\t\t\t\tdisplay:none;\n\t\t\t\tfill:#666666;\n\t\t\t\tbackground-color:transparent;\n\t\t\t\tborder-radius:24px;\"><rect x=\"0\" y=\"0\" width=\"100\" height=\"100\" fill=\"none\" class=\"bk\" ><\/rect><rect class=\"wppa-ajaxspin\"  x=\"47\" y=\"40\" width=\"6\" height=\"20\" rx=\"3\" ry=\"3\" transform=\"rotate(0 50 50) translate(0 -32)\"><animate attributeName=\"opacity\" from=\"1\" to=\"0\" dur=\"1.5s\" begin=\"0s\" repeatCount=\"indefinite\"\/><\/rect><rect class=\"wppa-ajaxspin\"  x=\"47\" y=\"40\" width=\"6\" height=\"20\" rx=\"3\" ry=\"3\" transform=\"rotate(22.5 50 50) translate(0 -32)\"><animate attributeName=\"opacity\" from=\"1\" to=\"0\" dur=\"1.5s\" begin=\"0.09375s\" repeatCount=\"indefinite\"\/><\/rect><rect class=\"wppa-ajaxspin\"  x=\"47\" y=\"40\" width=\"6\" height=\"20\" rx=\"3\" ry=\"3\" transform=\"rotate(45 50 50) translate(0 -32)\"><animate attributeName=\"opacity\" from=\"1\" to=\"0\" dur=\"1.5s\" begin=\"0.1875s\" repeatCount=\"indefinite\"\/><\/rect><rect class=\"wppa-ajaxspin\"  x=\"47\" y=\"40\" width=\"6\" height=\"20\" rx=\"3\" ry=\"3\" transform=\"rotate(67.5 50 50) translate(0 -32)\"><animate attributeName=\"opacity\" from=\"1\" to=\"0\" dur=\"1.5s\" begin=\"0.28125s\" repeatCount=\"indefinite\"\/><\/rect><rect class=\"wppa-ajaxspin\"  x=\"47\" y=\"40\" width=\"6\" height=\"20\" rx=\"3\" ry=\"3\" transform=\"rotate(90 50 50) translate(0 -32)\"><animate attributeName=\"opacity\" from=\"1\" to=\"0\" dur=\"1.5s\" begin=\"0.375s\" repeatCount=\"indefinite\"\/><\/rect><rect class=\"wppa-ajaxspin\"  x=\"47\" y=\"40\" width=\"6\" height=\"20\" rx=\"3\" ry=\"3\" transform=\"rotate(112.5 50 50) translate(0 -32)\"><animate attributeName=\"opacity\" from=\"1\" to=\"0\" dur=\"1.5s\" begin=\"0.46875s\" repeatCount=\"indefinite\"\/><\/rect><rect class=\"wppa-ajaxspin\"  x=\"47\" y=\"40\" width=\"6\" height=\"20\" rx=\"3\" ry=\"3\" transform=\"rotate(135 50 50) translate(0 -32)\"><animate attributeName=\"opacity\" from=\"1\" to=\"0\" dur=\"1.5s\" begin=\"0.5625s\" repeatCount=\"indefinite\"\/><\/rect><rect class=\"wppa-ajaxspin\"  x=\"47\" y=\"40\" width=\"6\" height=\"20\" rx=\"3\" ry=\"3\" transform=\"rotate(157.5 50 50) translate(0 -32)\"><animate attributeName=\"opacity\" from=\"1\" to=\"0\" dur=\"1.5s\" begin=\"0.65625s\" repeatCount=\"indefinite\"\/><\/rect><rect class=\"wppa-ajaxspin\"  x=\"47\" y=\"40\" width=\"6\" height=\"20\" rx=\"3\" ry=\"3\" transform=\"rotate(180 50 50) translate(0 -32)\"><animate attributeName=\"opacity\" from=\"1\" to=\"0\" dur=\"1.5s\" begin=\"0.75s\" repeatCount=\"indefinite\"\/><\/rect><rect class=\"wppa-ajaxspin\"  x=\"47\" y=\"40\" width=\"6\" height=\"20\" rx=\"3\" ry=\"3\" transform=\"rotate(202.5 50 50) translate(0 -32)\"><animate attributeName=\"opacity\" from=\"1\" to=\"0\" dur=\"1.5s\" begin=\"0.84375s\" repeatCount=\"indefinite\"\/><\/rect><rect class=\"wppa-ajaxspin\"  x=\"47\" y=\"40\" width=\"6\" height=\"20\" rx=\"3\" ry=\"3\" transform=\"rotate(225 50 50) translate(0 -32)\"><animate attributeName=\"opacity\" from=\"1\" to=\"0\" dur=\"1.5s\" begin=\"0.9375s\" repeatCount=\"indefinite\"\/><\/rect><rect class=\"wppa-ajaxspin\"  x=\"47\" y=\"40\" width=\"6\" height=\"20\" rx=\"3\" ry=\"3\" transform=\"rotate(247.5 50 50) translate(0 -32)\"><animate attributeName=\"opacity\" from=\"1\" to=\"0\" dur=\"1.5s\" begin=\"1.03125s\" repeatCount=\"indefinite\"\/><\/rect><rect class=\"wppa-ajaxspin\"  x=\"47\" y=\"40\" width=\"6\" height=\"20\" rx=\"3\" ry=\"3\" transform=\"rotate(270 50 50) translate(0 -32)\"><animate attributeName=\"opacity\" from=\"1\" to=\"0\" dur=\"1.5s\" begin=\"1.125s\" repeatCount=\"indefinite\"\/><\/rect><rect class=\"wppa-ajaxspin\"  x=\"47\" y=\"40\" width=\"6\" height=\"20\" rx=\"3\" ry=\"3\" transform=\"rotate(292.5 50 50) translate(0 -32)\"><animate attributeName=\"opacity\" from=\"1\" to=\"0\" dur=\"1.5s\" begin=\"1.21875s\" repeatCount=\"indefinite\"\/><\/rect><rect class=\"wppa-ajaxspin\"  x=\"47\" y=\"40\" width=\"6\" height=\"20\" rx=\"3\" ry=\"3\" transform=\"rotate(315 50 50) translate(0 -32)\"><animate attributeName=\"opacity\" from=\"1\" to=\"0\" dur=\"1.5s\" begin=\"1.3125s\" repeatCount=\"indefinite\"\/><\/rect><rect class=\"wppa-ajaxspin\"  x=\"47\" y=\"40\" width=\"6\" height=\"20\" rx=\"3\" ry=\"3\" transform=\"rotate(337.5 50 50) translate(0 -32)\"><animate attributeName=\"opacity\" from=\"1\" to=\"0\" dur=\"1.5s\" begin=\"1.40625s\" repeatCount=\"indefinite\"\/><\/rect><\/svg><\/div><\/div>\n<!-- End [photo 401] \/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/808 oc 1 29 queries in 20.3 ms. at 13:52. Max mem:  14.00 Mb.  -->\n\n\n\n<p>Next challenge will be to build an anemometer which is powered by wind and transmits wireless via LoRaWAN. Stay tuned.<\/p>","protected":false},"excerpt":{"rendered":"<p>In this part I write about the microcontroller I am using and the code. Recently the Raspberry Pi Foundation released a completely new designed microcontroller which can be programmed with MicroPython. Named the RP2040, it is somewhat limited as it does not have Wifi or any other means of wireless communication on board, but it [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":806,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"zakra_page_container_layout":"customizer","zakra_page_sidebar_layout":"customizer","zakra_remove_content_margin":false,"zakra_sidebar":"customizer","zakra_transparent_header":"customizer","zakra_logo":0,"zakra_main_header_style":"default","zakra_menu_item_color":"","zakra_menu_item_hover_color":"","zakra_menu_item_active_color":"","zakra_menu_active_style":"","zakra_page_header":true,"footnotes":""},"categories":[113],"tags":[],"class_list":["post-808","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microcontrollers"],"_links":{"self":[{"href":"https:\/\/outpost.garf.de\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/808","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/outpost.garf.de\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/outpost.garf.de\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/outpost.garf.de\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/outpost.garf.de\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=808"}],"version-history":[{"count":3,"href":"https:\/\/outpost.garf.de\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/808\/revisions"}],"predecessor-version":[{"id":814,"href":"https:\/\/outpost.garf.de\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/808\/revisions\/814"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/outpost.garf.de\/wordpress\/index.php\/wp-json\/wp\/v2\/media\/806"}],"wp:attachment":[{"href":"https:\/\/outpost.garf.de\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/outpost.garf.de\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/outpost.garf.de\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}