Coder Social home page Coder Social logo

adafruit_python_ssd1306's Introduction

DEPRECATED LIBRARY Adafruit Python SSD1306

his library has been deprecated! We are leaving this up for historical and research purposes but archiving the repository.

We are now only supporting the use of our CircuitPython libraries for use with Python.

Check out this guide for info on using OLEDs with the CircuitPython library: https://learn.adafruit.com/monochrome-oled-breakouts/python-wiring


Python library to use SSD1306-based 128x64 or 128x32 pixel OLED displays with a Raspberry Pi or Beaglebone Black.

Designed specifically to work with the Adafruit SSD1306-based OLED displays ----> https://www.adafruit.com/categories/98

Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!

Installing

sudo python -m pip install --upgrade pip setuptools wheel
sudo pip install Adafruit-SSD1306

Or alternatively:

sudo python -m pip install --upgrade pip setuptools wheel
git clone https://github.com/adafruit/Adafruit_Python_SSD1306.git
cd Adafruit_Python_SSD1306
sudo python setup.py install

Copying

Written by Tony DiCola for Adafruit Industries. MIT license, all text above must be included in any redistribution

adafruit_python_ssd1306's People

Contributors

abhinuvpitale avatar brennen avatar jmzjmzjmz avatar ladyada avatar tdicola avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_python_ssd1306's Issues

error install python3

Thank you for opening an issue on an Adafruit Python library repository. To
improve the speed of resolution please review the following guidelines and
common troubleshooting steps below before creating the issue:

  • Do not use GitHub issues for troubleshooting projects and issues. Instead use
    the forums at http://forums.adafruit.com to ask questions and troubleshoot why
    something isn't working as expected. In many cases the problem is a common issue
    that you will more quickly receive help from the forum community. GitHub issues
    are meant for known defects in the code. If you don't know if there is a defect
    in the code then start with troubleshooting on the forum first.

  • If following a tutorial or guide be sure you didn't miss a step. Carefully
    check all of the steps and commands to run have been followed. Consult the
    forum if you're unsure or have questions about steps in a guide/tutorial.

  • For Python/Raspberry Pi projects check these very common issues to ensure they don't apply:

    • If you are receiving an ImportError: No module named... error then a
      library the code depends on is not installed. Check the tutorial/guide or
      README to ensure you have installed the necessary libraries. Usually the
      missing library can be installed with the pip tool, but check the tutorial/guide
      for the exact command.

    • Be sure you are supplying adequate power to the board. Check the specs of
      your board and power in an external power supply. In many cases just
      plugging a board into your computer is not enough to power it and other
      peripherals.

    • Double check all soldering joints and connections. Flakey connections
      cause many mysterious problems. See the guide to excellent soldering for examples of good solder joints.

If you're sure this issue is a defect in the code and checked the steps above
please fill in the following fields to provide enough troubleshooting information.
You may delete the guideline and text above to just leave the following details:

  • Platform/operating system (i.e. Raspberry Pi with Raspbian operating system,
    Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.): INSERT PLATFORM/OPERATING
    SYSTEM HERE

  • Python version (run python -version or python3 -version): INSERT PYTHON
    VERSION HERE

  • Error message you are receiving, including any Python exception traces: INSERT
    ERROR MESAGE/EXCEPTION TRACES HERE
    *

  • List the steps to reproduce the problem below (if possible attach code or commands
    to run): LIST REPRO STEPS BELOW

pip library not updated to latest

  • Platform/operating system (i.e. Raspberry Pi with Raspbian operating system,
    Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.):
    Raspbian: Linux ##### 4.9.61-v7+ #1049 SMP Fri Nov 10 15:32:51 GMT 2017 armv7l GNU/Linux
    Distributor ID: Raspbian
    Description: Raspbian GNU/Linux 9.1 (stretch)
    Release: 9.1
    Codename: stretch

  • Python version (run python -version or python3 -version):
    pip: 9.0.1
    python: 2.7.13

  • Error message you are receiving, including any Python exception traces:
    Traceback (most recent call last):
    File "stats.py", line 29, in
    disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)
    File "/usr/local/lib/python2.7/dist-packages/Adafruit_SSD1306/SSD1306.py", line 285, in init
    gpio, spi, i2c_bus, i2c_address, i2c)
    File "/usr/local/lib/python2.7/dist-packages/Adafruit_SSD1306/SSD1306.py", line 88, in init
    self._gpio.setup(self._rst, GPIO.OUT)
    File "/usr/local/lib/python2.7/dist-packages/Adafruit_GPIO/GPIO.py", line 188, in setup
    pull_up_down=self._pud_mapping[pull_up_down])
    ValueError: Channel must be an integer or list/tuple of integers

  • List the steps to reproduce the problem below (if possible attach code or commands
    to run):

pip install Adafruit-GPIO Adafruit-SSD1306
apt-get install python-pilkit
apt-get install python-imaging

