{"id":1941,"date":"2018-11-27T22:34:31","date_gmt":"2018-11-27T21:34:31","guid":{"rendered":"https:\/\/www.breizh56.fr\/crepp2024\/?page_id=1941"},"modified":"2022-12-07T00:05:01","modified_gmt":"2022-12-06T23:05:01","slug":"ssd1306","status":"publish","type":"page","link":"https:\/\/www.breizh56.fr\/crepp2024\/technique\/ssd1306\/","title":{"rendered":"SSD1306 affichage OLED i2c (0x3c: 60d) micropython (2019)"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>petit <a href=\"https:\/\/www.amazon.fr\/s?k=OLED+SSD1306&amp;i=electronics&amp;__mk_fr_FR=\u00c5M\u00c5\u017d\u00d5\u00d1&amp;ref=nb_sb_noss\">\u00e9cran Oled<\/a>, largeur 128c x longueur 64c, \u00a0i2c, noir et blanc permettant d&rsquo;afficher des textes, des images..<\/p>\n<p>4 broches: GND, VCC 3,3v \/ 5v, <strong>SCL, SDA&#8211;&gt; <a href=\"https:\/\/www.breizh56.fr\/crepp2024\/technique\/informatique\/cartes-embarquees\/i2c\/\">communication i2c<\/a><\/strong><\/p>\n<p><a href=\"https:\/\/www.breizh56.fr\/crepp2024\/wp-content\/uploads\/2019\/03\/PQP-OLED.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2275\" src=\"https:\/\/www.breizh56.fr\/crepp2024\/wp-content\/uploads\/2019\/03\/PQP-OLED.jpg\" alt=\"\" width=\"692\" height=\"568\" srcset=\"https:\/\/www.breizh56.fr\/crepp2024\/wp-content\/uploads\/2019\/03\/PQP-OLED.jpg 692w, https:\/\/www.breizh56.fr\/crepp2024\/wp-content\/uploads\/2019\/03\/PQP-OLED-300x246.jpg 300w\" sizes=\"(max-width: 692px) 100vw, 692px\" \/><\/a><\/p>\n<p>biblioth\u00e8que <a href=\"https:\/\/www.breizh56.fr\/crepp2024\/ssd1306-py\/\">ssd1306.py<\/a><\/p>\n<p>adresse i2c: <strong>0x3c ,60d<\/strong><\/p>\n<p><a href=\"https:\/\/www.breizh56.fr\/crepp2024\/wp-content\/uploads\/2019\/04\/SSD1306-data-sheet.pdf\">sch\u00e9ma technique<\/a>\u00a0ou <a href=\"https:\/\/cdn-shop.adafruit.com\/datasheets\/SSD1306.pdf\">ici<\/a><\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><i>rappel de broches ESP8266<br \/>\n<\/i><br \/>\n<img decoding=\"async\" src=\"https:\/\/www.breizh56.fr\/crepp2024\/wp-content\/uploads\/2018\/11\/i2cSclPin5SdaPin4.png\" \/><\/p>\n<hr \/>\n<p>Avec la biblioth\u00e8que ssd1306 on acc\u00e8de aux m\u00e9thodes suivantes:<\/p>\n<ul>\n<li><strong>text(), pour afficher sur texte au coordonn\u00e9es x,y<\/strong><\/li>\n<li><strong>show(),\u00a0affiche<\/strong><\/li>\n<li><strong>fill(), pour remplir l\u2019\u00e9cran en noir (1) ou blanc (0)<\/strong><\/li>\n<li><strong>poweroff(), \u00e9teindre\u00a0l\u2019\u00e9cran<\/strong><\/li>\n<li>contrast(), r\u00e9glage du contraste<\/li>\n<li>invert(), inverse les couleurs (blanc &lt;&#8211;&gt;\u00a0noir)<\/li>\n<li>pixel(), permet d\u2019allumer un pixel en particulier<\/li>\n<li>scroll(), permet de faire un scroll de l\u2019\u00e9cran.<\/li>\n<li>Dessin de lignes hline(), vline(), line()<\/li>\n<li>Dessin de rectangle rect(), fill_rect() &lt;&#8211; rempli<\/li>\n<\/ul>\n<hr \/>\n<p><strong>code micropython \u00e0 executer sur terminal<\/strong><\/p>\n<pre># intialisation du bus i2c\r\n# scl=Pin5=GPIO5=d1 sda=Pin4=GPIO4=d2\r\n\r\nfrom machine import I2C, Pin\r\ni2c= I2C(scl=Pin(5), sda=Pin(4))\r\n\r\nimport ssd1306\r\n\r\n# adresse Oled 0x3c ?\r\nprint(i2c.scan())\r\n\r\n#initialisation de l'\u00e9cran 128x32 \u00e0 0x3c\r\noled=ssd1306.SSD1306_I2C(128,32, i2c, 0x3c)\r\n\r\n# timer\r\nimport time\r\n\r\noled.fill(0)\r\noled.text(\"Bonjour\", 0, 0)\r\noled.text(\"il fait beau\", 0, 20)\r\noled.show()\r\n\r\n<\/pre>\n<pre>time.sleep_ms(3000)\r\n\r\n<\/pre>\n<pre>import machine, sys oled.text('version\u00a0'\u00a0+\u00a0sys.version,\u00a00,10) oled.text('CPU:\u00a0'\u00a0+\u00a0str(machine.freq()\/1000000)\u00a0+\u00a0'MHz',\u00a00,20)<\/pre>\n<pre>oled.show() \r\n<\/pre>\n<pre>time.sleep_ms(3000)<\/pre>\n<pre># inversion fond blanc=1 \/ fond noir=0 \r\noled.invert(1) \r\n\r\n<\/pre>\n<pre>time.sleep_ms(3000)<\/pre>\n<pre># \u00e9cran blanc=1 \/ noir=0 \r\noled.fill(1) \r\noled.show() \r\n\r\n# 1-255 oled.constrast(150)<\/pre>\n<p>&nbsp;<\/p>\n<p>exemple d&rsquo;utilisation<\/p>\n<blockquote>\n<pre>import machine\r\nrtc= machine.RTC()\r\noled.text(str(rtc.datetime(), 0, 20)<\/pre>\n<\/blockquote>\n<p>&nbsp;<\/p>\n<hr \/>\n<p>Exemple <a href=\"https:\/\/www.breizh56.fr\/crepp2024\/wp-content\/uploads\/2019\/03\/pqp_oled.py_.zip\">pqp_oled<\/a> offrant les m\u00e9thodes:<\/p>\n<p>affiche, afficheXY, surafficheXY, efface, inverse, test, machine<\/p>\n<pre># intialisation du bus i2c\r\n# scl=Pin5=GPIO5=d1 sda=Pin4=GPIO4=d2\r\n#del sys.modules['pqp_oled']\r\n\r\nfrom machine import I2C, Pin\r\ni2c= I2C(scl=Pin(5), sda=Pin(4))\r\n\r\nimport ssd1306\r\n\r\n# adresse Oled 0x3c ?\r\nprint(i2c.scan())\r\n\r\n#initialisation de l'\u8305cran 128x64 \u813f 0x3c\r\n# oled=ssd1306.SSD1306_I2C(128,64, i2c, 0x3c)\r\noled=ssd1306.SSD1306_I2C(128,32, i2c, 0x3c)\r\n\r\n\r\n# timer\r\nimport time\r\n# time.sleep_ms(5000)\r\n\r\ndef affiche(Quoi):\r\n oled.fill(0)\r\n oled.text(Quoi, 0, 10)\r\n oled.show()\r\n \r\ndef afficheXY(Quoi,x,y):\r\n oled.fill(0) \r\n oled.text(Quoi, int(x), int(y))\r\n oled.show()\r\n \r\ndef surafficheXY(Quoi,x,y):\r\n #oled.fill(0)\r\n oled.text(Quoi, int(x), int(y))\r\n oled.show()\r\n \r\ndef efface():\r\n oled.fill(0)\r\n oled.show()\r\n \r\ndef inverse(p):\r\n oled.invert(p)\r\n \r\ndef test():\r\n oled.fill(0)\r\n oled.text(\"Bonjour\", 0, 0)\r\n oled.text(\"il fait beau\", 0, 20)\r\n oled.show()\r\n \r\ndef machine(): \r\n efface()\r\n import machine, sys\r\n oled.text('version ' + sys.version, 0,10)\r\n oled.text('CPU: ' + str(machine.freq()\/1000000) + 'MHz', 0,20)\r\n oled.show() \r\n time.sleep_ms(2500)\r\n # inversion fond blanc=1 \/ fond noir=0 \r\n oled.invert(1) \r\n time.sleep_ms(2000)\r\n # \u8305cran blanc=1 \/ noir=0 \r\n oled.fill(0) \r\n oled.show() \r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>exemple d&rsquo;utilisation<\/p>\n<blockquote>\n<pre>import pqp_oled as o\r\no.afficheXY('Bonjour','80','25)\r\no.machine()<\/pre>\n<\/blockquote>\n<p><a href=\"https:\/\/www.breizh56.fr\/crepp2024\/wp-content\/uploads\/2019\/03\/pqp_oled_execution.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2338\" src=\"https:\/\/www.breizh56.fr\/crepp2024\/wp-content\/uploads\/2019\/03\/pqp_oled_execution.jpg\" alt=\"\" width=\"404\" height=\"492\" srcset=\"https:\/\/www.breizh56.fr\/crepp2024\/wp-content\/uploads\/2019\/03\/pqp_oled_execution.jpg 404w, https:\/\/www.breizh56.fr\/crepp2024\/wp-content\/uploads\/2019\/03\/pqp_oled_execution-246x300.jpg 246w\" sizes=\"(max-width: 404px) 100vw, 404px\" \/><\/a><\/p>\n<hr \/>\n<p><strong>affichage sur Oled (pqp_oled.py) de la luminosit\u00e9 (pqp_luxmetre.py)<\/strong><br \/>\n<a href=\"https:\/\/www.breizh56.fr\/crepp2024\/wp-content\/uploads\/2019\/04\/pqp_luxmetreoled.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2355\" src=\"https:\/\/www.breizh56.fr\/crepp2024\/wp-content\/uploads\/2019\/04\/pqp_luxmetreoled.jpg\" alt=\"\" width=\"497\" height=\"546\" srcset=\"https:\/\/www.breizh56.fr\/crepp2024\/wp-content\/uploads\/2019\/04\/pqp_luxmetreoled.jpg 497w, https:\/\/www.breizh56.fr\/crepp2024\/wp-content\/uploads\/2019\/04\/pqp_luxmetreoled-273x300.jpg 273w\" sizes=\"(max-width: 497px) 100vw, 497px\" \/><\/a><\/p>\n<hr \/>\n<p>Exemple <a href=\"https:\/\/www.breizh56.fr\/crepp2024\/wp-content\/uploads\/2018\/12\/OledMontre.py_.zip\">montre sur Oled<\/a> (n\u00e9cessite module DS3231 i2c)<\/p>\n<blockquote>\n<pre># montre \u00e0 quartz sur oled\r\n# ppr 181213\r\n# utilisation sous REPL:\r\n# import OledMontre\r\n# OledMontre.heure_mm(100) \r\n# 1:22\/23 --&gt; 99 \u00e0 0\r\n\r\nfrom machine import I2C, Pin, RTC\r\nfrom ds3231_port import DS3231 # horloge date\/heure\r\nimport ssd1306 # oled\r\n\r\n# intialisation du bus i2c\r\n# scl=Pin5=GPIO5=d1 sda=Pin4=GPIO4=d2\r\n\r\ni2c= I2C(scl=Pin(5), sda=Pin(4))\r\n\r\n#initialisation de l'\u00e9cran 128x64 \u00e0 0x3c\r\noled=ssd1306.SSD1306_I2C(128,64, i2c, 0x3c)\r\n\r\n# adresse Oled 0x3c= 60 ?\r\nprint(i2c.scan())\r\n\r\n# date\/heure\r\nds3231=DS3231(i2c)\r\n\r\ndef heure_mm(i):\r\n while i &gt; 0:\r\n i = i - 1\r\n # on r\u00e9cup\u00e8re la date et heure\r\n (an, mois, jour, hh, mm, ss, jsem, zorbec) = ds3231.get_time()\r\n # affiche sur oled\r\n oled.fill(0)\r\n oled.text( str(hh) + ':' + str(mm) + ':' + str(ss) + ' --&gt;' + str(i), 0, 40)\r\n oled.show()\r\n \r\n\r\n\r\ndef heure_1x():\r\n # on r\u00e9cup\u00e8re la date et heure\r\n (an, mois, jour, hh, mm, ss, jsem, zorbec) = ds3231.get_time()\r\n # affiche sur oled\r\n oled.fill(0)\r\n oled.text( str(hh) + ':' + str(mm) + ':' + str(ss), 0, 40)\r\n oled.show()<\/pre>\n<\/blockquote>\n<pre>utilisation sous REPL:\r\n&gt;&gt;&gt; import OledMontre\r\n&gt;&gt;&gt; OledMontre.heure_mm(100) \r\n\r\n affichage sur Oled <strong>1:22\/23 --&gt; 99<\/strong> \u00e0 0<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.breizh56.fr\/crepp2024\/wp-content\/uploads\/2019\/03\/Oled-apala-190327.mov\">https:\/\/www.breizh56.fr\/crepp2024\/wp-content\/uploads\/2019\/03\/Oled-apala-190327.mov<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; &nbsp; petit \u00e9cran Oled, largeur 128c x longueur 64c, \u00a0i2c, noir et blanc permettant d&rsquo;afficher des textes, des images.. 4 broches: GND, VCC 3,3v \/ 5v, SCL, SDA&#8211;&gt; communication i2c biblioth\u00e8que ssd1306.py adresse i2c: 0x3c ,60d sch\u00e9ma technique\u00a0ou ici &nbsp; &nbsp; &nbsp; rappel de broches ESP8266 Avec la biblioth\u00e8que ssd1306 on acc\u00e8de aux m\u00e9thodes suivantes: text(), pour afficher sur [&#8230;]<\/p>\n","protected":false},"author":7,"featured_media":0,"parent":44,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1941","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.breizh56.fr\/crepp2024\/wp-json\/wp\/v2\/pages\/1941"}],"collection":[{"href":"https:\/\/www.breizh56.fr\/crepp2024\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.breizh56.fr\/crepp2024\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.breizh56.fr\/crepp2024\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.breizh56.fr\/crepp2024\/wp-json\/wp\/v2\/comments?post=1941"}],"version-history":[{"count":37,"href":"https:\/\/www.breizh56.fr\/crepp2024\/wp-json\/wp\/v2\/pages\/1941\/revisions"}],"predecessor-version":[{"id":5298,"href":"https:\/\/www.breizh56.fr\/crepp2024\/wp-json\/wp\/v2\/pages\/1941\/revisions\/5298"}],"up":[{"embeddable":true,"href":"https:\/\/www.breizh56.fr\/crepp2024\/wp-json\/wp\/v2\/pages\/44"}],"wp:attachment":[{"href":"https:\/\/www.breizh56.fr\/crepp2024\/wp-json\/wp\/v2\/media?parent=1941"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}