{"id":16257,"date":"2020-05-11T22:35:06","date_gmt":"2020-05-12T02:35:06","guid":{"rendered":"https:\/\/scruss.com\/blog\/?p=16257"},"modified":"2020-05-13T10:21:22","modified_gmt":"2020-05-13T14:21:22","slug":"micropython-on-the-terrible-old-esp8266-12-development-board","status":"publish","type":"post","link":"https:\/\/scruss.com\/blog\/2020\/05\/11\/micropython-on-the-terrible-old-esp8266-12-development-board\/","title":{"rendered":"MicroPython on the terrible old ESP8266-12 Development Board"},"content":{"rendered":"\n<figure class=\"wp-block-video aligncenter\"><video height=\"384\" style=\"aspect-ratio: 320 \/ 384;\" width=\"320\" controls src=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2020\/05\/binary8266g.mp4\"><\/video><figcaption>\u00e2\u20ac\u00a6 + 1 + 1 + 1 \u00e2\u20ac\u00a6<\/figcaption><\/figure>\n\n\n\n<p>I just found my first ESP8266 dev board. This was from way back before Arduino support, and long before MicroPython <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"400\" height=\"311\" src=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2020\/05\/esp8266-12_mod.jpg\" alt=\"\" class=\"wp-image-16258\" srcset=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2020\/05\/esp8266-12_mod.jpg 400w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2020\/05\/esp8266-12_mod-320x249.jpg 320w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2020\/05\/esp8266-12_mod-160x124.jpg 160w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><figcaption><a href=\"https:\/\/www.esp8266.com\/wiki\/doku.php?id=esp8266-dev-boards\">esp8266-dev-boards<\/a> from ESP8266 Support WIKI<\/figcaption><\/figure><\/div>\n\n\n\n<p>It&#8217;s not really in a useful form factor, but it&#8217;s got some sensors and outputs:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>an LDR on the ADC channel<\/li><li>RGB LED for PWM on pins 15, 12 &amp; 13<\/li><li>red LEDs pins 16, 14, 5, 4, 0, 2 with inverted logic: set them low to light them.<\/li><\/ul>\n\n\n\n<p>My board can&#8217;t quite be the earliest of the early, as it has 1 MB of flash. This is enough to install <a href=\"https:\/\/micropython.org\/\">MicroPython<\/a>, so I wrote a tiny test program for the outputs:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>run a binary counter every second on the six red LEDs;<\/li><li>cycle through a <a href=\"https:\/\/scruss.com\/blog\/2019\/03\/23\/hsvish-colour-wheel-in-python\/\">colour wheel<\/a> on the RGB LED while this is happening.<\/li><\/ul>\n\n\n\n<p>Here&#8217;s the code:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# esp8266 old explorer board\n# see https:\/\/www.esp8266.com\/wiki\/lib\/exe\/detail.php?id=esp8266-dev-boards&amp;media=esp8266-12_mod.png\n\nfrom time import sleep\nfrom machine import Pin, PWM\n# LEDs are 16, 14, 5, 4, 0, 2 - L to R\n# inverted logic: 1 = off\nleds = &#x5B;Pin(2, Pin.OUT, value=1), Pin(0, Pin.OUT, value=1), Pin(4, Pin.OUT, value=1), Pin(\n    5, Pin.OUT, value=1), Pin(14, Pin.OUT, value=1), Pin(16, Pin.OUT, value=1)]\n\n# RGB for PWM on &#x5B;15, 12, 13]\nrgb = (PWM(Pin(15)), PWM(Pin(12)), PWM(Pin(13)))\n# LDR on ADC\n\n\ndef cos_wheel(pos):\n    # Input a value 0 to 255 to get a colour value.\n    # scruss (Stewart Russell) - 2019-03 - CC-BY-SA\n    from math import cos, pi\n    if pos &lt; 0:\n        return (0, 0, 0)\n    pos %= 256\n    pos \/= 255.0\n    return (int(255 * (1 + cos(pos * 2 * pi)) \/ 2),\n            int(255 * (1 + cos((pos - 1 \/ 3.0) * 2 * pi)) \/ 2),\n            int(255 * (1 + cos((pos - 2 \/ 3.0) * 2 * pi)) \/ 2))\n\n\ni = 1\nwhile True:\n    i = i + 1\n    i = i % 64\n    w = cos_wheel(4 * i)\n    for j in range(3):\n        rgb&#x5B;j].duty(4 * w&#x5B;j])\n\n    for k in range(6):\n        if i &amp; (1 &lt;&lt; k):\n            leds&#x5B;k].value(0)\n        else:\n            leds&#x5B;k].value(1)\n    sleep(1)\n\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>I just found my first ESP8266 dev board. This was from way back before Arduino support, and long before MicroPython It&#8217;s not really in a useful form factor, but it&#8217;s got some sensors and outputs: an LDR on the ADC channel RGB LED for PWM on pins 15, 12 &amp; 13 red LEDs pins 16, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7],"tags":[],"class_list":["post-16257","post","type-post","status-publish","format-standard","hentry","category-computers-suck"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pQNZZ-4ed","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/16257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/comments?post=16257"}],"version-history":[{"count":2,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/16257\/revisions"}],"predecessor-version":[{"id":16264,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/16257\/revisions\/16264"}],"wp:attachment":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/media?parent=16257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/categories?post=16257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/tags?post=16257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}