Run the script below and you will get the error message. I replaced the SSD1306.py script with the one from this repo and everything works. It appears the pip repo is out of date from this repo.

****************************************** CODE *****************************************
import time
import Adafruit_GPIO.SPI as SPI
import Adafruit_SSD1306
import subprocess
import signal
import sys

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont

def signal_term_handler(signal, frame):
disp.command(Adafruit_SSD1306.SSD1306_DISPLAYOFF)
sys.exit(0)

#Setup Signal Handler
signal.signal(signal.SIGTERM, signal_term_handler)

Raspberry Pi pin configuration:

RST = None # on the PiOLED this pin isnt used

Note the following are only used with SPI:

DC = 23
SPI_PORT = 0
SPI_DEVICE = 0

128x32 display with hardware I2C:

disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)

Initialize library.

disp.begin()

Clear display.

disp.clear()
disp.display()

Create blank image for drawing.

width = disp.width
height = disp.height
image = Image.new('1', (width, height))

Get drawing object to draw on image.

draw = ImageDraw.Draw(image)

Draw a black filled box to clear the image.

draw.rectangle((0,0,width,height), outline=0, fill=0)

Draw some shapes.

padding = -2
top = padding
bottom = height-padding
x = 0

Load default font.

font = ImageFont.load_default()

try:
while True:

    # Draw a black filled box to clear the image.
    draw.rectangle((0,0,width,height), outline=0, fill=0)

    # Shell scripts for system monitoring from here : https://unix.stackexchange.com/questions/119126/command-to-display-memory-usage-disk-usage-and-cpu-load
    cmd = "hostname -I | cut -d\' \' -f1"
    IP = subprocess.check_output(cmd, shell = True )

    cmd = "top -bn1 | grep load | awk '{printf \"Load:%.2f\", $(NF-2)}'"
    CPU = subprocess.check_output(cmd, shell = True )

    cmd = " echo $(($(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)/1000))"
    Freq = subprocess.check_output(cmd, shell = True )

    cmd = "free -m | awk 'NR==2{printf \"Mem: %s/%sMB %.2f%%\", $3,$2,$3*100/$2 }'"
    MemUsage = subprocess.check_output(cmd, shell = True )

    cmd = "cat /sys/class/thermal/thermal_zone0/temp"
    CPUTemp = subprocess.check_output(cmd, shell = True )
    CPUTemp = int(CPUTemp)/1000
    CPUTemp = str(9.0/5.0 * CPUTemp + 32) + "F"

    cmd = "vcgencmd measure_temp | sed 's/temp=//g'"
    GPUTemp = subprocess.check_output(cmd, shell = True )
    GPUTemp = str(GPUTemp).replace("temp=","").replace("'C","")
    GPUTemp = str(9.0/5.0 * float(GPUTemp) + 32) + "F"

    draw.text((x, top),       "IP: " + str(IP),  font=font, fill=255)
    draw.text((x, top+8),     str(CPU) + "  Freq:" + str(Freq), font=font, fill=255)
    draw.text((x, top+16),    str(MemUsage),  font=font, fill=255)
    draw.text((x, top+25),    "CPU:" + str(CPUTemp) + " GPU:" + str(GPUTemp),  font=font, fill=255)

    # Display image
    disp.image(image)
    disp.display()
    time.sleep(.5)

except KeyboardInterrupt:
disp.command(Adafruit_SSD1306.SSD1306_DISPLAYOFF)

python version missing

having a really hard time getting this to run on ArchLinux. knowing with which python this should be working would allow to exclude half of the debugging. thank you. =)

"File is not a zip file" error when building per website instructions

Using instructions from website here: https://learn.adafruit.com/adafruit-pioled-128x32-mini-oled-for-raspberry-pi/usage

On latest Raspbian Stretch:

pi@raspberrypi:~ $ git clone https://github.com/adafruit/Adafruit_Python_SSD1306.git
Cloning into 'Adafruit_Python_SSD1306'...
remote: Counting objects: 112, done.
remote: Total 112 (delta 0), reused 0 (delta 0), pack-reused 112
Receiving objects: 100% (112/112), 34.60 KiB | 0 bytes/s, done.
Resolving deltas: 100% (57/57), done.
pi@raspberrypi:~ $ cd Adafruit_Python_SSD1306
pi@raspberrypi:~/Adafruit_Python_SSD1306 $ sudo python setup.py install
Downloading https://pypi.python.org/packages/source/s/setuptools/setuptools-3.5.1.zip
Extracting in /tmp/tmpPeTB4Y
Traceback (most recent call last):
  File "setup.py", line 4, in <module>
    use_setuptools()
  File "/home/pi/Adafruit_Python_SSD1306/ez_setup.py", line 128, in use_setuptools
    return _do_download(version, download_base, to_dir, download_delay)
  File "/home/pi/Adafruit_Python_SSD1306/ez_setup.py", line 108, in _do_download
    _build_egg(egg, archive, to_dir)
  File "/home/pi/Adafruit_Python_SSD1306/ez_setup.py", line 57, in _build_egg
    with archive_context(archive_filename):
  File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/home/pi/Adafruit_Python_SSD1306/ez_setup.py", line 88, in archive_context
    with get_zip_class()(filename) as archive:
  File "/usr/lib/python2.7/zipfile.py", line 770, in __init__
    self._RealGetContents()
  File "/usr/lib/python2.7/zipfile.py", line 813, in _RealGetContents
    raise BadZipfile, "File is not a zip file"
