{"id":17044,"date":"2022-07-01T16:58:13","date_gmt":"2022-07-01T20:58:13","guid":{"rendered":"https:\/\/scruss.com\/blog\/?p=17044"},"modified":"2024-05-04T08:47:55","modified_gmt":"2024-05-04T12:47:55","slug":"the-quite-rubbish-clock-mk-2","status":"publish","type":"post","link":"https:\/\/scruss.com\/blog\/2022\/07\/01\/the-quite-rubbish-clock-mk-2\/","title":{"rendered":"The Quite Rubbish Clock, mk.2"},"content":{"rendered":"\n<figure class=\"wp-block-video\"><video height=\"360\" style=\"aspect-ratio: 640 \/ 360;\" width=\"640\" controls poster=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2022\/07\/quite_rubbish_clock-mk2.jpg\" src=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2022\/07\/quite_rubbish_clock-mk2.mp4\"><\/video><figcaption class=\"wp-element-caption\">this is bad and I should feel bad<\/figcaption><\/figure>\n\n\n\n<p>In early 2013, I must&#8217;ve been left unsupervised for too long since I made <a href=\"https:\/\/scruss.com\/blog\/2013\/01\/19\/the-quite-rubbish-clock\/\">The Quite Rubbish Clock<\/a>:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"qrclock - the Quite Rubbish clock\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/PyvJUN5JRkM?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><figcaption class=\"wp-element-caption\">It <em>still<\/em> isn&#8217;t human readable &#8230;<\/figcaption><\/figure>\n\n\n\n<p>Written in (<em>Owen Wilson voice<\/em>) kind of an obsolete vernacular and running on hardware that&#8217;s now best described as &#8220;quaint&#8221;, it was still absurdly popular at the time. Raspberry Pis were still pretty new, and people were looking for different things to do with them.<\/p>\n\n\n\n<p>I happened across the <a href=\"https:\/\/github.com\/JASchilz\/uQR\">JASchilz\/uQR: QR Code Generator for MicroPython<\/a> the other day, and remembered I had some tiny OLED screens that were about the same resolution as the old Nokia I&#8217;d used in 2013. I wondered: <em>could I \u2026?<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"960\" src=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2022\/07\/quite_rubbish_clock-mk2-1.jpg\" alt=\"small microcontroller board with USB C cable attached and an OLED screen on top. The OLED is displaying a QR code which reads '172731'\" class=\"wp-image-17047\" srcset=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2022\/07\/quite_rubbish_clock-mk2-1.jpg 720w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2022\/07\/quite_rubbish_clock-mk2-1-240x320.jpg 240w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2022\/07\/quite_rubbish_clock-mk2-1-120x160.jpg 120w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><figcaption class=\"wp-element-caption\">OLED Shield on a LOLIN S2 Mini: very smol indeed<\/figcaption><\/figure>\n\n\n\n<p>The board is a <a href=\"https:\/\/www.aliexpress.com\/item\/1005003145192016.html?spm=a2g0o.order_detail.0.0.cfbef19chvXF1I\">LOLIN S2 Mini<\/a> with a <a href=\"https:\/\/www.aliexpress.com\/item\/32627787079.html\">OLED 0.66 Inch Shield<\/a> on top, all running <a href=\"https:\/\/micropython.org\/download\/LOLIN_S2_MINI\/\">MicroPython<\/a>. One limitation I found in the MicroPython QR library was that it was very picky about input formats, so it only displays the time as <em>HHMMSS<\/em> with no separators.<\/p>\n\n\n\n<p>Source, of course:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# -*- coding: utf-8 -*-\n# yes, the Quite Rubbish Clock rides again ...\n# scruss, 2022-06-30\n# MicroPython on Lolin S2 Mini with 64 x 48 OLED display\n# uses uQR from https:\/\/github.com\/JASchilz\/uQR\n# - which has problems detecting times with colons\n\nfrom machine import Pin, I2C, RTC\nimport s2mini  # on Lolin ESP32-S2 Mini\nimport ssd1306\nfrom uQR import QRCode\n\nWIDTH = 64  # screen size\nHEIGHT = 48\nSIZE = 8  # text size\nr = RTC()\n\n# set up and clear screen\ni2c = I2C(0, scl=Pin(s2mini.I2C_SCL), sda=Pin(s2mini.I2C_SDA))\noled = ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c)\noled.fill(0)\n\n\ndef snazz():\n    marquee = &#x5B;\n        &quot;   **&quot;,\n        &quot;   **&quot;,\n        &quot;   **&quot;,\n        &quot;   **&quot;,\n        &quot;   **&quot;,\n        &quot;********&quot;,\n        &quot; ******&quot;,\n        &quot;  ****&quot;,\n        &quot;   **&quot;,\n        &quot; quite&quot;,\n        &quot;rubbish&quot;,\n        &quot; clock&quot;,\n        &quot;  mk.2&quot;,\n        &quot;&lt;scruss&gt;&quot;,\n        &quot; &gt;2022&lt;&quot;\n    ]\n    for s in marquee:\n        oled.scroll(0, -SIZE)  # scroll up one text line\n        oled.fill_rect(0, HEIGHT-SIZE, WIDTH,\n                       SIZE, 0)  # blank last line\n        oled.text(&quot;%-8s&quot; % s, 0, HEIGHT-SIZE)  # write text\n        oled.show()\n        time.sleep(0.25)\n    time.sleep(5)\n    oled.fill(1)\n    oled.show()\n\n\nsnazz()  # tedious crowd-pleasing intro\n\nqr = QRCode()\nwhile True:\n    qr.add_data(&quot;%02d%02d%02d&quot; % r.datetime()&#x5B;4:7])\n    qr.border = 1  # default border too big to fit small screen\n    m = qr.get_matrix()\n    oled.fill(1)\n    for y in range(len(m)):\n        for x in range(len(m&#x5B;0])):\n            # plot a double-sized QR code, centred, inverted\n            oled.fill_rect(9 + 2*x, 1 + 2*y, 2, 2, not m&#x5B;y]&#x5B;x])\n    oled.show()\n    time.sleep(0.05)\n    qr.clear()\n\n<\/pre><\/div>\n\n\n<p>If your output is glitchy, you might need to put the following in <strong>boot.py<\/strong>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nimport machine\nmachine.freq(240000000)\n<\/pre><\/div>\n\n\n<p>This increases the ESP32-S2&#8217;s frequency from 160 to 240 MHz.<\/p>\n\n\n\n<p><strong>Update<\/strong>: there&#8217;s a fork of uQR that provides better character support, particularly those required for sending <a href=\"https:\/\/github.com\/zxing\/zxing\/wiki\/Barcode-Contents#wi-fi-network-config-android-ios-11\">Wi-Fi Network config<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In early 2013, I must&#8217;ve been left unsupervised for too long since I made The Quite Rubbish Clock: Written in (Owen Wilson voice) kind of an obsolete vernacular and running on hardware that&#8217;s now best described as &#8220;quaint&#8221;, it was still absurdly popular at the time. Raspberry Pis were still pretty new, and people were [&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,2],"tags":[2612,3094,2110,2609],"class_list":["post-17044","post","type-post","status-publish","format-standard","hentry","category-computers-suck","category-goatee-stroking-musing-or-something","tag-lcd","tag-micropython","tag-pointless","tag-qrcode"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pQNZZ-4qU","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/17044","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=17044"}],"version-history":[{"count":3,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/17044\/revisions"}],"predecessor-version":[{"id":17552,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/17044\/revisions\/17552"}],"wp:attachment":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/media?parent=17044"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/categories?post=17044"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/tags?post=17044"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}