{"id":837,"date":"2020-09-08T23:11:43","date_gmt":"2020-09-08T15:11:43","guid":{"rendered":"https:\/\/www.iotch.xyz\/?p=837"},"modified":"2020-09-08T23:11:43","modified_gmt":"2020-09-08T15:11:43","slug":"%e6%a0%91%e8%8e%93%e6%b4%be%e9%a9%b1%e5%8a%a8oled%e5%b1%8f%e5%b9%95%e4%bb%a5%e5%8f%8a%e8%8a%b1%e5%b1%8f%e9%97%ae%e9%a2%98%e7%9a%84%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"https:\/\/www.iotch.xyz\/?p=837","title":{"rendered":"\u6811\u8393\u6d3e\u9a71\u52a8OLED\u5c4f\u5e55\u4ee5\u53ca\u82b1\u5c4f\u95ee\u9898\u7684\u5904\u7406"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/shumeipai.nxez.com\/wp-content\/uploads\/2017\/09\/20170913105547844-0.jpg\" alt=\"\" class=\"wp-image-3451\"\/><\/figure><\/div>\n\n\n\n<p><em>\u6765\u81ea\u597d\u5947\u5416\u658c\u7684\u6295\u7a3f\uff0c\u611f\u8c22~<\/em><br>\u6700\u8fd1\u5728\u5b66\u4e60\u6811\u8393\u6d3e\uff0c\u9a71\u52a8OLED\u5c4f\u65f6\u51fa\u73b0\u4e86\u4e00\u4e2a\u95ee\u9898\uff0c\u5c31\u662f\u82b1\u5c4f\uff0c\u6298\u817e\u4e86\u4e24\u5929\u540e\u53d1\u73b0\u539f\u6765\u8fd9\u4e2aOLED\u7684\u9a71\u52a8\u82af\u7247\u4e0d\u662fSSD1306\u800c\u662fSH1106\uff0c\u6240\u4ee5\u7528Adafruit_Python_SSD1306\u8fd9\u4e2a\u5e93\u662f\u82b1\u5c4f\u7684\u3002<br>OLED\u7684\u9a71\u52a8\u82af\u7247\u6709\u597d\u51e0\u79cd\uff0c\u4f46\u662f\u6709\u7684\u5e93\u53ea\u652f\u6301SSD1306\u82af\u7247\uff0c\u6240\u4ee5\u5f53\u4f60\u7684OLED\u5c4f\u51fa\u73b0\u82b1\u5c4f\u65f6\u5c31\u5e94\u8be5\u662f\u82af\u7247\u548c\u5e93\u6ca1\u5bf9\u5e94\u4e0a\uff0c\u8d2d\u4e70OLED\u5c4f\u65f6\u6700\u597d\u8d2d\u4e70i2c\u7684SSD1306\u82af\u7247\u7684\uff0c\u5e93\u591a\u4e14\u63a5\u7ebf\u6bd4\u8f83\u7b80\u5355\u3002<br><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"Python\u6709\u4e24\u4e2a\u53ef\u4ee5\u7528\u7684OLED\u5e93\uff1a\">Python\u6709\u4e24\u4e2a\u53ef\u4ee5\u7528\u7684OLED\u5e93\uff1a<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/github.com\/adafruit\/Adafruit_Python_SSD1306\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >Adafruit_Python_SSD1306\u5e93<\/a>\u2014&gt;\u53ea\u652f\u6301SSD1306<\/li><li><a href=\"https:\/\/github.com\/rm-hull\/luma.oled\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >Luma.oled\u5e93<\/a>\u2014&gt;\u652f\u6301SSD1306 \/ SSD1322 \/ SSD1325 \/ SSD1331 \/ SH1106<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"Adafruit-Python-SSD1306\u5e93\u4e0eLuma-oled\u5e93\u7684\u5b89\u88c5\u8bf4\u660e-\u770b\u4e0d\u61c2\u82f1\u6587\u6ca1\u5173\u7cfb\uff0c\u770b\u4e0b\u9762\u6211\u4f1a\u8bf4\">Adafruit_Python_SSD1306\u5e93\u4e0eLuma.oled\u5e93\u7684\u5b89\u88c5\u8bf4\u660e(\u770b\u4e0d\u61c2\u82f1\u6587\u6ca1\u5173\u7cfb\uff0c\u770b\u4e0b\u9762\u6211\u4f1a\u8bf4)\u3002<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/learn.adafruit.com\/ssd1306-oled-displays-with-raspberry-pi-and-beaglebone-black\/wiring\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >SSD1306 OLED Displays with Raspberry Pi and BeagleBone Black<\/a><\/li><li><a href=\"https:\/\/luma-oled.readthedocs.io\/en\/latest\/install.html\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >Luma.OLED: Display drivers for SSD1306 \/ SSD1322 \/ SSD1325 \/ SSD1331 \/ SH1106<\/a><\/li><\/ul>\n\n\n\n<p>\u672c\u6587\u7684Luma.oled\u5e93\u53c2\u8003\u4e86<a href=\"http:\/\/blog.csdn.net\/ki1381\/article\/details\/52425565\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >I2C\u63a5\u53e3\u7684OLED\u5728\u6811\u8393\u6d3e3\u4e0a\u7684\u5e94\u7528 <\/a>\uff0c\u4f46\u8fd9\u662f\u65e7\u7248\u672c\u7684\uff0c\u65b0\u7248\u672c\u5e93\u4e0d\u662f\u8fd9\u6837\u5b89\u88c5\uff0c\u8bf7\u770b\u4e0b\u6587\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"i2c\u63a5\u7ebf\">i2c\u63a5\u7ebf<\/h4>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/shumeipai.nxez.com\/wp-content\/uploads\/2015\/03\/rpi-pins-40-0.png\" alt=\"\u6811\u8393\u6d3e\u5f15\u811a\u56fe\" title=\"\u6811\u8393\u6d3e\u5f15\u811a\u56fe\"\/><\/figure><\/div>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>OLED\u5f15\u811a<\/th><th>\u6811\u8393\u6d3e\u7269\u7406BOARD\u5f15\u811a<\/th><\/tr><\/thead><tbody><tr><td>VCC<\/td><td>1\u53f7<\/td><\/tr><tr><td>GND<\/td><td>6\u53f7<\/td><\/tr><tr><td>SCL<\/td><td>5\u53f7<\/td><\/tr><tr><td>SDA<\/td><td>3\u53f7<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u63a5\u597d\u7ebf\u540e\u5c31\u662f\u50cf\u4e00\u4e2aL\u578b\u7684\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/shumeipai.nxez.com\/wp-content\/uploads\/2017\/09\/20170913105547808-0.jpg\" alt=\"\" class=\"wp-image-3457\"\/><\/figure><\/div>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"\u5f00\u542fi2c\u529f\u80fd\">\u5f00\u542fi2c\u529f\u80fd<\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>123<\/td><td><code>sudo<\/code> <code>apt-get <\/code><code>install<\/code> <code>-y python-smbus<\/code><code>sudo<\/code> <code>apt-get <\/code><code>install<\/code> <code>-y i2c-tools<\/code><code>sudo<\/code> <code>raspi-config<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u6253\u5f00\u6811\u8393\u6d3e\u914d\u7f6e\u9009\u62e95 Interfacing Options\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/shumeipai.nxez.com\/wp-content\/uploads\/2017\/09\/20170913105547983-0.jpg\" alt=\"\" class=\"wp-image-3452\"\/><\/figure><\/div>\n\n\n\n<p>\u9009\u62e9P5 I2C\u56de\u8f66\u6fc0\u6d3bI2C\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/shumeipai.nxez.com\/wp-content\/uploads\/2017\/09\/20170913105547768-0.jpg\" alt=\"\" class=\"wp-image-3456\"\/><\/figure><\/div>\n\n\n\n<p>\u6309\u56de\u8f66\u542f\u52a8\u5c31\u5f97\u4e86\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/shumeipai.nxez.com\/wp-content\/uploads\/2017\/09\/20170913105547221-0.jpg\" alt=\"\" class=\"wp-image-3454\"\/><\/figure><\/div>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"\u67e5\u770bi2c\u5730\u5740\">\u67e5\u770bi2c\u5730\u5740<\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>1<\/td><td><code>sudo<\/code> <code>i2cdetect -y 1<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u7136\u540e\u4f60\u80fd\u770b\u5230\u4e0b\u9762\u7684\u5730\u5740\uff0c3c\u5c31\u662foled\u5c4f\u7684i2c\u5730\u5740\u4e86\uff0c\u8bf4\u660e\u5df2\u7ecf\u6210\u529f\u5f00\u542fi2c\u5566<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/shumeipai.nxez.com\/wp-content\/uploads\/2017\/09\/20170913105551735-0.jpg\" alt=\"\" class=\"wp-image-3450\"\/><\/figure><\/div>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"\u5b89\u88c5Adafruit-Python-SSD1306\u5e93\">\u2013 \u5b89\u88c5Adafruit_Python_SSD1306\u5e93<\/h4>\n\n\n\n<p>\u7ec8\u7aef\u8f93\u5165\u4e0b\u9762\u547d\u4ee4\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>12345678<\/td><td><code>sudo<\/code> <code>apt-get update<\/code><code>sudo<\/code> <code>apt-get <\/code><code>install<\/code> <code>build-essential python-dev python-pip<\/code><code>sudo<\/code> <code>pip <\/code><code>install<\/code> <code>RPi.GPIO<\/code><code>sudo<\/code> <code>apt-get <\/code><code>install<\/code> <code>python-imaging python-smbus<\/code><code>sudo<\/code> <code>apt-get <\/code><code>install<\/code> <code>git<\/code><code>git clone https:<\/code><code>\/\/github<\/code><code>.com<\/code><code>\/adafruit\/Adafruit_Python_SSD1306<\/code><code>.git<\/code><code>cd<\/code> <code>Adafruit_Python_SSD1306<\/code><code>sudo<\/code> <code>python setup.py <\/code><code>install<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5b89\u88c5\u597dAdafruit_Python_SSD1306\u5e93\u540e\uff0ccd examples\u8fdb\u5165\u4f8b\u7a0b\u76ee\u5f55\uff0cls\u67e5\u770b\u6587\u4ef6\uff0c\u4ee5shapes.py\u4f8b\u7a0b\u8bf4\u660e\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899<\/td><td><code>import<\/code> <code>time<\/code>&nbsp;<code>import<\/code> <code>Adafruit_GPIO.SPI as SPI<\/code><code>import<\/code> <code>Adafruit_SSD1306<\/code>&nbsp;<code>import<\/code> <code>Image<\/code><code>import<\/code> <code>ImageDraw<\/code><code>import<\/code> <code>ImageFont<\/code>&nbsp;<code># Raspberry Pi pin configuration:<\/code><code>RST <\/code><code>=<\/code> <code>24<\/code><code># Note the following are only used with SPI:<\/code><code>DC <\/code><code>=<\/code> <code>23<\/code><code>SPI_PORT <\/code><code>=<\/code> <code>0<\/code><code>SPI_DEVICE <\/code><code>=<\/code> <code>0<\/code>&nbsp;<code># Beaglebone Black pin configuration:<\/code><code># RST = 'P9_12'<\/code><code># Note the following are only used with SPI:<\/code><code># DC = 'P9_15'<\/code><code># SPI_PORT = 1<\/code><code># SPI_DEVICE = 0<\/code>&nbsp;<code># 128x32 display with hardware I2C:<\/code><code>disp <\/code><code>=<\/code> <code>Adafruit_SSD1306.SSD1306_128_32(rst<\/code><code>=<\/code><code>RST)<\/code>&nbsp;<code># 128x64 display with hardware I2C:<\/code><code># disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)<\/code>&nbsp;<code># Alternatively you can specify an explicit I2C bus number, for example<\/code><code># with the 128x32 display you would use:<\/code><code># disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, i2c_bus=2)<\/code>&nbsp;<code># 128x32 display with hardware SPI:<\/code><code># disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))<\/code>&nbsp;<code># 128x64 display with hardware SPI:<\/code><code># disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))<\/code>&nbsp;<code># Alternatively you can specify a software SPI implementation by providing<\/code><code># digital GPIO pin numbers for all the required display pins.&nbsp; For example<\/code><code># on a Raspberry Pi with the 128x32 display you might use:<\/code><code># disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, dc=DC, sclk=18, din=25, cs=22)<\/code>&nbsp;<code># Initialize library.<\/code><code>disp.begin()<\/code>&nbsp;<code># Clear display.<\/code><code>disp.clear()<\/code><code>disp.display()<\/code>&nbsp;<code># Create blank image for drawing.<\/code><code># Make sure to create image with mode '1' for 1-bit color.<\/code><code>width <\/code><code>=<\/code> <code>disp.width<\/code><code>height <\/code><code>=<\/code> <code>disp.height<\/code><code>image <\/code><code>=<\/code> <code>Image.new(<\/code><code>'1'<\/code><code>, (width, height))<\/code>&nbsp;<code># Get drawing object to draw on image.<\/code><code>draw <\/code><code>=<\/code> <code>ImageDraw.Draw(image)<\/code>&nbsp;<code># Draw a black filled box to clear the image.<\/code><code>draw.rectangle((<\/code><code>0<\/code><code>,<\/code><code>0<\/code><code>,width,height), outline<\/code><code>=<\/code><code>0<\/code><code>, fill<\/code><code>=<\/code><code>0<\/code><code>)<\/code>&nbsp;<code># Draw some shapes.<\/code><code># First define some constants to allow easy resizing of shapes.<\/code><code>padding <\/code><code>=<\/code> <code>2<\/code><code>shape_width <\/code><code>=<\/code> <code>20<\/code><code>top <\/code><code>=<\/code> <code>padding<\/code><code>bottom <\/code><code>=<\/code> <code>height<\/code><code>-<\/code><code>padding<\/code><code># Move left to right keeping track of the current x position for drawing shapes.<\/code><code>x <\/code><code>=<\/code> <code>padding<\/code><code># Draw an ellipse.<\/code><code>draw.ellipse((x, top , x<\/code><code>+<\/code><code>shape_width, bottom), outline<\/code><code>=<\/code><code>255<\/code><code>, fill<\/code><code>=<\/code><code>0<\/code><code>)<\/code><code>x <\/code><code>+<\/code><code>=<\/code> <code>shape_width<\/code><code>+<\/code><code>padding<\/code><code># Draw a rectangle.<\/code><code>draw.rectangle((x, top, x<\/code><code>+<\/code><code>shape_width, bottom), outline<\/code><code>=<\/code><code>255<\/code><code>, fill<\/code><code>=<\/code><code>0<\/code><code>)<\/code><code>x <\/code><code>+<\/code><code>=<\/code> <code>shape_width<\/code><code>+<\/code><code>padding<\/code><code># Draw a triangle.<\/code><code>draw.polygon([(x, bottom), (x<\/code><code>+<\/code><code>shape_width<\/code><code>\/<\/code><code>2<\/code><code>, top), (x<\/code><code>+<\/code><code>shape_width, bottom)], outline<\/code><code>=<\/code><code>255<\/code><code>, fill<\/code><code>=<\/code><code>0<\/code><code>)<\/code><code>x <\/code><code>+<\/code><code>=<\/code> <code>shape_width<\/code><code>+<\/code><code>padding<\/code><code># Draw an X.<\/code><code>draw.line((x, bottom, x<\/code><code>+<\/code><code>shape_width, top), fill<\/code><code>=<\/code><code>255<\/code><code>)<\/code><code>draw.line((x, top, x<\/code><code>+<\/code><code>shape_width, bottom), fill<\/code><code>=<\/code><code>255<\/code><code>)<\/code><code>x <\/code><code>+<\/code><code>=<\/code> <code>shape_width<\/code><code>+<\/code><code>padding<\/code>&nbsp;<code># Load default font.<\/code><code>font <\/code><code>=<\/code> <code>ImageFont.load_default()<\/code>&nbsp;<code># Alternatively load a TTF font.<\/code><code># Some other nice fonts to try: http:\/\/www.dafont.com\/bitmap.php<\/code><code>#font = ImageFont.truetype('Minecraftia.ttf', 8)<\/code>&nbsp;<code># Write two lines of text.<\/code><code>draw.text((x, top),&nbsp;&nbsp;&nbsp; <\/code><code>'Hello'<\/code><code>,&nbsp; font<\/code><code>=<\/code><code>font, fill<\/code><code>=<\/code><code>255<\/code><code>)<\/code><code>draw.text((x, top<\/code><code>+<\/code><code>20<\/code><code>), <\/code><code>'World!'<\/code><code>, font<\/code><code>=<\/code><code>font, fill<\/code><code>=<\/code><code>255<\/code><code>)<\/code>&nbsp;<code># Display image.<\/code><code>disp.image(image)<\/code><code>disp.display()<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u6309\u7167\u4f60\u7684oled\u5c4f\u4fee\u6539\u4ee3\u7801\uff0c\u7a0b\u5e8f\u9ed8\u8ba4\u662f12832\u7684\uff0c\u4f60\u7684oled\u5c4f\u662f\u8fd9\u4e2a\u5c31\u4e0d\u7528\u6539\u76f4\u63a5\u8fd0\u884c\u5c31OK\u3002<br>\u5982\u679c\u662f12864\u7684I2C\u5c31\u50cf\u4e0b\u9762\u90a3\u6837\u4fee\u6539\uff0c\u628a12832\u52a0#\u6ce8\u91ca\uff0c12864#\u6ce8\u91ca\u53bb\u6389\u4fdd\u5b58\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>12345<\/td><td><code># 128x32 display with hardware I2C:<\/code><code>#disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)<\/code>&nbsp;<code># 128x64 display with hardware I2C:<\/code><code>disp <\/code><code>=<\/code> <code>Adafruit_SSD1306.SSD1306_128_64(rst<\/code><code>=<\/code><code>RST)<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u7ec8\u7aef\u8f93\u5165sudo python shapes.py\u6216\u7528Python\u6253\u5f00\u6587\u4ef6\u8fd0\u884c\u5c31\u80fd\u770b\u5230OLED\u5c4f\u6709\u663e\u793a\u4e86\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"\u5b89\u88c5Luma-oled\u5e93\">\u2013 \u5b89\u88c5Luma.oled\u5e93<\/h4>\n\n\n\n<p>\u7ec8\u7aef\u8f93\u5165\u4e0b\u9762\u547d\u4ee4\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>1234<\/td><td><code>sudo<\/code> <code>apt-get <\/code><code>install<\/code> <code>python-dev python-pip libfreetype6-dev libjpeg-dev<\/code><code>sudo<\/code> <code>-H pip <\/code><code>install<\/code> <code>--upgrade pip<\/code><code>sudo<\/code> <code>apt-get purge python-pip<\/code><code>sudo<\/code> <code>-H pip <\/code><code>install<\/code> <code>--upgrade luma.oled<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u6ce8\uff1a\u5982\u679c\u4f60\u9700\u8981\u5b89\u88c5Python3\u7684Luma.oled\u5e93\u7684\u5219\u6309\u4e0b\u9762\u5bf9\u5e94\u7684Python3\u7248\u672c\u4fee\u6539\u4e0a\u9762\u7684\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\u3002<br>pip \u21d2 pip3<br>python \u21d2 python3<br>python-dev \u21d2 python3-dev<br>python-pip \u21d2 python3-pip<\/p>\n\n\n\n<p>\u5982\u679c\u5b89\u88c5Luma.oled\u5e93\u65f6\u51fa\u73b0\u7ea2\u5b57\u9519\u8bef\uff0c\u8bf7\u7ee7\u7eed\u6267\u884c\u547d\u4ee4\u91cd\u8bd5\uff0c\u90a3\u662f\u56e0\u4e3a\u7f51\u7edc\u95ee\u9898\u4e0b\u8f7d\u4e00\u4e2a\u53ebPillow\u7684\u5e93\u4e0d\u6210\u529f\u3002<\/p>\n\n\n\n<p>\u5b89\u88c5\u597dLuma.oled\u5e93\u540e\u65b0\u5efa\u6587\u4ef6\u547d\u540d\u4e3aoled.py\uff0c\u590d\u5236\u7c98\u8d34\u4e0b\u9762\u4ee3\u7801\u3002<a href=\"https:\/\/luma-oled.readthedocs.io\/en\/latest\/python-usage.html\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >\u53c2\u8003\u8fd9\u91cc\u4f7f\u7528\u8bf4\u660e<\/a><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>1234567891011121314<\/td><td><code>from<\/code> <code>luma.core.interface.serial <\/code><code>import<\/code> <code>i2c, spi<\/code><code>from<\/code> <code>luma.core.render <\/code><code>import<\/code> <code>canvas<\/code><code>from<\/code> <code>luma.oled.device <\/code><code>import<\/code> <code>ssd1306, ssd1325, ssd1331, sh1106<\/code>&nbsp;<code># rev.1 users set port=0<\/code><code># substitute spi(device=0, port=0) below if using that interface<\/code><code>serial <\/code><code>=<\/code> <code>i2c(port<\/code><code>=<\/code><code>1<\/code><code>, address<\/code><code>=<\/code><code>0x3C<\/code><code>)<\/code>&nbsp;<code># substitute ssd1331(...) or sh1106(...) below if using that device<\/code><code>device <\/code><code>=<\/code> <code>sh1106(serial)<\/code><code>#\u8fd9\u91cc\u6539ssd1306, ssd1325, ssd1331, sh1106<\/code>&nbsp;<code>with canvas(device) as draw:<\/code><code>draw.rectangle(device.bounding_box, outline<\/code><code>=<\/code><code>\"white\"<\/code><code>, fill<\/code><code>=<\/code><code>\"black\"<\/code><code>)<\/code><code>draw.text((<\/code><code>30<\/code><code>, <\/code><code>40<\/code><code>), <\/code><code>\"Hello World\"<\/code><code>, fill<\/code><code>=<\/code><code>\"white\"<\/code><code>)<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5982\u679c\u4f60\u7684oled\u9a71\u52a8\u82af\u7247\u662f\u5176\u5b83\u578b\u53f7\u627e\u5230device = sh1106(serial)\uff0c\u628ash1106\u6539\u6210\u5e93\u652f\u6301\u7684\u5176\u5b83\u578b\u53f7\u3002<br>\u6811\u8393\u6d3e\u4e0a\u7528Python2\u6253\u5f00oled.py\u8fd0\u884c\u5c31\u80fd\u770b\u5230\u4e0b\u56fe\u7684Hello World\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/shumeipai.nxez.com\/wp-content\/uploads\/2017\/09\/20170913105551459-0.jpg\" alt=\"\" class=\"wp-image-3453\"\/><\/figure><\/div>\n\n\n\n<p>\u80fd\u9a71\u52a8\u6210\u529f\u540e\u6211\u4eec\u53bb\u4e0b\u8f7dLuma.oled\u7684<a href=\"https:\/\/github.com\/rm-hull\/luma.examples\" target=\"_blank\" rel=\"noreferrer noopener\" rel=\"nofollow\" >examples\u4ee3\u7801<\/a>\u3002<br>\u7136\u540e\u662fexamples\u91cc\u9762\u7684\u4f8b\u5b50\u600e\u4e48\u7528\u5462\uff1f\u5982\u679c\u662f\u975essd1306\u82af\u7247\u76f4\u63a5\u8fd0\u884c\u8fd8\u662f\u82b1\u5c4f\u7684\uff0c\u56e0\u4e3a\u90a3\u4e2aexamples\u7684\u4ee3\u7801\u9700\u8981\u4fee\u6539\u3002<br>\u4e0b\u9762\u4ee5pi_logo.py\u4e3a\u4f8b\u53c2\u8003\u4e0a\u9762\u90a3\u4e2aHello World\u7684\u4f8b\u5b50\u4fee\u6539\u6210\u81ea\u5df1OLED\u82af\u7247\u578b\u53f7\u7684(\u6587\u4ef6\u653e\u5728\u5728examples\u5185)\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>123456789101112131415161718192021222324252627282930313233343536373839<\/td><td><code>#!\/usr\/bin\/env python<\/code><code># -*- coding: utf-8 -*-<\/code><code># Copyright (c) 2014-17 Richard Hull and contributors<\/code><code># See LICENSE.rst for details.<\/code><code># PYTHON_ARGCOMPLETE_OK<\/code>&nbsp;<code>\"\"\"<\/code><code>Display the Raspberry Pi logo (loads image as .png).<\/code><code>\"\"\"<\/code>&nbsp;<code>import<\/code> <code>os.path<\/code><code>from<\/code> <code>PIL <\/code><code>import<\/code> <code>Image<\/code>&nbsp;<code>from<\/code> <code>luma.core.interface.serial <\/code><code>import<\/code> <code>i2c, spi<\/code><code>from<\/code> <code>luma.oled.device <\/code><code>import<\/code> <code>ssd1306, ssd1325, ssd1331, sh1106<\/code>&nbsp;<code>def<\/code> <code>main():<\/code><code>img_path <\/code><code>=<\/code> <code>os.path.abspath(os.path.join(os.path.dirname(__file__),<\/code><code>'images'<\/code><code>, <\/code><code>'pi_logo.png'<\/code><code>))<\/code><code>logo <\/code><code>=<\/code> <code>Image.<\/code><code>open<\/code><code>(img_path).convert(<\/code><code>\"RGBA\"<\/code><code>)<\/code><code>fff <\/code><code>=<\/code> <code>Image.new(logo.mode, logo.size, (<\/code><code>255<\/code><code>,) <\/code><code>*<\/code> <code>4<\/code><code>)<\/code>&nbsp;<code>background <\/code><code>=<\/code> <code>Image.new(<\/code><code>\"RGBA\"<\/code><code>, device.size, <\/code><code>\"white\"<\/code><code>)<\/code><code>posn <\/code><code>=<\/code> <code>((device.width <\/code><code>-<\/code> <code>logo.width) <\/code><code>\/<\/code><code>\/<\/code> <code>2<\/code><code>, <\/code><code>0<\/code><code>)<\/code>&nbsp;<code>while<\/code> <code>True<\/code><code>:<\/code><code>for<\/code> <code>angle <\/code><code>in<\/code> <code>range<\/code><code>(<\/code><code>0<\/code><code>, <\/code><code>360<\/code><code>, <\/code><code>2<\/code><code>):<\/code><code>rot <\/code><code>=<\/code> <code>logo.rotate(angle, resample<\/code><code>=<\/code><code>Image.BILINEAR)<\/code><code>img <\/code><code>=<\/code> <code>Image.composite(rot, fff, rot)<\/code><code>background.paste(img, posn)<\/code><code>device.display(background.convert(device.mode))<\/code>&nbsp;<code>if<\/code> <code>__name__ <\/code><code>=<\/code><code>=<\/code> <code>\"__main__\"<\/code><code>:<\/code><code>try<\/code><code>:<\/code><code>serial <\/code><code>=<\/code> <code>i2c(port<\/code><code>=<\/code><code>1<\/code><code>, address<\/code><code>=<\/code><code>0x3C<\/code><code>)<\/code><code>device <\/code><code>=<\/code> <code>sh1106(serial)<\/code><code>main()<\/code><code>except<\/code> <code>KeyboardInterrupt:<\/code><code>pass<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Python\u8fd0\u884c\u4e0a\u9762\u7684\u7a0b\u5e8foled\u5c4f\u4f1a\u51fa\u73b0\u4e00\u4e2a\u80fd\u65cb\u8f6c\u7684\u6811\u8393\u6d3eLOGO\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/shumeipai.nxez.com\/wp-content\/uploads\/2017\/09\/20170913105547498-0.jpg\" alt=\"\" class=\"wp-image-3455\"\/><\/figure><\/div>\n\n\n\n<p>\u5168\u6587\u5b8c\u3002<\/p>\n\n\n\n<p>\u6765\u6e90\uff1a<a rel=\"noreferrer noopener\" href=\"http:\/\/www.haoqiabin.cn\/2017\/08\/07\/raspberry-oled\/\" target=\"_blank\" rel=\"nofollow\" >\u89e3\u51b3\u6811\u8393\u6d3e\u9a71\u52a8OLED(\u975eSSD1306)\u82b1\u5c4f\u95ee\u9898<\/a><br>\u4f5c\u8005\uff1a\u597d\u5947\u5416\u658c<\/p>\n\n\n\n<p>\u539f\u6587\u94fe\u63a5:<a href=\"https:\/\/shumeipai.nxez.com\/2017\/09\/13\/solve-the-raspberry-pi-drive-oled-problem.html\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/shumeipai.nxez.com\/2017\/09\/13\/solve-the-raspberry-pi-drive-oled-problem.html<\/a><\/p>\n<button class=\"simplefavorite-button\" data-postid=\"837\" data-siteid=\"1\" data-groupid=\"1\" data-favoritecount=\"0\" style=\"\">\u6536\u85cf <i class=\"sf-icon-star-empty\"><\/i><\/button>","protected":false},"excerpt":{"rendered":"<p>\u6765\u81ea\u597d\u5947\u5416\u658c\u7684\u6295\u7a3f\uff0c\u611f\u8c22~\u6700\u8fd1\u5728\u5b66\u4e60\u6811\u8393\u6d3e\uff0c\u9a71\u52a8OLED\u5c4f\u65f6\u51fa\u73b0\u4e86\u4e00\u4e2a\u95ee\u9898\uff0c\u5c31\u662f\u82b1\u5c4f\uff0c\u6298\u817e\u4e86\u4e24\u5929\u540e\u53d1\u73b0\u539f\u6765\u8fd9\u4e2aOLED\u7684\u9a71\u52a8\u82af\u7247\u4e0d &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-837","post","type-post","status-publish","format-standard","hentry","category-10"],"_links":{"self":[{"href":"https:\/\/www.iotch.xyz\/index.php?rest_route=\/wp\/v2\/posts\/837","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.iotch.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.iotch.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.iotch.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.iotch.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=837"}],"version-history":[{"count":0,"href":"https:\/\/www.iotch.xyz\/index.php?rest_route=\/wp\/v2\/posts\/837\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.iotch.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.iotch.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.iotch.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}