zipfile.BadZipfile: File is not a zip file

issues when running with Beaglebone Black

when I tried to run the programs with both pythion 2 and 3, an error msg showed as below:

root@beaglebone:~/Adafruit_Python_SSD1306/examples# python image.py
Traceback (most recent call last):
File "image.py", line 56, in
disp.begin()
File "/usr/local/lib/python2.7/dist-packages/Adafruit_SSD1306/SSD1306.py", line 148, in begin
self._initialize()
File "/usr/local/lib/python2.7/dist-packages/Adafruit_SSD1306/SSD1306.py", line 247, in _initialize
self.command(SSD1306_DISPLAYOFF) # 0xAE
File "/usr/local/lib/python2.7/dist-packages/Adafruit_SSD1306/SSD1306.py", line 129, in command
self._i2c.write8(control, c)
File "/usr/local/lib/python2.7/dist-packages/Adafruit_GPIO-1.0.3-py2.7.egg/Adafruit_GPIO/I2C.py", line 116, in write8
self._bus.write_byte_data(self._address, register, value)
File "/usr/local/lib/python2.7/dist-packages/Adafruit_PureIO/smbus.py", line 256, in write_byte_data
self._device.write(data)
IOError: [Errno 16] Device or resource busy

Did I get something wrong in the program?
Regards,

Debian 2015-03-01?

Mike, I am trying to run this code on a fresh install of Debian and get the following errors when running the examples. Any chance you have tried code on a BBB recently?

