{"id":1903,"date":"2022-12-27T17:07:04","date_gmt":"2022-12-27T09:07:04","guid":{"rendered":"https:\/\/104.es\/?p=1903"},"modified":"2023-11-22T09:37:21","modified_gmt":"2023-11-22T01:37:21","slug":"raspberry-pi-pico-w-ssd1306","status":"publish","type":"post","link":"https:\/\/104.es\/index.php\/2022\/12\/27\/raspberry-pi-pico-w-ssd1306\/","title":{"rendered":"Raspberry Pi Pico W + SSD1306\u986f\u793a\u5668"},"content":{"rendered":"\n<p>\u4e0d\u540c\u65bc\u6a19\u6e96\u7684Raspberry Pi\u7684\u5168\u529f\u80fd\u7528\u9014\uff0cPico\u53caPico W\u662f\u6c92\u6709\u4f5c\u696d\u7cfb\u7d71\u7684\uff0c\u7576\u7136\u4e5f\u5c31\u6c92\u6709\u81ea\u5df1\u7684\u986f\u793a\u5668\u8f38\u51fa\uff0c\u56e0\u6b64\u5982\u679c\u9700\u8981\u4e0d\u900f\u904e\u96fb\u8166\u986f\u793a\u4e00\u4e9b\u5167\u5bb9\u7684\u8a71\uff0c\u7576\u7136\u6700\u597d\u7684\u65b9\u5f0f\u5c31\u662f\u81ea\u5df1\u63a5\u4e0a\u4e00\u4e9b\u7269\u806f\u7db2\u958b\u767c\u677f\u6240\u4f7f\u7528\u7684\u5fae\u578b\u986f\u793a\u5668\uff0c\u5176\u4e2dSSD1306\u662f\u6700\u53d7\u6b61\u8fce\u7684\u5fae\u578b\u986f\u793a\u5668\uff0c\u5b83\u4f7f\u7528\u7684\u662fI2C\u7684\u4ecb\u9762\uff0c\u6b63\u597d\u4e5f\u53ef\u4ee5\u5728Pico\u4e0a\u4f7f\u7528\u3002\u9019\u7bc7\u6587\u7ae0\u5c31\u4f86\u8aaa\u660e\u5982\u4f55\u9023\u63a5\u53ca\u4f7f\u7528SSD1306\u3002<\/p>\n\n\n\n<p>SSD1306\u7684\u5916\u89c0\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"490\" height=\"465\" src=\"http:\/\/104es.nkust.org\/wp-content\/uploads\/2022\/12\/image-18.png?w=490\" alt=\"\" class=\"wp-image-1907\" srcset=\"https:\/\/104.es\/wp-content\/uploads\/2022\/12\/image-18.png 490w, https:\/\/104.es\/wp-content\/uploads\/2022\/12\/image-18-300x285.png 300w\" sizes=\"auto, (max-width: 490px) 100vw, 490px\" \/><\/figure>\n\n\n\n<p>\u5b83\u67094\u689d\u9023\u63a5\u7dda\uff0c\u5176\u4e2dVCC\u63a5\u6b63\u96fb\u6e90\uff0cGND\u63a5\u5730\u3002\u4f46\u662f\u8981\u7559\u610f\u7684\u662f\uff0c\u4e0d\u540c\u7684SSD1306\u6709\u4e9b\u5b83\u5011\u7684\u6b63\u8ca0\u96fb\u4f4d\u7f6e\u6703\u525b\u597d\u76f8\u53cd\uff0c\u4f7f\u7528\u4e4b\u524d\u4e00\u5b9a\u8981\u7279\u5225\u6ce8\u610f\u6b63\u8ca0\u96fb\u6e90\u4e0d\u8981\u63a5\u932f\u4e86\u3002Pico\u6709\u5169\u7d44 I2C\uff0c\u7406\u8ad6\u4e0a\u53ef\u4ee5\u4efb\u9078\u5176\u4e2d\u4e00\u7d44\uff0c\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u6211\u5011\u628a\u5b83\u9023\u63a5\u5230I2C0\uff0c\u4e5f\u5c31\u662fSCL\u63a5\u5230\u5be6\u9ad4\u63a5\u8173\u7684\u7b2c22\u8173\uff0cSDA\u63a5\u5230\u7b2c21\u8173\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=\"882\" height=\"752\" src=\"http:\/\/104es.nkust.org\/wp-content\/uploads\/2022\/12\/image-19.png?w=882\" alt=\"\" class=\"wp-image-1909\" srcset=\"https:\/\/104.es\/wp-content\/uploads\/2022\/12\/image-19.png 882w, https:\/\/104.es\/wp-content\/uploads\/2022\/12\/image-19-300x256.png 300w, https:\/\/104.es\/wp-content\/uploads\/2022\/12\/image-19-768x655.png 768w\" sizes=\"auto, (max-width: 882px) 100vw, 882px\" \/><\/figure>\n\n\n\n<p>\u5982\u540c\u4f7f\u7528DHT11\u4e00\u6a23\uff0c\u6700\u91cd\u8981\u7684\u4ecd\u7136\u662f\u8981\u627e\u5230\u5408\u9069\u7684\u51fd\u5f0f\u5eab\u3002Pico W\u9069\u7528\u7684SSD1306\u7a0b\u5f0f\u5eab\u5728\u4e0b\u9762\u9019\u500b\u7db2\u7ad9\u4e0a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-peppe-8-o wp-block-embed-peppe-8-o\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"mGkQmrEMOC\"><a href=\"https:\/\/peppe8o.com\/ssd1306-i2c-oled-raspberry-pi-pico-micropython\/\">Add an OLED display to Raspberry PI Pico with MicroPython<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Add an OLED display to Raspberry PI Pico with MicroPython&#8221; &#8212; peppe8o\" src=\"https:\/\/peppe8o.com\/ssd1306-i2c-oled-raspberry-pi-pico-micropython\/embed\/#?secret=bZql43WxNP#?secret=mGkQmrEMOC\" data-secret=\"mGkQmrEMOC\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\u5728\u4e0a\u9762\u9019\u500b\u7db2\u7ad9\u4e2d\u6709\u4e00\u500b\u4e0b\u8f09ssd1306.py\u7684\u8f09\u9ede\uff0c\u8acb\u76f4\u63a5\u4e0b\u8f09\u4e26\u5728Thonny\u4e2d\u958b\u555f\uff0c\u518d\u628a\u5b83\u5132\u5b58\u5230Pico\u7684\u677f\u5b50\u4e0a\u5373\u53ef\uff0c\u5132\u5b58\u5b8c\u7562\u4e4b\u5f8c\uff0c\u52a0\u4e0a\u524d\u4e00\u7bc7\u6587\u7ae0\u7684DHT11\u7a0b\u5f0f\u6a94\u6848\uff0c\u76ee\u524dPico\u7684\u5132\u5b58\u5167\u5bb9\u4e2d\u770b\u8d77\u4f86\u50cf\u662f\u4e0b\u9762\u9019\u500b\u6a23\u5b50\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"803\" height=\"411\" src=\"http:\/\/104es.nkust.org\/wp-content\/uploads\/2022\/12\/image-20.png?w=803\" alt=\"\" class=\"wp-image-1911\" srcset=\"https:\/\/104.es\/wp-content\/uploads\/2022\/12\/image-20.png 803w, https:\/\/104.es\/wp-content\/uploads\/2022\/12\/image-20-300x154.png 300w, https:\/\/104.es\/wp-content\/uploads\/2022\/12\/image-20-768x393.png 768w\" sizes=\"auto, (max-width: 803px) 100vw, 803px\" \/><\/figure>\n\n\n\n<p>\u4ee5\u4e0b\u7684\u7a0b\u5f0f\u5373\u53ef\u8b93\u4f60\u8f38\u51fa\u5982\u63a5\u7dda\u5716\u4e2d\u986f\u793a\u7684\u6587\u5b57\u5167\u5bb9\u4ee5\u53ca\u6b63\u5f26\u51fd\u6578\u5716\u5f62\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">from machine import Pin, I2C\nimport ssd1306\nimport math\ni2c = I2C(0, sda=Pin(16), scl=Pin(17))\ndisp = ssd1306.SSD1306_I2C(128, 64, i2c)\ndisp.text('NKUST CCET', 0, 0)\ndisp.text('Min-Huang Ho', 0, 10)\nfor th in range(360):\n    x = int(th * 0.25)\n    y = 44 - int(math.sin(th * (math.pi \/ 180))*20)\n    disp.pixel(x, y, 1)\ndisp.show()\n<\/code><\/pre>\n\n\n\n<p>\u5f9e\u4e0a\u8ff0\u7684\u7a0b\u5f0f\u53ef\u4ee5\u770b\u5f97\u51fa\u4f86\uff0c\u8a72\u986f\u793a\u5668\u7684\u89e3\u6790\u5ea6\u662f128&#215;64\uff0c\u5de6\u4e0a\u89d2\u5ea7\u6a19\u662f(0, 0)\uff0c\u53f3\u4e0b\u89d2\u5ea7\u6a19\u662f(127, 63)\u3002\u6211\u5011\u53ef\u4ee5\u4f7f\u7528text(str, x, y)\u51fd\u5f0f\u5728\u5ea7\u6a19(x, y)\u8655\u986f\u793a\u6587\u5b57\uff0c\u4f7f\u7528pixel(x, y, value)\u5728\u87a2\u5e55\u4e0a\u756b1\u500b\u9ede\u3002\u900f\u904e\u4e09\u89d2\u51fd\u6578\u7684\u8a08\u7b97\uff0c\u5c31\u53ef\u4ee5\u5728\u986f\u793a\u5668\u4e0a\u756b\u4e0a\u51fd\u6578\u5716\u5f62\u3002<\/p>\n\n\n\n<p>\u7d50\u5408\u524d\u4e00\u7bc7\u6587\u7ae0\u7684\u6eab\u6fd5\u5ea6\u91cf\u6e2c\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u7684\u7a0b\u5f0f\u78bc\uff0c\u8b93\u76ee\u524d\u7684\u6eab\u6fd5\u5ea6\u900f\u904eSSD1306\u5448\u73fe\u51fa\u4f86\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">from machine import Pin, I2C\nimport time, math\nfrom dht import DHT11\nimport ssd1306\npin = Pin(22, Pin.OUT, Pin.PULL_UP)\nsensor = DHT11(pin)\ni2c = I2C(0, sda=Pin(16), scl=Pin(17))\ndisp = ssd1306.SSD1306_I2C(128, 64, i2c)\nwhile True:\n    try:   \n        sensor.measure()\n        t  = (sensor.temperature)\n        h = (sensor.humidity)\n        disp.fill(0)\n        disp.text('NKUST CCET', 0, 0)\n        disp.text('Min-Huang Ho', 0, 10)\n        disp.text(\"{}, {}%\".format(t, h), 0, 40)\n    except:\n        pass\n    disp.show()\n<\/code><\/pre>\n\n\n\n<p>\u4e0a\u8ff0\u7a0b\u5f0f\u7684\u57f7\u884c\u7d50\u679c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"430\" height=\"406\" src=\"http:\/\/104es.nkust.org\/wp-content\/uploads\/2022\/12\/image-21.png?w=430\" alt=\"\" class=\"wp-image-1915\" srcset=\"https:\/\/104.es\/wp-content\/uploads\/2022\/12\/image-21.png 430w, https:\/\/104.es\/wp-content\/uploads\/2022\/12\/image-21-300x283.png 300w\" sizes=\"auto, (max-width: 430px) 100vw, 430px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0d\u540c\u65bc\u6a19\u6e96\u7684Raspberry Pi\u7684\u5168\u529f\u80fd\u7528\u9014\uff0cPico\u53caPico W\u662f\u6c92\u6709\u4f5c\u696d\u7cfb\u7d71\u7684\uff0c\u7576\u7136\u4e5f\u5c31\u6c92\u6709\u81ea\u5df1\u7684\u986f\u793a\u5668\u8f38\u51fa\uff0c\u56e0\u6b64\u5982\u679c\u9700\u8981\u4e0d\u900f\u904e\u96fb\u8166\u986f\u793a\u4e00\u4e9b\u5167\u5bb9\u7684\u8a71\uff0c\u7576\u7136\u6700\u597d\u7684\u65b9\u5f0f\u5c31\u662f\u81ea\u5df1\u63a5\u4e0a\u4e00\u4e9b\u7269\u806f\u7db2\u958b\u767c\u677f\u6240\u4f7f\u7528\u7684\u5fae\u578b\u986f\u793a\u5668\uff0c\u5176\u4e2dSSD1306\u662f\u6700\u53d7\u6b61\u8fce\u7684\u5fae\u578b\u986f\u793a\u5668\uff0c\u5b83\u4f7f\u7528\u7684\u662fI2C\u7684\u4ecb\u9762\uff0c\u6b63\u597d\u4e5f\u53ef\u4ee5\u5728Pico\u4e0a\u4f7f\u7528\u3002\u9019\u7bc7\u6587\u7ae0\u5c31\u4f86\u8aaa\u660e\u5982\u4f55\u9023\u63a5\u53ca\u4f7f\u7528SSD1306\u3002<\/p>\n","protected":false},"author":1,"featured_media":1862,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[16],"tags":[],"class_list":["post-1903","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-rasbperry-pi-pico"],"jetpack_featured_media_url":"https:\/\/104.es\/wp-content\/uploads\/2022\/12\/image-3.png","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/1903","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=1903"}],"version-history":[{"count":1,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/1903\/revisions"}],"predecessor-version":[{"id":2979,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/1903\/revisions\/2979"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media\/1862"}],"wp:attachment":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media?parent=1903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/categories?post=1903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/tags?post=1903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}