linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

SSD1306 OLED headless system monitor

Fri Jun 03, 2016 10:27 pm

oled.jpg
oled.jpg (60.61 KiB) Viewed 14565 times
hey folks... have been having a lot of fun down here on the Gulf of Mexico (today's WX: 92F 'feels like 110F')...

:twisted:

anyhoo, i recently scarfed one of those neato 128x64 OLEDs for about a Hamilton off the 'Net and thought it would make for a nice little system monitor on a headless RPi3 (they somehow seem to keep multiplying 'round these parts - dunno why)

it's one of those two-color jobbies that has a yellow area up top and the rest in blue... (too bad i couldn't figure out a way to make a blue LED work with the display)... what are these things, anyway? rejects from an old cell factory? there must be a gazillion of 'em out there! but i digress...

so i sat down this afternoon and crafted up a little Python (i'm a Python n00b, btw) to have the OLED do something useful... here are my pitiful results - i hope this can help someone out there ... it was an interesting diversion until it was '5 o'clock somewhere'...

but first I have to put out a big shout of 'thank you' to rm-hull for SSD1306 code... and of course, the many others who take the time to post examples of Python code to solve simple problems for us n00bs...

here's the code:

Code: Select all

#!/usr/bin/env python
# myssd.py version 0.6 - a simple system monitor for the Raspberry Pi
# adapted from rmhull's wonderful ssd1306 Python lib by bball@tux.org
# crafted for the dual-color 128x64 OLED w/yellow top area
# 060316 - added date
# added Raspberry Pi's CPU temperature in fahrenheit
# added wlan0 IP address
# added memory used
# added sd card usage
# 060416 - added splash screen
# general code cleanup
# added KB output for memory

import os
import psutil
from lib_oled96 import ssd1306
from time import sleep
from datetime import datetime
from PIL import ImageFont, ImageDraw, Image
#font = ImageFont.load_default()

from smbus import SMBus                  #  These are the only two variant lines !!
i2cbus = SMBus(1)                        #
oled = ssd1306(i2cbus)

draw = oled.canvas
# set font to 13 for yellow area
font = ImageFont.truetype('FreeSans.ttf', 13)

# show splash screen
draw.text((1, 1), 'RASPBIAN SYSMON', font=font, fill=1)
logo = Image.open('rpi.png')
draw.bitmap((42, 16), logo, fill=1)

oled.display()
sleep(3)
oled.cls()

while True:

 # "draw" onto this canvas, then call display() to send the canvas contents to the hardware.
 draw = oled.canvas

 # set font to 13 for yellow area
 font = ImageFont.truetype('FreeSans.ttf', 13)

 # get, display date and time
 draw.text((1, 1), str(datetime.now().strftime('%a  %b  %d  %H:%M:%S')), font=font, fill=1)

 # reset font for four smaller lines
 font = ImageFont.truetype('FreeSans.ttf', 10)

 # get, return CPU's current temperature
 def cpu_temp():
    tempF = (((int(open('/sys/class/thermal/thermal_zone0/temp').read()) / 1000)*9/5)+32)
    return "CPU TEMP: %sF" % str(tempF)

  # display CPU temp
 draw.text((1, 15),    cpu_temp(),  font=font, fill=1)

 # get, return wlan0's current IP address
 def wlan_ip():
    f = os.popen('ifconfig wlan0 | grep "inet\ addr" | cut -c 21-33')
    ip = str(f.read())
    # strip out trailing chars for cleaner output
    return "WIFI IP: %s" % ip.rstrip('\r\n')

 # display the IP address
 draw.text((1, 28),    wlan_ip(),  font=font, fill=1)

 # get amount of memory in use
 def mem_usage():
    usage = psutil.virtual_memory()
    return "MEM IN USE:  %s KB" % (int(str(usage.used)) / 1024)

 # display amount of free memory
 draw.text((1, 41),    mem_usage(),  font=font, fill=1)

 # get disk usage
 def disk_usage(dir):
    usage = psutil.disk_usage(dir)
    return "SD CARD IN USE: %.0f%%" % (usage.percent)

 # display disk usage
 draw.text((1, 53), disk_usage('/'),  font=font, fill=1)
 oled.display()

 sleep(10)
 oled.cls()      # Oled still on, but screen contents now blacked out
you will need to install PILLOW (from what i've read, a most friendly version of the Python Imaging Library (PIL)), along with Python's psutil - and also download lib_oled96 (github is your friend)

of course, TTIWWP (this thread is worthless without pics), so i've put up a pic of my little display... it will go nicely with my new camera-enabled Pi Zero...

regards,

willie
on the stinkin' hot Gulf of Mexico

eltito51
Posts: 1
Joined: Tue Jun 28, 2016 11:18 pm

Re: SSD1306 OLED headless system monitor

Tue Jun 28, 2016 11:22 pm

Willie:

Fantastic your screen. I bought a similar one and waiting to receive it and play with you code. I do live in sweeting Houston so we are close to the gulf. As a Question for you:

Have you ever try to run this phyton code in Kodi?

I a, attempting to use this display in a Kodi player to have easy visibility of system information and specially IP address.

Cheers

linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Re: SSD1306 OLED headless system monitor

Wed Jun 29, 2016 12:13 am

nope, have not tried this on a Kodi system (our OpenELEC/Kodi system is mounted behind our TV in the front room, and we use a Logitech K400 Plus keyboard to control the screen)...

i bought the little OLED to learn a bit about Python and for a little system monitor for one of my Raspberry Pi Zeros... my next effort will be to get the display working on my new Beaglebone Green Wireless!

have fun with the display... i'm a Python n00b, so i haven't gone into scrolling, etc.... but i have run across some code that does auto-line wrapping for long character strings - which would be handy for a bit more info...

i've also updated the code posted here to include a secondary screen that shows current weather conditions (kinda important here in hurricane country!) ... here's the snippet:

Code: Select all

# get, return wlan0's current WX
 def do_wx():
    f = os.popen('/usr/local/bin/currentwx')
    wx = str(f.read())
    # strip out trailing chars for cleaner output
    return "%s" % wx.rstrip('\r\n')

 font = ImageFont.truetype('FreeSans.ttf', 13)
 draw.text((1, 1),    'CURRENT WEATHER:',  font=font, fill=1)


 # display the WX
 font = ImageFont.truetype('FreeSans.ttf', 12)
 draw.text((1, 15),    'PINELLAS PARK',  font=font, fill=1)
 draw.text((1, 41),    do_wx(),  font=font, fill=1)
 oled.display()

 sleep(10)
the code calls a shell script named 'currentwx,' which in turn, calls another script 'dowx,' which sends a zip code to accuweather (which then in turn returns a one-liner of the current weather conditions)... it's a shame that the NOAA and the NWS no longer support their FTP servers, which offered nice forecasts easily in text form, and used to be easily retrievable - more 'transparency' in govt? LOL!)

regards,

willie on the hot and humid Gulf of Mexico

linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Re: SSD1306 OLED headless system monitor

Fri Jul 15, 2016 6:43 pm

oledwifi.jpg
oledwifi.jpg (36.84 KiB) Viewed 14161 times
hey folks... just a quick update on the system monitor code... i added wifi signal connection reporting (hope it helps someone orient a RPi for best AP reception):



here's the snippet i used (thanks to another online poster):

Code: Select all

# LARGE display - get wifi wlan0 signal strength
 def get_wifi():
    cmd = "iwconfig wlan0 | grep Signal | /usr/bin/awk '{print $4}' | /usr/bin/cut -d'=' -f2"
    strDbm = os.popen(cmd).read()
    dbm = int(strDbm)
    quality = 2 * (dbm + 100)
    if strDbm:
     return("{0} dbm = {1}%".format(dbm, quality))
    else: 
     return("No Wifi Signal")

 font = ImageFont.truetype('/home/debian/Downloads/FreeSans.ttf', 17)
 draw.text((1, 1), 'WIFI SIGNAL', font=font, fill=1)
 font = ImageFont.truetype('/home/debian/Downloads/FreeSans.ttf', 15)
 draw.text((1, 30),    get_wifi(),  font=font, fill=1)

 oled.display()
 sleep(3)
 oled.cls()
enjoy!

willie
on the 94F Gulf of Mexico

ballen
Posts: 20
Joined: Fri Aug 05, 2016 6:35 pm

Re: SSD1306 OLED headless system monitor

Fri Aug 05, 2016 6:53 pm

willie,

Billy here also from the Gulf - it's pleasure to find another old salt with similar interests. After searching the web and finding this thread, I've determined you must be my brother from another mother!

I was looking for exactly what you have created.

First off, I'm a complete n00b. Old school IT, but I'm from the MS camp... Got interested in the Pi (about a month in) and just getting my feet wet. Intent is to learn programming and small electronics... All this is completely new to me.

I've gotten the BME280 and the ssd1306 working prior to finding your project. Wired properly and the samples run for both. However, after three late nights, I'm still unable to get your code to work.

If I start from scratch and document my steps could you take a look for my prosperity and hopefully others out there?

Thank you in advance!

linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Re: SSD1306 OLED headless system monitor

Fri Aug 05, 2016 10:05 pm

sure! be happy to help... i have an RPi3 and a Beaglebone Green Wireless set up for the SSD1306 OLED...

you'll need to make sure to install the requisite libraries and have the fonts on hand... i keep everything in a single directory...

willie
on the hot and humid Gulf of Mexico

ballen
Posts: 20
Joined: Fri Aug 05, 2016 6:35 pm

Re: SSD1306 OLED headless system monitor

Fri Aug 05, 2016 10:32 pm

RPi3 and Jessie on my side

I think I have all the needed libraries... I'll sit down and document as I go through. As mentioned - n00b but I've been a technical writer for years.

ballen
Posts: 20
Joined: Fri Aug 05, 2016 6:35 pm

Re: SSD1306 OLED headless system monitor

Sat Aug 06, 2016 5:06 am

Got it working, didn't have everything in the same folder.

I had seemingly done everything else correct. A few modifications to your lovely script and all is well. Already added in the Wifi Signal snippet. I have the white monochrome version, so I'm presently modifying the script to encompass the lack of the 2 pixel gap from the yellow to the blue. Once I get an idea how to get that going and layout, I will probably implementing your weather script (Hurricane Alley!) and then look into adding sensor input from the BME280. Exciting stuff!

Thank you very much for your assistance, you have most definitely helped! I'll provide my code here as it comes along.

linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Re: SSD1306 OLED headless system monitor

Sat Aug 06, 2016 11:10 am

IMG_0630.jpg
IMG_0630.jpg (34.23 KiB) Viewed 13839 times
very good! and here's another snippet with text wrap! this means you can output the display of Linux commands and are not limited to small, clipped fragments (obviously there's a limit, but if you make the text smaller...)

:-)

