{"id":15780185,"url":"https://github.com/rgl/oled-display-i2c-ssd1306","last_synced_at":"2025-03-14T08:32:40.100Z","repository":{"id":139753167,"uuid":"233428904","full_name":"rgl/oled-display-i2c-ssd1306","owner":"rgl","description":"Example SSD1306 OLED display controlled by a Raspberry Pi","archived":false,"fork":false,"pushed_at":"2020-01-12T17:16:23.000Z","size":11664,"stargazers_count":9,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-31T11:06:08.487Z","etag":null,"topics":["example","monochrome-oled-displays","oled","oled-display-ssd1306","raspberry-pi","ssd1306"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rgl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-12T17:15:36.000Z","updated_at":"2024-06-06T10:05:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"7cca169c-bb24-464a-9741-64279de9510e","html_url":"https://github.com/rgl/oled-display-i2c-ssd1306","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgl%2Foled-display-i2c-ssd1306","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgl%2Foled-display-i2c-ssd1306/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgl%2Foled-display-i2c-ssd1306/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgl%2Foled-display-i2c-ssd1306/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rgl","download_url":"https://codeload.github.com/rgl/oled-display-i2c-ssd1306/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243547633,"owners_count":20308744,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["example","monochrome-oled-displays","oled","oled-display-ssd1306","raspberry-pi","ssd1306"],"created_at":"2024-10-04T18:40:49.083Z","updated_at":"2025-03-14T08:32:39.175Z","avatar_url":"https://github.com/rgl.png","language":null,"readme":"# Raspberry Pi Usage\n\nBreadboard example of a [I2C](https://en.wikipedia.org/wiki/I2C) monochromatic 128x64 OLED display based on the SSD1306 controller:\n\n\u003cimg src=\"oled-display-i2c-ssd1306-rpi.jpg\" width=\"250\" /\u003e\n\nEnable i2c:\n\n```bash\n# NB this changes /boot/config.txt\nraspi-config nonint do_i2c 0\n\n# increase the i2c baud rate from the default of 100 KHz to 1 MHz.\n# see https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README\nsed -i -E 's/^(dtparam=i2c_arm=on).*/\\1,i2c_arm_baudrate=1000000/g' /boot/config.txt\n\n# reboot to apply changes.\nreboot\n\n# show i2c module information.\nmodinfo i2c_bcm2835\nmodinfo i2c_dev\n```\n\nInstall i2c tools:\n\n```bash\napt-get install -y i2c-tools\n```\n\nDetect i2c buses:\n\n```bash\ni2cdetect -l\n```\n\nIn my case, this displayed the single bus `i2c-1`:\n\n```plain\ni2c-1\ti2c       \tbcm2835 I2C adapter             \tI2C adapter\n```\n\nDetect i2c devices in bus `1`:\n\n```bash\ni2cdetect -y 1\n```\n\nIn my case, this displayed a single device at the `0x3c` address:\n\n```plain\n     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f\n00:          -- -- -- -- -- -- -- -- -- -- -- -- --\n10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --\n20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --\n30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --\n40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --\n50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --\n60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --\n70: -- -- -- -- -- -- -- --\n```\n\nInstall the [luma.oled](https://github.com/rm-hull/luma.oled) python library:\n\n```bash\napt-get install -y python3-dev python3-pip libfreetype6-dev libjpeg-dev build-essential libopenjp2-7 libtiff5\npython3 -m pip install luma.oled\n```\n\nDownload the rpi logo and resize it to fit the 128x64 oled display resolution:\n\n```bash\n# see https://commons.wikimedia.org/wiki/Raspberry_Pi_logos\nwget -qO rpi-logo-big.png https://upload.wikimedia.org/wikipedia/commons/0/01/RPi-Logo-White-SCREEN.png\npython3 \u003c\u003c'EOF'\nfrom PIL import Image\n\nimage = Image.open('rpi-logo-big.png')\nimage.thumbnail((128, 64), Image.BICUBIC)\nimage.save('rpi-logo.png', 'PNG')\nEOF\n```\n\nShow the rpi logo on the oled display:\n\n```bash\npython3 \u003c\u003c'EOF'\nimport time\nfrom luma.core.interface.serial import i2c\nfrom luma.oled.device import ssd1306\nfrom luma.core.render import canvas\nfrom PIL import Image\n\n# NB ssd1306 devices are monochromatic; a pixel is enabled with\n#    white and disabled with black.\n# NB the ssd1306 class has no way of knowing the device resolution/size.\ndevice = ssd1306(i2c(port=1, address=0x3c), width=128, height=64, rotate=0)\n\n# set the contrast to minimum.\ndevice.contrast(1)\n\n# load the rpi logo.\nlogo = Image.open('rpi-logo.png')\n\n# show some info.\nprint(f'device size {device.size}')\nprint(f'device mode {device.mode}')\nprint(f'logo size {logo.size}')\nprint(f'logo mode {logo.mode}')\n\n# NB this will only send the data to the display after this \"with\" block is complete.\n# NB the draw variable is-a PIL.ImageDraw.Draw (https://pillow.readthedocs.io/en/3.1.x/reference/ImageDraw.html).\n# see https://github.com/rm-hull/luma.core/blob/master/luma/core/render.py\nwith canvas(device, dither=True) as draw:\n    #draw.rectangle(device.bounding_box, outline='white', fill='black')\n    draw.bitmap((0, 0), logo)\n    message = 'Raspberry Pi'\n    text_size = draw.textsize(message)\n    draw.text((device.width - text_size[0], (device.height - text_size[1]) // 2), message, fill='white')\n\n# NB the display will be turn off after we exit this application.\ntime.sleep(5*60)\nEOF\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frgl%2Foled-display-i2c-ssd1306","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frgl%2Foled-display-i2c-ssd1306","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frgl%2Foled-display-i2c-ssd1306/lists"}