{"id":970,"date":"2021-08-25T12:09:18","date_gmt":"2021-08-25T04:09:18","guid":{"rendered":"https:\/\/104.es\/?p=970"},"modified":"2021-08-25T12:09:18","modified_gmt":"2021-08-25T04:09:18","slug":"raspi-ssd1306-python","status":"publish","type":"post","link":"https:\/\/104.es\/index.php\/2021\/08\/25\/raspi-ssd1306-python\/","title":{"rendered":"\u5728\u6a39\u8393\u6d3e\u4e0a\u4f7f\u7528SSD1306"},"content":{"rendered":"\n<p>\u96d6\u7136\u6a39\u8393\u6d3e\u672c\u8eab\u53ef\u4ee5\u900f\u904eHDMI\u9023\u63a5\u5230\u5927\u5c3a\u5bf8\u7684\u87a2\u5e55\u4e0a\uff0c\u4f46\u662f\u5728\u628a\u5b83\u7576\u4f5c\u662f\u7269\u806f\u7db2\u88dd\u7f6e\u6642\uff0c\u8b93\u5b83\u53ef\u4ee5\u5728\u4e00\u4e9b\u5c0f\u5c3a\u5bf8\u7684\u87a2\u5e55\u4e0a\u986f\u793a\u4e00\u4e9b\u5fc5\u8981\u7684\u8cc7\u8a0a\u4e5f\u662f\u5f88\u5e38\u898b\u7684\u61c9\u7528\u3002\u9664\u4e86\u5728\u4e0a\u4e00\u7bc7\u6587\u7ae0\u4e2d\u4ecb\u7d39\u7684\uff0c\u5982\u4f55\u5728LCD\u4e0a\u986f\u793a\u8cc7\u6599\u4e4b\u5916\uff0c\u672c\u7bc7\u6703\u6574\u7406\u4e00\u4e0b\u57280.96\u540b\u7684OLED SSD1306\u4e0a\u986f\u793a\u8cc7\u8a0a\u6240\u9700\u8981\u7684\u7a0b\u5f0f\u78bc\u3002<\/p>\n\n\n\n<p>\u5148\u4f86\u770b\u770b\u672c\u7bc7\u6587\u7ae0\u7684\u4e3b\u89d2\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-\u5d4c\u5165\u5167\u5bb9 wp-block-embed-\u5d4c\u5165\u5167\u5bb9\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"0Dt9nCszT0\"><a href=\"https:\/\/www.taiwaniot.com.tw\/product\/0-96%e5%90%8boled-%e6%b6%b2%e6%99%b6%e5%b1%8f%e9%a1%af%e7%a4%ba%e6%a8%a1%e7%b5%84-%e9%bb%83%e8%97%8d%e9%9b%99%e8%89%b2-i2c-oled%e6%a8%a1%e5%a1%8a%ef%bc%81%e5%8f%aa%e9%9c%804%e5%80%8b%e5%bc%95%e8%85%b3\/\">0.96\u540bOLED \u6db2\u6676\u5c4f\u986f\u793a\u6a21\u7d44 \u9ec3\u85cd\u96d9\u8272 I2C OLED\u6a21\u7d44\uff01\u53ea\u97004\u500b\u5f15\u8173<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"0.96\u540bOLED \u6db2\u6676\u5c4f\u986f\u793a\u6a21\u7d44 \u9ec3\u85cd\u96d9\u8272 I2C OLED\u6a21\u7d44\uff01\u53ea\u97004\u500b\u5f15\u8173 &#8212; \u53f0\u7063\u7269\u806f\u79d1\u6280 TaiwanIOT Studio\" src=\"https:\/\/www.taiwaniot.com.tw\/product\/0-96%e5%90%8boled-%e6%b6%b2%e6%99%b6%e5%b1%8f%e9%a1%af%e7%a4%ba%e6%a8%a1%e7%b5%84-%e9%bb%83%e8%97%8d%e9%9b%99%e8%89%b2-i2c-oled%e6%a8%a1%e5%a1%8a%ef%bc%81%e5%8f%aa%e9%9c%804%e5%80%8b%e5%bc%95%e8%85%b3\/embed\/#?secret=0Dt9nCszT0\" data-secret=\"0Dt9nCszT0\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\u81f3\u65bc\u9023\u7dda\u7684\u90e8\u4efd\uff0c\u56e0\u70ba\u5b83\u4f7f\u7528\u4e86I2C\u4ecb\u9762\uff0c\u6240\u4ee5\u9664\u4e86\u628a\u6a39\u8393\u6d3e\u4e0a\u76845V\u548cGND\u63a5\u5230ssd1306\u4e0a\u7684VCC\u548cGND\u4e4b\u5916\uff0c\u53e6\u5916\u5169\u689d\u7ddaSDA\u548cSCL\uff0c\u6a39\u8393\u6d3e\u628a\u5b83\u5011\u5206\u5225\u653e\u5728\u5be6\u9ad4\u7de8\u865f3\u548c\u5be6\u9ad4\u7de8\u865f5\u7684\u90a3\u5169\u652f\u63a5\u8173\u4e0a\uff0c\u5728\u9023\u63a5\u4e0a\u61c9\u8a72\u6c92\u6709\u592a\u5927\u7684\u96e3\u5ea6\u3002<\/p>\n\n\n\n<p>\u9023\u63a5\u5b8c\u7562\u4e4b\u5f8c\uff0c\u53ef\u4ee5\u57f7\u884c\u4ee5\u4e0b\u7684\u6307\u4ee4\uff0c\u6aa2\u67e5\u662f\u5426\u53ef\u4ee5\u9806\u5229\u627e\u5230\u5df2\u9023\u63a5\u7684I2C\u88dd\u7f6e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>i2cdetect -y 1<\/code><\/pre>\n\n\n\n<p>\u57f7\u884c\u7d50\u679c\u61c9\u8a72\u770b\u8d77\u4f86\u6703\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=\"723\" height=\"261\" src=\"http:\/\/104es.nkust.org\/wp-content\/uploads\/2021\/08\/image.png?w=723\" alt=\"\" class=\"wp-image-976\" srcset=\"https:\/\/104.es\/wp-content\/uploads\/2021\/08\/image.png 723w, https:\/\/104.es\/wp-content\/uploads\/2021\/08\/image-300x108.png 300w\" sizes=\"auto, (max-width: 723px) 100vw, 723px\" \/><\/figure>\n\n\n\n<p>\u770b\u5230\u90a3\u500b3c\u5c31\u8868\u793a\u9023\u63a5\u6b63\u5e38\u3002\u63a5\u8457\uff0c\u6700\u91cd\u8981\u7684\u662f\u8981\u88dd\u5c0d\u6a21\u7d44\uff0c\u5148\u4f86\u770b\u5b89\u88dd\u6240\u9700\u8981\u7684\u662f\u54ea\u4e00\u500b\u6a21\u7d44\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install adafruit-circuitpython-ssd1306\n<\/code><\/pre>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u7c21\u55ae\u7684\u6e2c\u8a66\u7a0b\u5f0f\u78bc\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from board import SCL, SDA\nimport busio\n\nimport adafruit_ssd1306\n\ni2c = busio.I2C(SCL, SDA)\n\ndisplay = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)\ndisplay.fill(1)\ndisplay.show()<\/code><\/pre>\n\n\n\n<p>\u4e0a\u8ff0\u7a0b\u5f0f\u5728\u57f7\u884c\u4e4b\u5f8c\uff0c\u5982\u679c\u4f60\u7684SSD1306\u7684\u9023\u63a5\u7dda\u662f\u6b63\u5e38\u7684\u8a71\uff0c\u5c31\u6703\u5728\u756b\u9762\u4e0a\u770b\u5230\u6240\u6709\u7684\u50cf\u7d20\u90fd\u88ab\u9ede\u4eae\u7684\u60c5\u6cc1\u3002<\/p>\n\n\n\n<p>\u90a3\u9ebc\u61c9\u8a72\u5982\u4f55\u986f\u793a\u51fa\u6587\u5b57\u5462\uff1f\u53ea\u8981\u5229\u7528PIL\u6a21\u7d44\u88e1\u9762\u7684\u529f\u80fd\uff0c\u7136\u5f8c\u518d\u7528\u5716\u50cf\u7684\u65b9\u5f0f\u628a\u6e96\u5099\u597d\u7684\u6587\u5b57\u8cbc\u4e0a\u53bb\u5c31\u53ef\u4ee5\u4e86\u3002\u9996\u5148\u9700\u8981\u5b89\u88ddpillow\u6a21\u7d44\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install pillow<\/code><\/pre>\n\n\n\n<p> \u4ee5\u4e0b\u662f\u6e2c\u8a66\u7528\u7684\u7a0b\u5f0f\u78bc\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from board import SCL, SDA\nimport busio\nimport adafruit_ssd1306\nfrom PIL import Image, ImageDraw, ImageFont\n\ni2c = busio.I2C(SCL, SDA)\ndisplay = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)\ndisplay.fill(1)\ndisplay.show()\n\nwidth, height = 128, 32\nimage = Image.new(\"1\", (width, height))\ndraw = ImageDraw.Draw(image)\nfont = ImageFont.load_default()\n\ndraw.text((0,0), \"Hello\", font=font, fill=1)\ndraw.text((0, 10), \"12345678\", font=font, fill=1)\ndisplay.image(image)\ndisplay.show()<\/code><\/pre>\n\n\n\n<p>\u4ee5\u4e0b\u7684\u7a0b\u5f0f\u78bc\u662f\u52a0\u4e0a\u6eab\u6fd5\u5ea6\u611f\u6e2c\u5668\u7684\u986f\u793a\u529f\u80fd\uff0c\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\u6211\u5011\u4f7f\u7528\u7684\u662fDHT11\uff0c\u4e26\u628a\u5176out\u7684\u63a5\u8173\u9023\u63a5\u5230\u5be6\u9ad4\u63a5\u8173\u7b2c7\u8173\uff08GPIO4\uff09\u7684\u4f4d\u7f6e\u4e0a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import Adafruit_DHT\nfrom board import SCL, SDA\nimport busio\nimport adafruit_ssd1306\nfrom PIL import Image, ImageDraw, ImageFont\n\ni2c = busio.I2C(SCL, SDA)\ndisplay = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)\nwidth, height = 128, 32\nimage = Image.new(\"1\", (width, height))\ndraw = ImageDraw.Draw(image)\nfont = ImageFont.load_default()\ntry:\n    while True:\n        h, t = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11, 4)\n        draw.rectangle((0, 0, width, height), outline=0, fill=0)\n        draw.text((0,0), \"NKUST CCET\", font=font, fill=1)\n        draw.text((0, 8), \"Temperature:{}\".format(t), font=font, fill=1)\n        draw.text((0, 16), \"Humidity:{}\".format(h), font=font, fill=1)\n        display.image(image)\n        display.show()\nexcept KeyboardInterrupt:\n    print(\"See you\")<\/code><\/pre>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u57f7\u884c\u4e0a\u8ff0\u7a0b\u5f0f\u7684\u7d50\u679c\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"325\" height=\"227\" src=\"http:\/\/104es.nkust.org\/wp-content\/uploads\/2021\/08\/image-1.png?w=325\" alt=\"\" class=\"wp-image-982\" srcset=\"https:\/\/104.es\/wp-content\/uploads\/2021\/08\/image-1.png 325w, https:\/\/104.es\/wp-content\/uploads\/2021\/08\/image-1-300x210.png 300w\" sizes=\"auto, (max-width: 325px) 100vw, 325px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7136\u6a39\u8393\u6d3e\u672c\u8eab\u53ef\u4ee5\u900f\u904eHDMI\u9023\u63a5\u5230\u5927\u5c3a\u5bf8\u7684\u87a2\u5e55\u4e0a\uff0c\u4f46\u662f\u5728\u628a\u5b83\u7576\u4f5c\u662f\u7269\u806f\u7db2\u88dd\u7f6e\u6642\uff0c\u8b93\u5b83\u53ef\u4ee5\u5728\u4e00\u4e9b\u5c0f\u5c3a\u5bf8\u7684\u87a2\u5e55\u4e0a\u986f\u793a\u4e00\u4e9b\u5fc5\u8981\u7684\u8cc7\u8a0a\u4e5f\u662f\u5f88\u5e38\u898b\u7684\u61c9\u7528\u3002\u9664\u4e86\u5728\u4e0a\u4e00\u7bc7\u6587\u7ae0\u4e2d\u4ecb\u7d39\u7684\uff0c\u5982\u4f55\u5728LCD\u4e0a\u986f\u793a\u8cc7\u6599\u4e4b\u5916\uff0c\u672c\u7bc7\u6703\u6574\u7406\u4e00\u4e0b\u57280.96\u540b\u7684OLED SSD1306\u4e0a\u986f\u793a\u8cc7\u8a0a\u6240\u9700\u8981\u7684\u7a0b\u5f0f\u78bc\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":[17],"tags":[],"class_list":["post-970","post","type-post","status-publish","format-standard","hentry","category-raspberry-pi"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/970","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=970"}],"version-history":[{"count":0,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/970\/revisions"}],"wp:attachment":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media?parent=970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/categories?post=970"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/tags?post=970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}