root@beaglebone:~/Adafruit_Python_SSD1306/examples# python animate.py
Traceback (most recent call last):
  File "animate.py", line 74, in <module>
    font = ImageFont.load_default()
  File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 377, in l                                           oad_default
    '''))))
  File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 117, in _                                           load_pilfont_data
    image.load()
  File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFile.py", line 189, in l                                           oad
    d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
  File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 385, in _getd                                           ecoder
    raise IOError("decoder %s not available" % decoder_name)
IOError: decoder zip not available

happy cat path is wrong

There is a small error in the example scripts when trying to display images. The images are referred to without a path, and the result is that the script will crash when trying to display the referenced image.

For example,
IOError: [Errno 2] No such file or directory: 'happycat_oled_32.ppm'

To fix this, I simply edited the buttons.py script at line 154 with an absolute path to the image file.
It was ๐Ÿ‘
catImage = Image.open('happycat_oled_64.ppm').convert('1')

Changed to:
catImage = Image.open('/home/pi/Adafruit_Python_SSD1306/examples/happycat_oled_64.ppm').convert('1')

now, it works fine.

Documentation missing

The documentation page doesn't completely document the steps necessary to make I2C work.
Specifically, on a virgin Raspberry Pi, you need to do the following:
Put a # comment in front of the blacklist i2c-bcm2708 line in /etc/modprobe.d/raspi-blacklist.conf
Add the modules i2c-bcm2708 AND i2c-dev to the file /etc/modules <-- this took me a while to find out!
Restart, or run modprobe to install the modules.
After this, you can find the i2c bus using i2cscan -l. Before that, you will get "No such file or device" or similar errors.

Adafruit_SSD1306.SSD1306_128_64 - TypeError: argument 1 must be string, not int

  • Platform/operating system (i.e. Raspberry Pi with Raspbian operating system,
    Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.): Raspberry Pi 3 Model B

  • Python version (run python -version or python3 -version): Python 2.7.9

  • Error message you are receiving, including any Python exception traces:

Traceback (most recent call last):
  File "stats.py", line 63, in <module>
    disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))
  File "build/bdist.linux-armv7l/egg/Adafruit_SSD1306/SSD1306.py", line 243, in __init__
  File "build/bdist.linux-armv7l/egg/Adafruit_SSD1306/SSD1306.py", line 115, in __init__
  File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/GPIO.py", line 278, in setup
TypeError: argument 1 must be string, not int
  • List the steps to reproduce the problem below (if possible attach code or commands
    to run):

Using example file provided by repo does not work. I'm using the SPI version. So uncommenting the following line leads to the error above:
https://github.com/adafruit/Adafruit_Python_SSD1306/blob/master/examples/stats.py#L63
disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))

How can I fix this?

Make I2C Address a parameter to init?

In using this library I found I had to change:

SSD1306_I2C_ADDRESS = 0x3C  # 011110+SA0+RW - 0x3C or 0x3D

to

SSD1306_I2C_ADDRESS = 0x3D  # 011110+SA0+RW - 0x3C or 0x3D

Since this address could change:

https://www.adafruit.com/products/326
This board/chip uses I2C 7-bit address between 0x3C-0x3D, selectable with jumpers

would it be possible to make it a parameter:

def __init__(self, width, height, rst, dc=None, sclk=None, din=None, cs=None, gpio=None, spi=None, i2c_bus=I2C.get_default_bus()):

would change to:

def __init__(self, width, height, rst, dc=None, sclk=None, din=None, cs=None, gpio=None, spi=None, i2c_bus=I2C.get_default_bus(), i2c_address=0x3C):

and

self._i2c = I2C.Device(SSD1306_I2C_ADDRESS, i2c_bus)

to

self._i2c = I2C.Device(i2c_address, i2c_bus)

(and a few other places in the library)

Right now I'm fairly new to python, so I'm not too sure if this would work the way I've written it here, and why I didn't make a pull request. I tested some code changes, and they work.

IOError: [Errno 70] Communication error on send

Hardware: Orange PI Zero
OS: Distributor ID: Ubuntu
Description: Ubuntu 16.04.6 LTS
Release: 16.04
Codename: xenial
Python version: 2.7.12-1~16.04

root@OrangePI:~/Adafruit_Python_SSD1306/examples# sudo i2cdetect -y 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

root@OrangePI:~/Adafruit_Python_SSD1306/examples# python stats.py
Traceback (most recent call last):
File "stats.py", line 71, in
disp.begin()
File "/usr/local/lib/python2.7/dist-packages/Adafruit_SSD1306/SSD1306.py", line 148, in begin
self._initialize()
File "/usr/local/lib/python2.7/dist-packages/Adafruit_SSD1306/SSD1306.py", line 292, in _initialize
self.command(SSD1306_DISPLAYOFF) # 0xAE
File "/usr/local/lib/python2.7/dist-packages/Adafruit_SSD1306/SSD1306.py", line 129, in command
self._i2c.write8(control, c)
File "/usr/local/lib/python2.7/dist-packages/Adafruit_GPIO/I2C.py", line 114, in write8
self._bus.write_byte_data(self._address, register, value)
File "/usr/local/lib/python2.7/dist-packages/Adafruit_PureIO/smbus.py", line 256, in write_byte_data
self._device.write(data)
IOError: [Errno 70] Communication error on send

RuntimeError: Could not determine platform

  • Platform/operating system (i.e. Raspberry Pi with Raspbian operating system,
    Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.): Raspberry Pi zero Rev1 with Raspian and newst update)

  • Python version (run python -version or python3 -version): .2.7.9 and 3.4.2

  • Error message you are receiving, including any Python exception traces: Traceback (most recent call last):
    File "Feldbahn/Fernbedienung.py", line 26, in
    disp = Adafruit_SSD1306.SSD1306_128_64(rst=4, i2c_address=0x3d)
    File "build/bdist.linux-armv6l/egg/Adafruit_SSD1306/SSD1306.py", line 240, in init
    File "build/bdist.linux-armv6l/egg/Adafruit_SSD1306/SSD1306.py", line 85, in init
    File "build/bdist.linux-armv6l/egg/Adafruit_GPIO/GPIO.py", line 426, in get_platform_gpio
    RuntimeError: Could not determine platform.

  • List the steps to reproduce the problem below (if possible attach code or commands
    to run):
    run one of the examples

MicroPython 1.8 on Huzzah ESP8266 with 128x32 OLED

Hi Mike, I am an an early adopter of MicroPython on the ESP8266 and would very much like to get the 128x32 OLED feather wing working there. I noticed that the feather libraries pull in SSD1306.h and in researching found this library for BB and Pi. Any pointers before I start hacking to try and make this work? ๐Ÿ”จ

IOError: [Errno 2] No such file or directory: '/dev/i2c-1'

Hardware : Orange Pi Zero

OS : ARMBIAN 5.73 stable Debian GNU/Linux 9 (stretch) 4.19.20-sunxi

Python : Python 2.7.13 (default, Sep 26 2018, 18:42:22)
[GCC 6.3.0 20170516] on linux2

sudo i2cdetect -y 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

python
Python 2.7.13 (default, Sep 26 2018, 18:42:22)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.

        import Adafruit_GPIO.SPI as SPI
        import Adafruit_SSD1306
        RST = None
        DC = 23
        SPI_PORT = 0
        SPI_DEVICE = 0
        disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, i2c_address=0x3C)
        Traceback (most recent call last):
        File "", line 1, in
        File "/usr/local/lib/python2.7/dist-packages/Adafruit_SSD1306/SSD1306.py", line 243, in init
        gpio, spi, i2c_bus, i2c_address, i2c)
        File "/usr/local/lib/python2.7/dist-packages/Adafruit_SSD1306/SSD1306.py", line 107, in init
        self._i2c = I2C.get_i2c_device(i2c_address)
        File "/usr/local/lib/python2.7/dist-packages/Adafruit_GPIO/I2C.py", line 64, in get_i2c_device
        return Device(address, busnum, i2c_interface, **kwargs)
        File "/usr/local/lib/python2.7/dist-packages/Adafruit_GPIO/I2C.py", line 97, in init
        self._bus = Adafruit_PureIO.smbus.SMBus(busnum)
        File "/usr/local/lib/python2.7/dist-packages/Adafruit_PureIO/smbus.py", line 105, in init
        self.open(bus)
        File "/usr/local/lib/python2.7/dist-packages/Adafruit_PureIO/smbus.py", line 130, in open
        self._device = open('/dev/i2c-{0}'.format(bus), 'r+b', buffering=0)
        IOError: [Errno 2] No such file or directory: '/dev/i2c-1'

Changing font / size

I have succeeded to installing and run the examples included in this code on a ssd1306 i2c device, but I primarily want to display text, again I have succeeded but I cannot understand how to change the font size, it occurred to me that maybe I need to use a larger font type, so I followed the advice and downloaded Minecraftia.ttf', 8 from http://www.dafont.com/bitmap.php but when I try to use it I get the following error :
font = ImageFont.truetype('Minecraftia.ttf', 8)
File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 218, in truetype
return FreeTypeFont(filename, size, index, encoding)
File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 134, in init
self.font = core.getfont(file, size, index, encoding)
IOError: cannot open resource

So the question is how do I change the size of text and how do I actually utilize a different font type ?

Thanks and regards

An issue with my raspberry pi with the https://github.com code

Thank you for opening an issue on an Adafruit Python library repository. To
improve the speed of resolution please review the following guidelines and
common troubleshooting steps below before creating the issue:

  • Do not use GitHub issues for troubleshooting projects and issues. Instead use
    the forums at http://forums.adafruit.com to ask questions and troubleshoot why
    something isn't working as expected. In many cases the problem is a common issue
    that you will more quickly receive help from the forum community. GitHub issues
    are meant for known defects in the code. If you don't know if there is a defect
    in the code then start with troubleshooting on the forum first.

  • If following a tutorial or guide be sure you didn't miss a step. Carefully
    check all of the steps and commands to run have been followed. Consult the
    forum if you're unsure or have questions about steps in a guide/tutorial.

  • For Python/Raspberry Pi projects check these very common issues to ensure they don't apply:

    • If you are receiving an ImportError: No module named... error then a
      library the code depends on is not installed. Check the tutorial/guide or
      README to ensure you have installed the necessary libraries. Usually the
      missing library can be installed with the pip tool, but check the tutorial/guide
      for the exact command.

    • Be sure you are supplying adequate power to the board. Check the specs of
      your board and power in an external power supply. In many cases just
      plugging a board into your computer is not enough to power it and other
      peripherals.

    • Double check all soldering joints and connections. Flakey connections
      cause many mysterious problems. See the guide to excellent soldering for examples of good solder joints.

If you're sure this issue is a defect in the code and checked the steps above
please fill in the following fields to provide enough troubleshooting information.
You may delete the guideline and text above to just leave the following details:

  • Platform/operating system (i.e. Raspberry Pi with Raspbian operating system,
    Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.): INSERT PLATFORM/OPERATING
    SYSTEM HERE

  • Python version (run python -version or python3 -version): INSERT PYTHON
    VERSION HERE

  • Error message you are receiving, including any Python exception traces: INSERT
    ERROR MESAGE/EXCEPTION TRACES HERE
    *

  • List the steps to reproduce the problem below (if possible attach code or commands
    to run): LIST REPRO STEPS BELOW

TypeError: __init__() takes at least 3 arguments (3 given)

Hello,
I have following issue on RBPI:

pi@RBPI:~/apps/OLED/python-examples $ sudo python OLEDclock.py
Traceback (most recent call last):
  File "OLEDclock.py", line 18, in <module>
    led = gaugette.ssd1306.SSD1306(reset_pin=RESET_PIN, dc_pin=DC_PIN)
TypeError: __init__() takes at least 3 arguments (3 given)

image

line 11: (yellow highlighted)
image

OS:
Linux RBPI 4.4.21-v7+ #911 SMP Thu Sep 15 14:22:38 BST 2016 armv7l GNU/Linux with Python 2.7.9

IOError: [Errno 6] No such device or address

Hardware : Orange Pi Zero

OS : ARMBIAN 5.73 stable Debian GNU/Linux 9 (stretch) 4.19.20-sunxi

Python : Python 2.7.13 (default, Sep 26 2018, 18:42:22)
[GCC 6.3.0 20170516] on linux2

sudo i2cdetect -y 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

python
Python 2.7.13 (default, Sep 26 2018, 18:42:22)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import Adafruit_GPIO.SPI as SPI
import Adafruit_SSD1306

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont

RST = None

disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, i2c_address=0x3C)

disp.begin()
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/Adafruit_SSD1306/SSD1306.py", line 148, in begin self._initialize()
File "/usr/local/lib/python2.7/dist-packages/Adafruit_SSD1306/SSD1306.py", line 247, in _initialize self.command(SSD1306_DISPLAYOFF) # 0xAE
File "/usr/local/lib/python2.7/dist-packages/Adafruit_SSD1306/SSD1306.py", line 129, in command self._i2c.write8(control, c)
File "/usr/local/lib/python2.7/dist-packages/Adafruit_GPIO/I2C.py", line 114, in write8 self._bus.write_byte_data(self._address, register, value)
File "/usr/local/lib/python2.7/dist-packages/Adafruit_PureIO/smbus.py", line 256, in write_byte_data
self._device.write(data)
IOError: [Errno 6] No such device or address

Banana Pi (Raspbian)

i2cdetect -y 2:
line 30 row c with 3c in it

sudo python shapes.py
gives this error:
Traceback (most recent call last):
File "shapes.py", line 49, in
disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)
File "/usr/local/lib/python2.7/dist-packages/Adafruit_SSD1306-1.5.0-py2.7.egg/Adafruit_SSD1306/SSD1306.py", line 239, in init
gpio, spi, i2c_bus, i2c_address, i2c)
File "/usr/local/lib/python2.7/dist-packages/Adafruit_SSD1306-1.5.0-py2.7.egg/Adafruit_SSD1306/SSD1306.py", line 87, in init
self._gpio.setup(self._rst, GPIO.OUT)
File "/usr/local/lib/python2.7/dist-packages/Adafruit_GPIO-0.7-py2.7.egg/Adafruit_GPIO/GPIO.py", line 222, in setup
pull_up_down=self._pud_mapping[pull_up_down])
TypeError: argument 1 must be string, not int

using this display:
128x64 display with hardware I2C
and I did comment/uncommen the lines to set it up for 128x64

Can't have the display scroll text from right to left

I made a slight modification on your existing code trying to work with the pure SMBus. I got everything working fine for somehow I still couldn't manage to get my text scrolling from Right to Left
I've looked over the Arduino codes for this SSD1306 trying to see how you guys manage to do it but it wouldn't help much
I assume it's just as simple as sending a command to the register to activate Left/Right scrolling. Please correct me if I'm wrong.
Below is the modified code for my application


# Copyright (c) 2014 Adafruit Industries
# Author: Tony DiCola
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import time, smbus

# Constants
SSD1306_I2C_ADDRESS = 0x3C    # 011110+SA0+RW - 0x3C or 0x3D
SSD1306_SETCONTRAST = 0x81
SSD1306_DISPLAYALLON_RESUME = 0xA4
SSD1306_DISPLAYALLON = 0xA5
SSD1306_NORMALDISPLAY = 0xA6
SSD1306_INVERTDISPLAY = 0xA7
SSD1306_DISPLAYOFF = 0xAE
SSD1306_DISPLAYON = 0xAF
SSD1306_SETDISPLAYOFFSET = 0xD3
SSD1306_SETCOMPINS = 0xDA
SSD1306_SETVCOMDETECT = 0xDB
SSD1306_SETDISPLAYCLOCKDIV = 0xD5
SSD1306_SETPRECHARGE = 0xD9
SSD1306_SETMULTIPLEX = 0xA8
SSD1306_SETLOWCOLUMN = 0x00
SSD1306_SETHIGHCOLUMN = 0x10
SSD1306_SETSTARTLINE = 0x40
SSD1306_MEMORYMODE = 0x20
SSD1306_COLUMNADDR = 0x21
SSD1306_PAGEADDR = 0x22
SSD1306_COMSCANINC = 0xC0
SSD1306_COMSCANDEC = 0xC8
SSD1306_SEGREMAP = 0xA0
SSD1306_CHARGEPUMP = 0x8D
SSD1306_EXTERNALVCC = 0x1
SSD1306_SWITCHCAPVCC = 0x2

# Scrolling constants
SSD1306_ACTIVATE_SCROLL = 0x2F
SSD1306_DEACTIVATE_SCROLL = 0x2E
SSD1306_SET_VERTICAL_SCROLL_AREA = 0xA3
SSD1306_RIGHT_HORIZONTAL_SCROLL = 0x26
SSD1306_LEFT_HORIZONTAL_SCROLL = 0x27
SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL = 0x29
SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL = 0x2A


class SSD1306Base(object):
    """Base class for SSD1306-based OLED displays.  Implementors should subclass
    and provide an implementation for the _initialize function.
    """

    def __init__(self, width, height,address=SSD1306_I2C_ADDRESS):
        self._i2c = smbus.SMBus(1)
        self.address = address
        self.width = width
        self.height = height
        self._pages = height//8
        self._buffer = [0]*(width*self._pages)
        # Default to platform GPIO if not provided.

    def _initialize(self):
        raise NotImplementedError

    def command(self, c):
        """Send command byte to display."""
        control = 0x00   # Co = 0, DC = 0
        self._i2c.write_byte_data(self.address, control, c)

    def data(self, c):    
        # I2C write.
        control = 0x40   # Co = 0, DC = 0
        self._i2c.write_byte_data(self.address, control, c)

    def begin(self, vccstate=SSD1306_SWITCHCAPVCC):
        """Initialize display."""
        # Save vcc state.
        self._vccstate = vccstate
        # Reset and initialize display.
        self._initialize()
        # Turn on the display.
        self.command(SSD1306_DISPLAYON)

    def display(self):
        """Write display buffer to physical display."""
        self.command(SSD1306_COLUMNADDR)
        self.command(0)              # Column start address. (0 = reset)
        self.command(self.width-1)   # Column end address.
        self.command(SSD1306_PAGEADDR)
        self.command(0)              # Page start address. (0 = reset)
        self.command(self._pages-1)  # Page end address.
        # Write buffer data.   
        for i in range(0, len(self._buffer), 16):
            control = 0x40   # Co = 0, DC = 0
            self._i2c.write_i2c_block_data(self.address, control, self._buffer[i:i+16])

    def image(self, image):
        """Set buffer to value of Python Imaging Library image.  The image should
        be in 1 bit mode and a size equal to the display size.
        """
        if image.mode != '1':
            raise ValueError('Image must be in mode 1.')
        imwidth, imheight = image.size
        if imwidth != self.width or imheight != self.height:
            raise ValueError('Image must be same dimensions as display ({0}x{1}).' \
                .format(self.width, self.height))
        # Grab all the pixels from the image, faster than getpixel.
        pix = image.load()
        # Iterate through the memory pages
        index = 0
        for page in range(self._pages):
            # Iterate through all x axis columns.
            for x in range(self.width):
                # Set the bits for the column of pixels at the current position.
                bits = 0
                # Don't use range here as it's a bit slow
                for bit in [0, 1, 2, 3, 4, 5, 6, 7]:
                    bits = bits << 1
                    bits |= 0 if pix[(x, page*8+7-bit)] == 0 else 1
                # Update buffer byte and increment to next byte.
                self._buffer[index] = bits
                index += 1

    def clear(self):
        """Clear contents of image buffer."""
        self._buffer = [0]*(self.width*self._pages)

    def set_contrast(self, contrast):
        """Sets the contrast of the display.  Contrast should be a value between
        0 and 255."""
        if contrast < 0 or contrast > 255:
            raise ValueError('Contrast must be a value from 0 to 255 (inclusive).')
        self.command(SSD1306_SETCONTRAST)
        self.command(contrast)

    def dim(self, dim):
        """Adjusts contrast to dim the display if dim is True, otherwise sets the
        contrast to normal brightness if dim is False.
        """
        # Assume dim display.
        contrast = 0
        # Adjust contrast based on VCC if not dimming.
        if not dim:
            if self._vccstate == SSD1306_EXTERNALVCC:
                contrast = 0x9F
            else:
                contrast = 0xCF
    #~ def horScroll(self, direction):
        #~ try:
            #~ if direction.lower() == 'left':
                #~ self.command(SSD1306_LEFT_HORIZONTAL_SCROLL)
            #~ elif direction.lower()=='right':
                #~ self.command(SSD1306_RIGHT_HORIZONTAL_SCROLL)
        #~ except:
            #~ pass
    def scrollHorLeft(self):
        self.command(SSD1306_ACTIVATE_SCROLL)
        self.command(SSD1306_LEFT_HORIZONTAL_SCROLL)
        #~ self._i2c.write_i2c_block_data(self.address, SSD1306_LEFT_HORIZONTAL_SCROLL, self._buffer[i:i+16])
    def scrollHorRight(self):
        self.command(SSD1306_ACTIVATE_SCROLL)
        self.command(SSD1306_RIGHT_HORIZONTAL_SCROLL)
            

class SSD1306(SSD1306Base):
    def __init__(self, i2c_address=SSD1306_I2C_ADDRESS):
        # Call base class constructor.
        super(SSD1306, self).__init__(128, 64, i2c_address)

    def _initialize(self):
        # 128x64 pixel specific initialization.
        self.command(SSD1306_DISPLAYOFF)                    # 0xAE
        self.command(SSD1306_SETDISPLAYCLOCKDIV)            # 0xD5
        self.command(0x80)                                  # the suggested ratio 0x80
        self.command(SSD1306_SETMULTIPLEX)                  # 0xA8
        self.command(0x3F)
        self.command(SSD1306_SETDISPLAYOFFSET)              # 0xD3
        self.command(0x0)                                   # no offset
        self.command(SSD1306_SETSTARTLINE | 0x0)            # line #0
        self.command(SSD1306_CHARGEPUMP)                    # 0x8D
        if self._vccstate == SSD1306_EXTERNALVCC:
            self.command(0x10)
        else:
            self.command(0x14)
        self.command(SSD1306_MEMORYMODE)                    # 0x20
        self.command(0x00)                                  # 0x0 act like ks0108
        self.command(SSD1306_SEGREMAP | 0x1)
        self.command(SSD1306_COMSCANDEC)
        self.command(SSD1306_SETCOMPINS)                    # 0xDA
        self.command(0x12)
        self.command(SSD1306_SETCONTRAST)                   # 0x81
        if self._vccstate == SSD1306_EXTERNALVCC:
            self.command(0x9F)
        else:
            self.command(0xCF)
        self.command(SSD1306_SETPRECHARGE)                  # 0xd9
        if self._vccstate == SSD1306_EXTERNALVCC:
            self.command(0x22)
        else:
            self.command(0xF1)
        self.command(SSD1306_SETVCOMDETECT)                 # 0xDB
        self.command(0x40)
        self.command(SSD1306_DISPLAYALLON_RESUME)           # 0xA4
        self.command(SSD1306_NORMALDISPLAY)                 # 0xA6

banana pi TypeError: argument 1 must be string, not int (SSD1306)

python -V
Python 2.7.9

uname -a
Linux 4.4.8 #3 SMP Sun Apr 24 14:46:20 CEST 2016 armv7l GNU/Linux

sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

i2cdetect -l
i2c-0 i2c mv64xxx_i2c adapter I2C adapter
i2c-1 i2c mv64xxx_i2c adapter I2C adapter

gpio readall
+----------+-Rev3-+------+--------+------+-------+
| wiringPi | GPIO | Phys | Name | Mode | Value |
+----------+------+------+--------+------+-------+
| 0 | 17 | 11 | GPIO 0 | IN | Low |
| 1 | 18 | 12 | GPIO 1 | IN | Low |
| 2 | 27 | 13 | GPIO 2 | IN | Low |
| 3 | 22 | 15 | GPIO 3 | IN | Low |
| 4 | 23 | 16 | GPIO 4 | IN | Low |
| 5 | 24 | 18 | GPIO 5 | IN | Low |
| 6 | 25 | 22 | GPIO 6 | IN | Low |
| 7 | 4 | 7 | GPIO 7 | IN | Low |
| 8 | 2 | 3 | SDA | ALT5 | Low |
| 9 | 3 | 5 | SCL | ALT5 | Low |
| 10 | 8 | 24 | CE0 | ALT5 | Low |
| 11 | 7 | 26 | CE1 | ALT5 | Low |
| 12 | 10 | 19 | MOSI | ALT5 | Low |
| 13 | 9 | 21 | MISO | ALT5 | Low |
| 14 | 11 | 23 | SCLK | ALT5 | Low |
| 15 | 14 | 8 | TxD | ALT0 | Low |
| 16 | 15 | 10 | RxD | ALT0 | Low |
| 17 | 28 | 3 | GPIO 8 | IN | Low |
| 18 | 29 | 4 | GPIO 9 | ALT4 | Low |
| 19 | 30 | 5 | GPIO10 | OUT | High |
| 20 | 31 | 6 | GPIO11 | ALT4 | Low |
+----------+------+------+--------+------+-------+

sudo python shapes.py
Traceback (most recent call last):
File "shapes.py", line 52, in
disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, i2c_address=0x3C)
File "build/bdist.linux-armv7l/egg/Adafruit_SSD1306/SSD1306.py", line 240, in init
File "build/bdist.linux-armv7l/egg/Adafruit_SSD1306/SSD1306.py", line 88, in init
File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/GPIO.py", line 278, in setup
TypeError: argument 1 must be string, not int

/lcd/examples# sudo python shapes.py
Traceback (most recent call last):
File "shapes.py", line 52, in
disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, i2c_address=0x3C)
File "build/bdist.linux-armv7l/egg/Adafruit_SSD1306/SSD1306.py", line 240, in init
File "build/bdist.linux-armv7l/egg/Adafruit_SSD1306/SSD1306.py", line 88, in init
File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/GPIO.py", line 278, in setup
TypeError: argument 1 must be string, not int

Error running i2c example code on BeagleBone Black

Please see the trace below:

/usr/local/lib/python2.7/dist-packages/setuptools-3.5.1-py2.7.egg/pkg_resources.py:1031: UserWarning: /home/ubuntu/.python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
Traceback (most recent call last):
File "image.py", line 47, in
disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)
File "build/bdist.linux-armv7l/egg/Adafruit_SSD1306/SSD1306.py", line 239, in init
File "build/bdist.linux-armv7l/egg/Adafruit_SSD1306/SSD1306.py", line 105, in init
File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 64, in get_i2c_device
File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 75, in init
IOError: [Errno 2] No such file or directory

The above is having modified image.py appropriately for my display:

128x64 display with hardware I2C:

disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)

Beaglebone Black pin configuration:

RST = 'P9_12'

Note the following are only used with SPI:

DC = 'P9_15'
SPI_PORT = 1
SPI_DEVICE = 0

I hope this can help someone.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.