this snippet contains everything you need to display the output of the uptime command:

Code: Select all

 # LARGE display - uptime
 def get_uptime():
    uptime = os.popen("uptime")
    ut = str(uptime.read())
    # strip out trailing chars for cleaner output
    return "%s" % ut.rstrip('\r\n')

 font = ImageFont.truetype('/home/pi/Downloads/ssd1306-master/FreeSans.ttf', 17)
 draw.text((1, 1),    '    UPTIME',  font=font, fill=1)

 # now smaller font needed and wrap text to show info
 font = ImageFont.truetype('/home/pi/Downloads/ssd1306-master/FreeSans.ttf', 11)
 import textwrap
 lines = textwrap.wrap(get_uptime(), width=25)
 # what 'line' to start info
 y_text = 20
 w = 1 # we'll always start at left side of OLED
 for line in lines:
    width, height = font.getsize(line)
    draw.text((w, y_text), line, font=font, fill=1)
    y_text += height

 oled.display()
 sleep(4)
 oled.cls()
enjoy!

willie
on the Porcupine Party Gulf of Mexico
Last edited by linux_author on Sat Aug 06, 2016 3:01 pm, edited 1 time in total.

linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Re: SSD1306 OLED headless system monitor

Sat Aug 06, 2016 2:59 pm

