Difference between revisions of "BakeBit - OLED 128x64"

From FriendlyELEC WiKi
Jump to: navigation, search
(Created page with "查看中文")
 
(Source Code)
 
(9 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
[[BakeBit - OLED 128x64/zh|查看中文]]
 
[[BakeBit - OLED 128x64/zh|查看中文]]
 +
 +
==Introduction==
 +
[[File:BakeBit - OLED.jpg|thumb|OLED]]
 +
* The BakeBit - OLED is a monochromatic OLED module. The OLED is 0.96" and its resoltuion is 128 x 64. Its interface is I2C.
 +
* Users can set the I2C's address to either 0X3C or 0X3D and place two OLED modules on one I2C bus.
 +
 +
==Hardware Spec==
 +
* Standard 2.0mm pitch 4-Pin BakeBit I2C Interface
 +
* Resolution: 128 x 64
 +
* Color: blue
 +
* I2C's address configurable
 +
* PCB dimension(mm): 24 x 42
 +
[[File:BakeBit - OLED_Top_PCB.png | frameless|400px|BakeBit - OLED_Top]]
 +
[[File:BakeBit - OLED_Bottom_PCB.png | frameless|359px|BakeBit - OLED_Bottom]]
 +
 +
* Pin Description:
 +
{| class="wikitable"
 +
|-
 +
|Pin || Description
 +
|-
 +
|GND  || Ground
 +
|-
 +
|5V    || 5V Supply Voltage
 +
|-
 +
|SDA    || I2C-SDA
 +
|-
 +
|SCL  || I2C-SCL
 +
|}
 +
 +
== Code Sample(1): Display System Info  ==
 +
 +
When you run this code sample the system’s information will be listed on the OLED.
 +
 +
=== Hardware Setup ===
 +
Connect the OLED module to the NanoHat Hub's I2C interface:
 +
 +
::{| class="wikitable"
 +
|-
 +
|[[File:OLED-1.jpg |frameless|300px]]    || [[File:OLED-2.jpg |frameless|300px]]
 +
|-
 +
|}
 +
 +
=== Source Code ===
 +
 +
<syntaxhighlight lang="python">
 +
import time
 +
import bakebit
 +
import os
 +
import psutil
 +
from math import log
 +
import multiprocessing
 +
import platform
 +
import socket
 +
import bakebit_128_64_oled as oled
 +
 +
oled.init()                  #initialze SEEED OLED display
 +
oled.clearDisplay()          #clear the screen and set start position to top left corner
 +
oled.setNormalDisplay()      #Set display to normal mode (i.e non-inverse mode)
 +
oled.setPageMode()          #Set addressing mode to Page Mode
 +
 +
byteunits = ('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB')
 +
def filesizeformat(value):
 +
    exponent = int(log(value, 1024))
 +
    return "%.1f %s" % (float(value) / pow(1024, exponent), byteunits[exponent])
 +
 +
memUsage = psutil.phymem_usage()
 +
diskUsage = psutil.disk_usage('/')
 +
 +
oled.setTextXY(0,0)
 +
oled.putString("%s" % socket.gethostbyname(socket.gethostname()))
 +
 +
oled.setTextXY(0,1)
 +
oled.putString("Mem:%s" % filesizeformat(memUsage.total))
 +
 +
oled.setTextXY(0,2)
 +
oled.putString("Usage:%d%%" % memUsage.percent)
 +
 +
oled.setTextXY(0,3)
 +
oled.putString("Disk:%s" % filesizeformat(diskUsage.total))
 +
 +
oled.setTextXY(0,4)
 +
oled.putString("Usage:%d%%" % diskUsage.percent)
 +
 +
oled.setTextXY(0,5)
 +
oled.putString("CPU:%s" % platform.processor())
 +
 +
oled.setTextXY(0,6)
 +
oled.putString("Cores:%d" % multiprocessing.cpu_count())
 +
 +
with open("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq") as f:
 +
freq = int(f.readlines()[0])/1000
 +
freqStr = "%d MHz" % freq
 +
if freq > 1000:
 +
freqStr = "%.1f GHz" % (float(freq)/1000.0)
 +
oled.setTextXY(0,7)
 +
oled.putString("Freq:%s" % freqStr)
 +
oled.setTextXY(0,2)
 +
oled.putString("Usage:%d%%" % memUsage.percent)
 +
 +
oled.setTextXY(0,3)
 +
oled.putString("Disk:%s" % filesizeformat(diskUsage.total))
 +
 +
oled.setTextXY(0,4)
 +
oled.putString("Usage:%d%%" % diskUsage.percent)
 +
 +
oled.setTextXY(0,5)
 +
oled.putString("CPU:%s" % platform.processor())
 +
 +
oled.setTextXY(0,6)
 +
oled.putString("Cores:%d" % multiprocessing.cpu_count())
 +
 +
with open("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq") as f:
 +
freq = int(f.readlines()[0])/1000
 +
freqStr = "%d MHz" % freq
 +
if freq > 1000:
 +
freqStr = "%.1f GHz" % (float(freq)/1000.0)
 +
oled.setTextXY(0,7)
 +
oled.putString("Freq:%s" % freqStr)
 +
 +
</syntaxhighlight>
 +
 +
[https://github.com/friendlyarm/BakeBit/blob/master/Software/Python/bakebit_prj_SystemInfo.py Github]
 +
 +
=== Run Code Sample ===
 +
 +
Before you run the code sample you need to follow the steps in [http://wiki.friendlyarm.com/bakebit bakebit tutorial] to install the BakeBit package.<br />
 +
Enter the "BakeBit/Software/Python" directory and run the "bakebit_prj_SystemInfo.py" program:
 +
<syntaxhighlight lang="bash">
 +
cd ~/BakeBit/Software/Python
 +
sudo python bakebit_prj_SystemInfo.py
 +
</syntaxhighlight>
 +
 +
=== Observation ===
 +
 +
This is what users expect to observe:<br />
 +
[[File:OLED-SystemInfo.jpg |frameless|500px]]
 +
 +
== Code Sample(2): UI Control via Joystick ==
 +
A [[BakeBit - JoyStick]] module is needed in this test case. For more details about the joystick refer to the [[BakeBit - JoyStick]] page.
 +
 +
==Resources==
 +
*[Schematic]([http://wiki.friendlyarm.com/wiki/images/f/f6/11-SCHEMATIC_OLED128x64.pdf BakeBit - OLED 128x64.pdf])
 +
*[Datasheet]([http://wiki.friendlyarm.com/wiki/images/a/af/096-30-SPEC_QG-2864KLBEG01_VER_C.pdf BakeBit - OLED 128x64 Datasheet.pdf])
 +
*[BakeBit Github Project Page](https://github.com/friendlyarm/BakeBit)
 +
*[BakeBit Starter Kit User's Manual](http://wiki.friendlyarm.com/bakebit/bakebit_starter_kit_manual_en.pdf)
 +
 +
==Update Log==
 +
===December-14-2016===
 +
* Released English version
 +
 +
===Jan-19-2017===
 +
* Renamed "NEO-Hub" to "NanoHat-Hub"
 +
 +
===Jan-20-2017===
 +
* Renamed "NanoHat-Hub" to "NanoHat Hub"

Latest revision as of 00:10, 2 May 2017

查看中文

1 Introduction

OLED
  • The BakeBit - OLED is a monochromatic OLED module. The OLED is 0.96" and its resoltuion is 128 x 64. Its interface is I2C.
  • Users can set the I2C's address to either 0X3C or 0X3D and place two OLED modules on one I2C bus.

2 Hardware Spec

  • Standard 2.0mm pitch 4-Pin BakeBit I2C Interface
  • Resolution: 128 x 64
  • Color: blue
  • I2C's address configurable
  • PCB dimension(mm): 24 x 42

BakeBit - OLED_Top BakeBit - OLED_Bottom

  • Pin Description:
Pin Description
GND Ground
5V 5V Supply Voltage
SDA I2C-SDA
SCL I2C-SCL

3 Code Sample(1): Display System Info

When you run this code sample the system’s information will be listed on the OLED.

3.1 Hardware Setup

Connect the OLED module to the NanoHat Hub's I2C interface:

OLED-1.jpg OLED-2.jpg

3.2 Source Code

import time
import bakebit
import os
import psutil
from math import log
import multiprocessing
import platform
import socket
import bakebit_128_64_oled as oled
 
oled.init()                  #initialze SEEED OLED display
oled.clearDisplay()          #clear the screen and set start position to top left corner
oled.setNormalDisplay()      #Set display to normal mode (i.e non-inverse mode)
oled.setPageMode()           #Set addressing mode to Page Mode
 
byteunits = ('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB')
def filesizeformat(value):
    exponent = int(log(value, 1024))
    return "%.1f %s" % (float(value) / pow(1024, exponent), byteunits[exponent])
 
memUsage = psutil.phymem_usage()
diskUsage = psutil.disk_usage('/')
 
oled.setTextXY(0,0)
oled.putString("%s" % socket.gethostbyname(socket.gethostname()))
 
oled.setTextXY(0,1)
oled.putString("Mem:%s" % filesizeformat(memUsage.total))
 
oled.setTextXY(0,2)
oled.putString("Usage:%d%%" % memUsage.percent)
 
oled.setTextXY(0,3)
oled.putString("Disk:%s" % filesizeformat(diskUsage.total))
 
oled.setTextXY(0,4)
oled.putString("Usage:%d%%" % diskUsage.percent)
 
oled.setTextXY(0,5)
oled.putString("CPU:%s" % platform.processor())
 
oled.setTextXY(0,6)
oled.putString("Cores:%d" % multiprocessing.cpu_count())
 
with open("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq") as f:
	freq = int(f.readlines()[0])/1000
	freqStr = "%d MHz" % freq
	if freq > 1000:
		freqStr = "%.1f GHz" % (float(freq)/1000.0)
	oled.setTextXY(0,7)
	oled.putString("Freq:%s" % freqStr)
oled.setTextXY(0,2)
oled.putString("Usage:%d%%" % memUsage.percent)
 
oled.setTextXY(0,3)
oled.putString("Disk:%s" % filesizeformat(diskUsage.total))
 
oled.setTextXY(0,4)
oled.putString("Usage:%d%%" % diskUsage.percent)
 
oled.setTextXY(0,5)
oled.putString("CPU:%s" % platform.processor())
 
oled.setTextXY(0,6)
oled.putString("Cores:%d" % multiprocessing.cpu_count())
 
with open("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq") as f:
	freq = int(f.readlines()[0])/1000
	freqStr = "%d MHz" % freq
	if freq > 1000:
		freqStr = "%.1f GHz" % (float(freq)/1000.0)
	oled.setTextXY(0,7)
	oled.putString("Freq:%s" % freqStr)

Github

3.3 Run Code Sample

Before you run the code sample you need to follow the steps in bakebit tutorial to install the BakeBit package.
Enter the "BakeBit/Software/Python" directory and run the "bakebit_prj_SystemInfo.py" program:

cd ~/BakeBit/Software/Python
sudo python bakebit_prj_SystemInfo.py

3.4 Observation

This is what users expect to observe:
OLED-SystemInfo.jpg

4 Code Sample(2): UI Control via Joystick

A BakeBit - JoyStick module is needed in this test case. For more details about the joystick refer to the BakeBit - JoyStick page.

5 Resources

6 Update Log

6.1 December-14-2016

  • Released English version

6.2 Jan-19-2017

  • Renamed "NEO-Hub" to "NanoHat-Hub"

6.3 Jan-20-2017

  • Renamed "NanoHat-Hub" to "NanoHat Hub"