{"id":1972,"date":"2023-01-02T01:22:38","date_gmt":"2023-01-01T17:22:38","guid":{"rendered":"https:\/\/104.es\/?p=1972"},"modified":"2023-01-02T01:22:38","modified_gmt":"2023-01-01T17:22:38","slug":"raspberry-pi-pico-ssd1306-linechart","status":"publish","type":"post","link":"https:\/\/104.es\/index.php\/2023\/01\/02\/raspberry-pi-pico-ssd1306-linechart\/","title":{"rendered":"Raspberry Pi Pico + SSD1306\u6298\u7dda\u5716"},"content":{"rendered":"\n<p>\u5728\u524d\u9762\u7684\u6587\u7ae0\u4e2d\u6211\u5011\u5b78\u6703\u4e86\u5982\u4f55\u5728Pico\/Pico W\u4e2d\u5229\u7528SSD1306\u9019\u500b\u5fae\u578b\u986f\u793a\u5668\u4f86\u8f38\u51fa\u6587\u5b57\uff0c\u4e5f\u5229\u7528pixel\u51fd\u5f0f\u7e6a\u88fd\u4e86\u4e00\u500bSIN\u51fd\u6578\u5716\u5f62\uff0c\u90a3\u9ebc\uff0c\u6211\u5011\u5728\u8cc7\u6599\u6536\u96c6\u7684\u904e\u7a0b\u4e2d\uff0c\u5982\u679c\u60f3\u8981\u628a\u9019\u4e9b\u8cc7\u6599\u7684\u5167\u5bb9\u4ee5\u6298\u7dda\u5716\u7684\u65b9\u5f0f\u5448\u73fe\u51fa\u4f86\uff0c\u8a72\u5982\u4f55\u7de8\u5beb\u7a0b\u5f0f\u5462\uff1f\u6211\u5011\u9019\u7bc7\u6587\u7ae0\u5c31\u4f86\u6559\u540c\u5b78\u5011\u5982\u4f55\u5728SSD1306\u7e6a\u88fd\u8cc7\u6599\u6298\u7dda\u5716\u3002<\/p>\n\n\n\n<p>\u60f3\u8981\u5728SSD1306\u7e6a\u88fd\u6298\u7dda\u5716\u6709\u5169\u500b\u91cd\u8981\u7684\u5730\u65b9\uff0c\u7b2c\u4e00\u500b\u662f\u77ad\u89e3\u5982\u4f55\u5728SSD1306\u7e6a\u88fd\u76f4\u7dda\u3002\u53c3\u8003\u524d\u9762\u7684\u6587\u7ae0\u8aaa\u660e\uff0c\u5728\u5efa\u7acb\u4e86SSD1306\u7684\u7269\u4ef6disp\u4e4b\u5f8c\uff0c\u4f7f\u7528disp.text(str, x,  y)\u53ef\u4ee5\u8f38\u51fa\u6587\u5b57\uff0cdisp.pixel(x, y, 1)\u53ef\u4ee5\u5728\u6307\u5b9a\u5ea7\u6a19\u7e6a\u88fd\u4e00\u500b\u50cf\u7d20\uff0c\u800cdisp.line(x1, y1, x2, y2, 1)\u5247\u53ef\u4ee5\u5728(x1, y1)-(x2, y2)\u4e4b\u9593\u7e6a\u88fd\u4e00\u689d\u76f4\u7dda\uff0c\u6211\u5011\u8981\u4f7f\u7528\u7684\u5c31\u662f\u9019\u500b\u529f\u80fd\u3002<\/p>\n\n\n\n<p>\u7b2c\u4e8c\u500b\u8981\u77e5\u9053\u7684\u662f\uff0c\u8981\u7e6a\u88fd\u6298\u7dda\u5716\u4f7f\u7528\u7684\u8cc7\u6599\u9ede\u3002\u7531\u65bcSSD1306\u7684\u89e3\u6790\u5ea6\u5728x\u8ef8\u70ba128\u9ede\uff0c\u4e5f\u5c31\u662f0~127\uff0c\u53ef\u4ee5\u5f97\u77e5\u9019\u6a23\u4ee5\u87a2\u5e55\u7684\u5bec\u5ea6\u6700\u591a\u53ef\u4ee5\u7e6a\u88fd128\u500b\u8cc7\u6599\u9ede\u3002\u6b64\u5916\uff0c\u5728y\u8ef8\u7684\u90e8\u4efd\uff0c\u7531\u65bc\u89e3\u6790\u5ea6\u53ea\u670964\uff0c\u800c\u4e0a\u65b9\u6211\u5011\u9084\u60f3\u8981\u986f\u793a\u4e00\u4e9b\u6587\u5b57\uff0c\u6240\u4ee5\u53ef\u4ee5\u4f7f\u7528\u7684\u7bc4\u570d\u4ee5\u4e0d\u8d85\u904e\u87a2\u5e55\u7684\u4e00\u534a\u70ba\u539f\u5247\uff0c\u4e5f\u5c31\u662f\u8aaa\uff0c\u8cc7\u6599\u80fd\u5920\u986f\u793a\u7684\u7bc4\u570d\u9700\u63a7\u5236\u57280~32\u4e4b\u9593\u3002<\/p>\n\n\n\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u6211\u5011\u6253\u7b97\u628a\u611f\u6e2c\u5230\u4eae\u5ea6\u7684\u5149\u654f\u96fb\u963b\u6240\u53d6\u5f97\u7684\u6578\u503c\u63db\u7b97\u6210\u767e\u5206\u6bd4\uff0c\u7136\u5f8c\u628a\u9019\u500b\u6bd4\u4f8b\u9664\u4ee5 2.5\uff0c\u8b93\u5b83\u53ef\u4ee5\u5448\u73fe\u7684\u7bc4\u570d\u7d04\u7565\u572830\u4e4b\u5167\uff08\u5982\u679c\u66f4\u6697\u4e00\u9ede\u53ef\u80fd\u6703\u8d85\u51fa\u7bc4\u570d\uff0c\u4f46\u662f\u5f88\u6697\u7684\u6642\u5019\u901a\u5e38\u6211\u5011\u4e0d\u6703\u89c0\u5bdf\u9019\u500b\u87a2\u5e55\uff0c\u6240\u4ee5\u5c31\u4ee5\u6b63\u5e38\u7684\u74b0\u5883\u4eae\u5ea6\u7bc4\u570d\u4f86\u770b\uff0c\u63db\u7b97\u5f8c\u5927\u7d04\u662f30%~90%\u4e4b\u9593\uff09\u3002\u5f9e\u611f\u6e2c\u5668\u4e2d\u53d6\u5f97\u7684\u6578\u503c\u90fd\u653e\u5728data\u9019\u500b\u4e32\u5217\u4e2d\uff0c\u4f46\u662f\u7576\u4e32\u5217\u4e2d\u7684\u8cc7\u6599\u9805\u76ee\u6578\u91cf\u8d85\u904e128\u6642\uff0c\u5c31\u628a\u7b2c0\u500b\u9805\u76ee\u62cb\u68c4\uff0c\u518d\u589e\u52a0\u65b0\u7684\u9805\u76ee\uff0c\u8b93\u4e32\u5217\u7684\u500b\u6578\u7dad\u6301\u5728128\u500b\u4ee5\u5167\u3002<\/p>\n\n\n\n<p>\u6bcf\u6b21\u53d6\u5f97\u8cc7\u6599\u4e4b\u5f8c\uff0c\u5c31\u628a\u6240\u6709\u76ee\u524d\u53d6\u5f97\u7684\u6578\u503c\u8cc7\u6599\u5f9e\u7b2c0\u500b\u958b\u59cb\u7e6a\u88fd\uff0c\u7528line\u628a\u6bcf\u4e00\u500b\u9ede\u9023\u63a5\u8d77\u4f86\uff0c\u5c31\u53ef\u4ee5\u5f97\u5230\u52d5\u614b\u7684\u6298\u7dda\u5716\u4e86\uff0c\u5982\u4e0b\u5716\u6240\u793a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"513\" height=\"421\" src=\"http:\/\/104es.nkust.org\/wp-content\/uploads\/2023\/01\/image.png?w=513\" alt=\"\" class=\"wp-image-1977\" srcset=\"https:\/\/104.es\/wp-content\/uploads\/2023\/01\/image.png 513w, https:\/\/104.es\/wp-content\/uploads\/2023\/01\/image-300x246.png 300w\" sizes=\"auto, (max-width: 513px) 100vw, 513px\" \/><\/figure>\n\n\n\n<p>\u7a0b\u5f0f\u78bc\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from machine import ADC, Pin, I2C\nimport time\nimport ssd1306\n\ni2c = I2C(0, sda=Pin(16), scl=Pin(17))\ndisp = ssd1306.SSD1306_I2C(128, 64, i2c)\ntemp_sensor = ADC(1)\nlight_sensor = ADC(0)\n\ndata = list()\nwhile True:\n    val = temp_sensor.read_u16()\n    light = light_sensor.read_u16()\n    temp = round((val\/65536) * 3.3 * 100, 2)\n    light = 100-round(light\/65536*100,2)\n    if len(data)&lt;=128:\n        data.append(light\/2.5)\n    else:\n        del data&#091;0]\n        data.append(light\/2.5)\n    disp.fill(0)\n    disp.text('NKUST CCET', 0, 0)\n    disp.text('Min-Huang Ho', 0, 8)\n    disp.text(\"{}C, {}%\".format(temp, light), 0, 16)\n    x, y, py = 0, 70, 70-int(data&#091;0])\n    for i, t in enumerate(data):\n        y = 70-int(t)\n        disp.line(x, py, x, y, 1)\n        x += 1\n        py = y\n    disp.show()\n\n<\/code><\/pre>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u52d5\u614b\u7684\u57f7\u884c\u6548\u679c\u5c55\u793a\uff1a<\/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=\"Raspberry Pi Pico + SSD1306 + \u5149\u654f\u96fb\u963b \u6298\u7dda\u5716\u793a\u7bc4\u5f71\u7247\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/Z_iM9Tlb9RA?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><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u524d\u9762\u7684\u6587\u7ae0\u4e2d\u6211\u5011\u5b78\u6703\u4e86\u5982\u4f55\u5728Pico\/Pico W\u4e2d\u5229\u7528SSD1306\u9019\u500b\u5fae\u578b\u986f\u793a\u5668\u4f86\u8f38\u51fa\u6587\u5b57\uff0c\u4e5f\u5229\u7528pixel\u51fd\u5f0f\u7e6a\u88fd\u4e86\u4e00\u500bSIN\u51fd\u6578\u5716\u5f62\uff0c\u90a3\u9ebc\uff0c\u6211\u5011\u5728\u8cc7\u6599\u6536\u96c6\u7684\u904e\u7a0b\u4e2d\uff0c\u5982\u679c\u60f3\u8981\u628a\u9019\u4e9b\u8cc7\u6599\u7684\u5167\u5bb9\u4ee5\u6298\u7dda\u5716\u7684\u65b9\u5f0f\u5448\u73fe\u51fa\u4f86\uff0c\u8a72\u5982\u4f55\u7de8\u5beb\u7a0b\u5f0f\u5462\uff1f\u6211\u5011\u9019\u7bc7\u6587\u7ae0\u5c31\u4f86\u6559\u540c\u5b78\u5011\u5982\u4f55\u5728SSD1306\u7e6a\u88fd\u8cc7\u6599\u6298\u7dda\u5716\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[16],"tags":[56],"class_list":["post-1972","post","type-post","status-publish","format-standard","hentry","category-rasbperry-pi-pico","tag-ssd1306"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/1972","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/comments?post=1972"}],"version-history":[{"count":0,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/1972\/revisions"}],"wp:attachment":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media?parent=1972"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/categories?post=1972"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/tags?post=1972"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}