IMG_0632.jpg
IMG_0632.jpg (34.08 KiB) Viewed 13839 times
and here's a shortie that displays your RPi's serial #:

Code: Select all

# LARGE display - get, display serial number
 def get_serial():
    cmd = "cat /proc/cpuinfo | grep Serial | /usr/bin/awk '{print $3}'"
    strDbm = os.popen(cmd).read()
    snum = str(strDbm)
    return "%s" % snum.rstrip('\r\n')

 font = ImageFont.truetype('/home/pi/Downloads/ssd1306-master/FreeSans.ttf', 17)
 draw.text((1, 1), 'Serial Number', font=font, fill=1)
 font = ImageFont.truetype('/home/pi/Downloads/ssd1306-master/FreeSans.ttf', 14)
 draw.text((1, 30),    get_serial(),  font=font, fill=1)

 oled.display()
 sleep(3)
 oled.cls()
enjoy!

willie
on the stormy Gulf of Mexico

ballen
Posts: 20
Joined: Fri Aug 05, 2016 6:35 pm

Re: SSD1306 OLED headless system monitor

Sat Aug 06, 2016 9:56 pm

Here is what I have come up with:

Code: Select all

#!/usr/bin/env python
# myssd.py version 0.6 - a simple system monitor for the Raspberry Pi
# adapted from rmhull's wonderful ssd1306 Python lib by bball@tux.org
# crafted for the dual-color 128x64 OLED w/yellow top area
# 060316 - added date
# added Raspberry Pi's CPU temperature in fahrenheit
# added wlan0 IP address
# added memory used
# added sd card usage
# 060416 - added splash screen
# general code cleanup
# added KB output for memory

