├── Montserrat-Light.ttf ├── Montserrat-Medium.ttf ├── Montserrat-Regular.ttf ├── Montserrat-Thin.ttf ├── README.md ├── fontawesome-webfont.ttf ├── howto.txt └── monitor.py /Montserrat-Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jumejume1/raspberry-oled-monitor/0711215b7ac967ca3a3b1ce2f1095aa63c9378f2/Montserrat-Light.ttf -------------------------------------------------------------------------------- /Montserrat-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jumejume1/raspberry-oled-monitor/0711215b7ac967ca3a3b1ce2f1095aa63c9378f2/Montserrat-Medium.ttf -------------------------------------------------------------------------------- /Montserrat-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jumejume1/raspberry-oled-monitor/0711215b7ac967ca3a3b1ce2f1095aa63c9378f2/Montserrat-Regular.ttf -------------------------------------------------------------------------------- /Montserrat-Thin.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jumejume1/raspberry-oled-monitor/0711215b7ac967ca3a3b1ce2f1095aa63c9378f2/Montserrat-Thin.ttf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # raspberry-oled-monitor 2 | Raspberry Tutorial 3 | How to use OLED i2c with Raspberry Pi Display system Monitor with icons from Font Awesome 4 | 5 | Check if the display device is connected 6 | sudo i2cdetect -y 1 7 | ---- 8 | Clone Adafruit Python SSD1306 library 9 | git clone https://github.com/adafruit/Adafruit_Python_SSD1306 10 | ---- 11 | Go to the cloned repository and execute 12 | sudo python setup.py install 13 | ---- 14 | 15 | after editing of this line don't forget to reboot your RPi 16 | ---- 17 | Run the script by 18 | python monitor.py 19 | -------------------------------------------------------------------------------- /fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jumejume1/raspberry-oled-monitor/0711215b7ac967ca3a3b1ce2f1095aa63c9378f2/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /howto.txt: -------------------------------------------------------------------------------- 1 | Check if the display device is connected 2 | sudo i2cdetect -y 1 3 | ---- 4 | Clone Adafruit Python SSD1306 library 5 | git clone https://github.com/adafruit/Adafruit_Python_SSD1306 6 | ---- 7 | Go to the cloned repository and execute 8 | sudo python setup.py install 9 | ---- 10 | 11 | after editing of this line don't forget to reboot your RPi 12 | ---- 13 | Run the script by 14 | python monitor.py 15 | 16 | 17 | -------------------------------------------------------------------------------- /monitor.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Adafruit Industries 2 | # Author: Tony DiCola & James DeVito 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | # THE SOFTWARE. 21 | import time 22 | 23 | import Adafruit_GPIO.SPI as SPI 24 | import Adafruit_SSD1306 25 | 26 | from PIL import Image 27 | from PIL import ImageDraw 28 | from PIL import ImageFont 29 | 30 | import subprocess 31 | 32 | # Raspberry Pi pin configuration: 33 | RST = None # on the PiOLED this pin isnt used 34 | # Note the following are only used with SPI: 35 | DC = 23 36 | SPI_PORT = 0 37 | SPI_DEVICE = 0 38 | 39 | # Beaglebone Black pin configuration: 40 | # RST = 'P9_12' 41 | # Note the following are only used with SPI: 42 | # DC = 'P9_15' 43 | # SPI_PORT = 1 44 | # SPI_DEVICE = 0 45 | 46 | # 128x32 display with hardware I2C: 47 | # disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST) 48 | 49 | # 128x64 display with hardware I2C: 50 | disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST) 51 | 52 | # Note you can change the I2C address by passing an i2c_address parameter like: 53 | # disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, i2c_address=0x3C) 54 | 55 | # Alternatively you can specify an explicit I2C bus number, for example 56 | # with the 128x32 display you would use: 57 | # disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, i2c_bus=2) 58 | 59 | # 128x32 display with hardware SPI: 60 | # disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000)) 61 | 62 | # 128x64 display with hardware SPI: 63 | # disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000)) 64 | 65 | # Alternatively you can specify a software SPI implementation by providing 66 | # digital GPIO pin numbers for all the required display pins. For example 67 | # on a Raspberry Pi with the 128x32 display you might use: 68 | # disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, dc=DC, sclk=18, din=25, cs=22) 69 | 70 | # Initialize library. 71 | disp.begin() 72 | 73 | # Clear display. 74 | disp.clear() 75 | disp.display() 76 | 77 | # Create blank image for drawing. 78 | # Make sure to create image with mode '1' for 1-bit color. 79 | width = disp.width 80 | height = disp.height 81 | image = Image.new('1', (width, height)) 82 | 83 | # Get drawing object to draw on image. 84 | draw = ImageDraw.Draw(image) 85 | 86 | # Draw a black filled box to clear the image. 87 | draw.rectangle((0,0,width,height), outline=0, fill=0) 88 | 89 | # Draw some shapes. 90 | # First define some constants to allow easy resizing of shapes. 91 | padding = -2 92 | top = padding 93 | bottom = height-padding 94 | # Move left to right keeping track of the current x position for drawing shapes. 95 | x = 0 96 | 97 | 98 | # Load default font. 99 | font = ImageFont.load_default() 100 | 101 | # Alternatively load a TTF font. Make sure the .ttf font file is in the same directory as the python script! 102 | # Some other nice fonts to try: http://www.dafont.com/bitmap.php 103 | font = ImageFont.truetype('Montserrat-Light.ttf', 12) 104 | font2 = ImageFont.truetype('fontawesome-webfont.ttf', 14) 105 | font_icon = ImageFont.truetype('fontawesome-webfont.ttf', 20) 106 | font_text_small = ImageFont.truetype('Montserrat-Medium.ttf', 8) 107 | 108 | while True: 109 | 110 | # Draw a black filled box to clear the image. 111 | draw.rectangle((0,0,width,height), outline=0, fill=0) 112 | 113 | # Shell scripts for system monitoring from here : https://unix.stackexchange.com/questions/119126/command-to-display-memory-usage-disk-usage-and-cpu-load 114 | cmd = "hostname -I | cut -d\' \' -f1 | head --bytes -1" 115 | IP = subprocess.check_output(cmd, shell = True ) 116 | 117 | cmd = "top -bn1 | grep load | awk '{printf \"CPU %.2f\", $(NF-2)}'" 118 | CPU = subprocess.check_output(cmd, shell = True ) 119 | 120 | cmd = "free -m | awk 'NR==2{printf \"%.2f%%\", $3*100/$2 }'" 121 | MemUsage = subprocess.check_output(cmd, shell = True ) 122 | 123 | cmd = "df -h | awk '$NF==\"/\"{printf \"HDD: %d/%dGB %s\", $3,$2,$5}'" 124 | cmd = "df -h | awk '$NF==\"/\"{printf \"%s\", $5}'" 125 | Disk = subprocess.check_output(cmd, shell = True ) 126 | 127 | cmd = "vcgencmd measure_temp | cut -d '=' -f 2 | head --bytes -1" 128 | Temperature = subprocess.check_output(cmd, shell = True ) 129 | 130 | # Icons 131 | # Icon temperator 132 | draw.text((x, top+5), unichr(62152), font=font_icon, fill=255) 133 | # Icon memory 134 | draw.text((x+60, top+5), unichr(62171), font=font_icon, fill=255) 135 | # Icon disk 136 | draw.text((x, top+30), unichr(61888), font=font2, fill=255) 137 | # Icon Wifi 138 | draw.text((x, top+52), unichr(61931), font=font2, fill=255) 139 | 140 | # Text temperatur 141 | draw.text((x+15, top+5), str(Temperature), font=font, fill=255) 142 | # Text mem usage 143 | draw.text((x+80, top+5), str(MemUsage), font=font, fill=255) 144 | # Text Disk usage 145 | draw.text((x+15, top+30), str(Disk), font=font, fill=255) 146 | # Text cpu usage 147 | draw.text((x+60, top+30), str(CPU), font=font, fill=255) 148 | 149 | # Text IP addresss 150 | draw.text((x+20, top+55), str(IP), font=font_text_small, fill=255) 151 | 152 | # Display image. 153 | disp.image(image) 154 | disp.display() 155 | time.sleep(5) 156 | 157 | 158 | --------------------------------------------------------------------------------