adafruit / Adafruit_Python_SSD1306

Python library to use SSD1306-based 128x64 or 128x32 pixel OLED displays with a Raspberry Pi or Beaglebone Black.
MIT License
542 stars 283 forks source link

pip library not updated to latest #17

Closed zaforic closed 4 years ago

zaforic commented 6 years ago

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)

steverweber commented 6 years ago

also hit this issue... thanks for reporting it or I would still be stuck. after replacing /usr/local/lib/python3.5/dist-packages/Adafruit_SSD1306/SSD1306.py with the git version i was up and running.

curl https://raw.githubusercontent.com/adafruit/Adafruit_Python_SSD1306/master/Adafruit_SSD1306/SSD1306.py > /usr/local/lib/python3.5/dist-packages/Adafruit_SSD1306/SSD1306.py

Please update your pip package so your users have a clean experience!

ladyada commented 4 years ago

hiya, this library is being deprecated - we have a similar library that works with Python3 and modern linux computers. please check out this guide for more info https://learn.adafruit.com/monochrome-oled-breakouts/python-wiring