import os
import psutil
from lib_oled96 import ssd1306
from time import sleep
from datetime import datetime
from PIL import ImageFont, ImageDraw, Image
#font = ImageFont.load_default()

from smbus import SMBus                  #  These are the only two variant lines !!
i2cbus = SMBus(1)                        #
oled = ssd1306(i2cbus)

#draw = oled.canvas
# set font to 13 for yellow area
# font = ImageFont.truetype('FreeSans.ttf', 13)

# show splash screen
# draw.text((1, 1), 'RASPBIAN SYSMON', font=font, fill=1)
#logo = Image.open('pi_logo.png')
#draw.bitmap((1, 1), logo, fill=1)

#oled.display()
#sleep(3)
#oled.cls()

while True:

 # "draw" onto this canvas, then call display() to send the canvas contents to the hardware.
 draw = oled.canvas

 logo = Image.open('pi_logo.png')
 draw.bitmap((1, 1), logo, fill=1)

 oled.display()
 sleep(20)
 oled.cls()


 # set font to 13 for yellow area
 font = ImageFont.truetype('FreeSans.ttf', 13)

 # get, display date and time
 draw.text((1, 26), str(datetime.now().strftime('%a  %b  %d  %H:%M:%S')), font=font, fill=1)

 oled.display()
 sleep(5)
 oled.cls()

 # reset font for four smaller lines
 font = ImageFont.truetype('FreeSans.ttf', 16)

 # get, return CPU's current temperature
 def cpu_temp():
    tempF = (((int(open('/sys/class/thermal/thermal_zone0/temp').read()) / 1000)*9/5)+32)
    return "CPU Temp: %sF" % str(tempF)

  # display CPU temp
 draw.text((1, 26),    cpu_temp(),  font=font, fill=1)

 oled.display()
 sleep(5)
 oled.cls()

 font = ImageFont.truetype('FreeSans.ttf', 12)

 # get, return wlan0's current IP address
 #def wlan_ip():
 #   f = os.popen('ifconfig wlan0 | grep "inet\ addr" | cut -c 21-33')
 #   ip = str(f.read())
 #   # strip out trailing chars for cleaner output
 #   return "WIFI IP: %s" % ip.rstrip('\r\n')

# font = ImageFont.truetype('FreeSans.ttf', 10)

 # display the IP address
# draw.text((1, 28),    wlan_ip(),  font=font, fill=1)

 # get amount of memory in use
 def mem_usage():
    usage = psutil.virtual_memory()
    return "RAM used:  %s KB" % (int(str(usage.used)) / 1024)

 # display amount of free memory
 draw.text((1, 16),    mem_usage(),  font=font, fill=1)

 # get disk usage
 def disk_usage(dir):
    usage = psutil.disk_usage(dir)
    return "Storage used: %.0f%%" % (usage.percent)

 # display disk usage
 draw.text((14, 40), disk_usage('/'),  font=font, fill=1)
 oled.display()

 sleep(5)
 oled.cls()      # Oled still on, but screen contents now blacked out

# LARGE display - get wifi wlan0 signal strength
 def get_wifi():
    cmd = "iwconfig wlan0 | grep Signal | /usr/bin/awk '{print $4}' | /usr/bin/cut -d'=' -f2"
    strDbm = os.popen(cmd).read()
    dbm = int(strDbm)
    quality = 2 * (dbm + 100)
    if strDbm:
     return("{0} dbm = {1}%".format(dbm, quality))
    else: 
     return("No Wifi Signal")

 font = ImageFont.truetype('FreeSans.ttf', 17)
 draw.text((17, 1), 'WIFI Signal', font=font, fill=1)
 font = ImageFont.truetype('FreeSans.ttf', 15)
 draw.text((11, 19),    get_wifi(),  font=font, fill=1)

 font = ImageFont.truetype('FreeSans.ttf', 13)

 # get, return wlan0's current IP address
 def wlan_ip():
    f = os.popen('ifconfig wlan0 | grep "inet\ addr" | cut -c 21-33')
    ip = str(f.read())
    # strip out trailing chars for cleaner output
    return "WIFI IP: %s" % ip.rstrip('\r\n')

 # display the IP address
 draw.text((3, 51),    wlan_ip(),  font=font, fill=1)


 oled.display()
 sleep(5)
 oled.cls()

# LARGE display - uptime
 def get_uptime():
    uptime = os.popen("uptime")
    ut = str(uptime.read())
    # strip out trailing chars for cleaner output
    return "%s" % ut.rstrip('\r\n')

 font = ImageFont.truetype('FreeSans.ttf', 17)
 draw.text((27, 1),    'UPTIME',  font=font, fill=1)

 # now smaller font needed and wrap text to show info
 font = ImageFont.truetype('FreeSans.ttf', 13)
 import textwrap
 lines = textwrap.wrap(get_uptime(), width=25)
 # what 'line' to start info
 y_text = 21
 w = 1 # we'll always start at left side of OLED
 for line in lines:
    width, height = font.getsize(line)
    draw.text((w, y_text), line, font=font, fill=1)
    y_text += height

 oled.display()
 sleep(5)
 oled.cls()
Attachments
20160806_184456.jpg
20160806_184456.jpg (32.9 KiB) Viewed 13681 times
20160806_184508.jpg
20160806_184508.jpg (31.64 KiB) Viewed 13683 times
pi_logo.png
pi_logo.png (496 Bytes) Viewed 13752 times
Last edited by ballen on Sat Aug 06, 2016 10:59 pm, edited 3 times in total.

ballen
Posts: 20
Joined: Fri Aug 05, 2016 6:35 pm

Re: SSD1306 OLED headless system monitor

Sat Aug 06, 2016 10:04 pm

Any pointers for using/setting up your weather script before I start down that route willie?

Good stuff and many thanks!

linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Re: SSD1306 OLED headless system monitor

Sun Aug 07, 2016 12:23 am

looks great! here's the wx.sh script i use to get the weather returned... i call it with my zipcode... the script is shamelessly lifted from somewhere (can't remember where); i put it in /usr/local/bin as an executable:

Code: Select all

# !/usr/bin/bash
METRIC=0 #Should be 0 or 1; 0 for F, 1 for C
if [ -z $1 ]; then
    echo "USAGE: weather.sh <locationcode>"
    exit 0;
fi

wget -q http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=$1 -O - | awk \
'/Currently:/ {CurWeather=$0}
/[0-9] Forecast<\/title>/ {nr=NR+5}
NR==nr    {postIndx[++x]=$0}
# x>2    {exit}
END{
    split(CurWeather,tmp,"Currently: ")
    split(tmp[2],tmp1,"<")
    CurWeather=sprintf("%s",tmp1[1])
    sub(":",",",CurWeather)
    for(x in postIndx){
    split(postIndx[x],tmp,";|&")
    split(tmp[1],tmp,">")
    split(tmp[2],statement," C ") # substitute C for F if metric differs
    split(tmp[2],temp)
    forecast[++y]=sprintf("%d-%dC %-15s",temp[5],temp[2],statement[3])
    }
    printf("%s\n",CurWeather)
}'
hope this helps! btw, it would probably be a good thing (and courteous) to not ding the accuweather folks once every 10 seconds for the forecast - perhaps put a counter in your Python script in to only update the weather on your OLED once every 10 or 15 minutes? just a thought...

willie
on the practice-courteous-computing Gulf of Mexico

ballen
Posts: 20
Joined: Fri Aug 05, 2016 6:35 pm

Re: SSD1306 OLED headless system monitor

Sun Aug 07, 2016 4:22 pm

I have got the OLED script presently setup so I can see everything in a few minutes... For editing reasons. Ultimately, once everything is in place and working most of the time the OLED will be displaying the Pi logo (kind of a case badge) with a slower roll for the info screens.

Even here in FL, the weather really does not need updates beyond a 15 minute interval.

I am with you on not overusing a resource!

Down the line your weather would probably be replaced with or supplemented by (most likely for comparison) sensor data from the BME280 when I can figure out how to get it to output to the OLED. The BME280 example script uses "print" and I'm not sure how to translate that over into something usable for the OLED. I need to dig around.

Again, thanks for everything willie! It's because of you and those like you that there is community surrounding the PI. Glad to be joining in and hopefully upping my game to contribute!

linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Re: SSD1306 OLED headless system monitor

Mon Aug 08, 2016 7:08 pm

IMG_0650.jpg
IMG_0650.jpg (57.63 KiB) Viewed 12994 times
hey there... just thought i might help out with an idea... most of the hard work in this snippet on retrieving and interpreting the BME280 sensor data was done by Matt Hawkins @ http://www.raspberrypi-spy.co.uk/

it's a due credit to him that it took 5 times as long to solder together an i2C 'Y' cable for the sensor and my oled... all i had to do was import a single function from his example program, 'bme280.py,' and i got this:

Code: Select all

# read bme280 data
 def get_temp():
  from bme280 import readBME280All

  temperature,pressure,humidity = readBME280All()

  return "%sF" % str(((temperature)*9/5)+32)

 def get_pressure():
  from bme280 import readBME280All

  temperature,pressure,humidity = readBME280All()

  return "%s hPa" % str(pressure)

 def get_humidity():
  from bme280 import readBME280All

  temperature,pressure,humidity = readBME280All()

  return "%s percent" % str(humidity)

 font = ImageFont.truetype('/home/pi/Downloads/ssd1306-master/FreeSans.ttf', 13)
 draw.text((1, 1), 'Ambient Conditions', font=font, fill=1)

 font = ImageFont.truetype('/home/pi/Downloads/ssd1306-master/FreeSans.ttf', 11)
 draw.text((1, 20),  get_temp(),  font=font, fill=1)
 draw.text((1, 35),  get_pressure(),  font=font, fill=1)
 draw.text((1, 50),  get_humidity(),  font=font, fill=1)

 oled.display()
 sleep(5)
 oled.cls()
i know, i know, it's ugly because i'm still learning Python and how do tuples... but it works as a quick hack. i suppose i should also translate/convert the hectopascal reading to inch of mercury by dividing by 33.8638866667 - perhaps even convert the output to dial guages?

EDIT: i played around with formatting and think these lines have better output for me:

for the temp:

Code: Select all

return "%.2f degrees F" % (((temperature)*9/5)+32)
for barometric pressure:

Code: Select all

return "%.2f inches mercury" % ((pressure)/33.8638866667)
and humidty (the '%' escape was neat to learn!):

Code: Select all

return "%.2f%% humidity" % humidity
hope this helps!

willie
on the Python-n00b Gulf of Mexico
Last edited by linux_author on Sun Aug 14, 2016 4:48 pm, edited 3 times in total.

ballen
Posts: 20
Joined: Fri Aug 05, 2016 6:35 pm

Re: SSD1306 OLED headless system monitor

Mon Aug 08, 2016 7:16 pm

Fantastic! Could not find that when doing my searches... I will attempt to implement it into my roll tonight. Thank you!

ballen
Posts: 20
Joined: Fri Aug 05, 2016 6:35 pm

Re: SSD1306 OLED headless system monitor

Wed Aug 10, 2016 7:04 pm

willie, your code for the BME280 (and subsequent updates) worked wonderfully. I'm cleaning up the output in my script an will post with photos soon. Thank you!

AJB2K3
Posts: 215
Joined: Sun Aug 11, 2013 3:25 pm

Re: SSD1306 OLED headless system monitor

Fri Aug 12, 2016 6:48 pm

Silly question, how did you connect this to the raspberry pi?
Back in the old days, we were smarter then the technology.
Nowadays technology makes us look like villages fools in front of the children!

linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Re: SSD1306 OLED headless system monitor

Fri Aug 12, 2016 7:25 pm

IMG_0639.jpg
IMG_0639.jpg (30.04 KiB) Viewed 13035 times
AJB2K3 wrote:Silly question, how did you connect this to the raspberry pi?
not a silly question at all... the beauty of the i2C devices is their simplicity - only four wires: 3.3V, GND, SDA, and SCL...

these correspond to pins 1,9,3,5 ... the i2c devices can, if there's no address conflict, all co-exist and run on one connection (i built a little 'Y' harness to tie all the lines to the proper GPIO pins...)

another approach i used is to tie four pins in parallel in a 16-pin matrix - one cable feeds to i2c signals, and i can attach three devices - very inexpensive

this means that the display and sensor are running at the same time!

hope this helps!

willie
on the heavily raining Gulf of Mexico

ballen
Posts: 20
Joined: Fri Aug 05, 2016 6:35 pm

Re: SSD1306 OLED headless system monitor

Wed Aug 17, 2016 4:45 am

AJB2K3 wrote:Silly question, how did you connect this to the raspberry pi?
Initially when testing, I used a breadboard and jumper wire.

When I was happy with everything, I soldered up a Y-cable like wille. I've since managed to cram it all inside the case with the assistance of some heavy duty double sided tape.
Attachments
nflsh.jpg
nflsh.jpg (21.16 KiB) Viewed 12916 times
flsh.jpg
flsh.jpg (34.76 KiB) Viewed 12918 times

AJB2K3
Posts: 215
Joined: Sun Aug 11, 2013 3:25 pm

Re: SSD1306 OLED headless system monitor

Sat Aug 20, 2016 7:19 am

ballen wrote:
AJB2K3 wrote:Silly question, how did you connect this to the raspberry pi?
Initially when testing, I used a breadboard and jumper wire.

When I was happy with everything, I soldered up a Y-cable like wille. I've since managed to cram it all inside the case with the assistance of some heavy duty double sided tape.
I can't make out much from your images as they are too dark.

Open up GIMP, duplicate the layer, desaturate and invert the colours of the layer, set layermode to softlight, merge layers and resave to equalise the brighness and make the images more clearer.
Back in the old days, we were smarter then the technology.
Nowadays technology makes us look like villages fools in front of the children!

ballen
Posts: 20
Joined: Fri Aug 05, 2016 6:35 pm

Re: SSD1306 OLED headless system monitor

Sat Aug 20, 2016 9:48 pm

Here's what I think you need: First take a look at image1. This is a map of the Raspberry PI GPIO I pulled from Google Images.

Note the locations of 3.3v, SDA, SCL and GND. Those four pins match those on the ssd1306 and BM280 (and pretty much any other I2C device I've found). You'll want to somehow wire those pins to the OLED and sensor.

There are a couple of ways I use to go about this. First is the breadboard in image2. Many different ways to do this on a breadboard, this is how mine is presently set up.

When I get that the way I like it, I solder y-cables like that in image3.

Hope this helps.

Sorry I didn't fix the previous pics, You wouldn't have been able to see the important bits because of the fan in that case blocks the view.
Attachments
image1.jpg
image1.jpg (50.36 KiB) Viewed 12750 times
image2.jpg
image2.jpg (43.12 KiB) Viewed 12750 times
image3.jpg
image3.jpg (43.73 KiB) Viewed 12750 times

linux_author
Posts: 248
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Re: SSD1306 OLED headless system monitor

Sun Aug 21, 2016 9:10 pm

and here's my weekend project:
IMG_0691.jpg
IMG_0691.jpg (59.52 KiB) Viewed 12243 times
LATEST UPDATE: a replacement BMP180 sensor in use outside has been running for nearly a week with no problems; and thanks to a fellow RPi user, my little in-home monitor now has a nice little 3D printed case!

the monitor pulls in data from an RPi3 running a lighttpd server and a BMP180 logging script... the monitor displays the date, time, then combines data from a BME280 and the BMP180 to show temperature inside and out, along with barometric pressure and humidity

i'm still going to run tests on the sensors - but that's for another thread...

SECOND UPDATE: a second bme280 installed lasted less than 48 hours; i think i may have a bad batch of bme280s?

UPDATE: a bme280 i had installed outside today lasted only four hours before failure and demise... i had set the sensor for queries on one-minute intervals with logging to a lightthpd lan server... fortunately i had a spare bmp180 to throw out for testing... the bme280 installed in the little box is still working after 48 hours... i do not know if 93F temps and 60% humidity had anything to do with the bme280 failure (it was not installed in direct sunlight, but on a shaded, protected side of the house)

a wireless ambient condition monitor for the home... using an RPi Zero (yep, i got one by mail order), SSD1306 .96" OLED, microusb adapter, cheap nubby Edimax wifi adapter (i have two cheaper ones, $3 MT7601s, on order), BME280 sensor, $0.67 and $0.68 junction cover and box from the local home improvement store (makes a great case and there are inexpensive heavy-duty waterproof ones that can easily hold an RPi 3 for about $7!!), some scrap Lexan (can't see it, but i hot-glued the display onto the Lexan), a cheap 4GB Sandisk, microsdhc,
and a 'Y' cable w/GPIO female headers

having a lot of fun down here in hurricane country!

willie
on the 'grill in the morning it's too hot in the afternoon' Gulf of Mexico
Last edited by linux_author on Sun Sep 04, 2016 8:58 pm, edited 4 times in total.

ballen
Posts: 20
Joined: Fri Aug 05, 2016 6:35 pm

Re: SSD1306 OLED headless system monitor

Mon Aug 22, 2016 12:07 am

Very nice!

I also snapped up a Pi Zero for $5. I plan on ordering another before they dry up again.

ballen
Posts: 20
Joined: Fri Aug 05, 2016 6:35 pm

Re: SSD1306 OLED headless system monitor

Thu Sep 15, 2016 2:15 am

Displays CPU load if you use my code or Willie's:

Code: Select all

 font = ImageFont.truetype('/home/pi/lib_oled96/FreeSans.ttf', 14)
 draw.text((26, 18), 'CPU Load', font=font, fill=1)

 # get CPU load
 def cpu_usage():
    usage = psutil.cpu_percent(interval=1, percpu=False)
    return "%.0f%%" % (usage)
 font = ImageFont.truetype('/home/pi/lib_oled96/FreeSans.ttf', 24)
 # display CPU load
 draw.text((40, 36),    cpu_usage(),  font=font, fill=1)

 oled.display()
 sleep(8)
 oled.cls()
Compared to the monitor built into Raspbian, it seems fairly accurate.

Return to “General discussion”