Difference between revisions of "BakeBit - OLED 128x64"

From FriendlyELEC WiKi
Jump to: navigation, search
(Created page with "查看中文")
 
Line 1: Line 1:
 
[[BakeBit - OLED 128x64/zh|查看中文]]
 
[[BakeBit - OLED 128x64/zh|查看中文]]
 +
 +
==Introduction==
 +
[[File:BakeBit - OLED.jpg|thumb|OLED]]
 +
*BakeBit - OLED是一个0.96寸模块,使用了一片128x64分辨率的单色OLED屏幕,OLED具有亮度高、对比度高、自发光、视角宽、功耗低等特点。模块使用了I2C接口,使用方便快捷。
 +
*通过配置模块上的地址设置电阻,可设置模块I2C从地址为0X3C或0X3D,这样同一个I2C总线上可同时连接两个OLED模块。
 +
 +
==特性==
 +
* 使用标准的2.0mm 4 Pin BakeBit I2C接口
 +
* 128x64分辨率
 +
* 颜色:蓝色
 +
* 模块I2C地址可配置。
 +
* PCB尺寸(mm):24x42
 +
[[File:BakeBit - OLED_Top_PCB.png | frameless|400px|BakeBit - OLED_Top]]
 +
[[File:BakeBit - OLED_Bottom_PCB.png | frameless|359px|BakeBit - OLED_Bottom]]
 +
 +
* 引脚说明:
 +
{| class="wikitable"
 +
|-
 +
|名称 || 描述
 +
|-
 +
|GND  || 地
 +
|-
 +
|5V    || 电源5V
 +
|-
 +
|SDA    || I2C-SDA
 +
|-
 +
|SCL  || I2C-SCL
 +
|}
 +
 +
== 示例程序(1):Display System Info  ==
 +
 +
这个例子我们使用显示屏来显示系统信息,例如IP地址,存储空间和内存信息,CPU当前频率等。
 +
 +
=== 硬件连接 ===
 +
简单的将 OLED 模块插入随便一个 I2C 接口,如下面这样:
 +
 +
::{| class="wikitable"
 +
|-
 +
|[[File:OLED-1.jpg |frameless|300px]]    || [[File:OLED-2.jpg |frameless|300px]]
 +
|-
 +
|}
 +
 +
=== 示例源代码 ===
 +
 +
<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))
 +
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]
 +
 +
=== 运行示例 ===
 +
 +
假设你已经参考[http://wiki.friendlyarm.com/bakebit bakebit教程]安装了BakeBit源代码,<br />
 +
要运行示例程序,可以在开发板上进入 BakeBit/Software/Python目录,运行bakebit_prj_SystemInfo.py:
 +
<syntaxhighlight lang="bash">
 +
cd ~/BakeBit/Software/Python
 +
sudo python bakebit_prj_SystemInfo.py
 +
</syntaxhighlight>
 +
 +
=== 运行结果 ===
 +
 +
效果如下图所示:<br />
 +
[[File:OLED-SystemInfo.jpg |frameless|500px]]
 +
 +
== 示例程序(2):UI Control via Joystick ==
 +
该示例是配合[[BakeBit - JoyStick]]来实现的,可参考[[BakeBit - JoyStick]]页面。
 +
 +
==相关资料==
 +
*[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项目](https://github.com/friendlyarm/BakeBit)
 +
*[BakeBit Starter Kit手册](http://wiki.friendlyarm.com/bakebit/bakebit_starter_kit_manual_cn.pdf)

Revision as of 14:48, 14 December 2016

查看中文

1 Introduction

OLED
  • BakeBit - OLED是一个0.96寸模块,使用了一片128x64分辨率的单色OLED屏幕,OLED具有亮度高、对比度高、自发光、视角宽、功耗低等特点。模块使用了I2C接口,使用方便快捷。
  • 通过配置模块上的地址设置电阻,可设置模块I2C从地址为0X3C或0X3D,这样同一个I2C总线上可同时连接两个OLED模块。

2 特性

  • 使用标准的2.0mm 4 Pin BakeBit I2C接口
  • 128x64分辨率
  • 颜色:蓝色
  • 模块I2C地址可配置。
  • PCB尺寸(mm):24x42

BakeBit - OLED_Top BakeBit - OLED_Bottom

  • 引脚说明:
名称 描述
GND
5V 电源5V
SDA I2C-SDA
SCL I2C-SCL

3 示例程序(1):Display System Info

这个例子我们使用显示屏来显示系统信息,例如IP地址,存储空间和内存信息,CPU当前频率等。

3.1 硬件连接

简单的将 OLED 模块插入随便一个 I2C 接口,如下面这样:

OLED-1.jpg OLED-2.jpg

3.2 示例源代码

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))
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 运行示例

假设你已经参考bakebit教程安装了BakeBit源代码,
要运行示例程序,可以在开发板上进入 BakeBit/Software/Python目录,运行bakebit_prj_SystemInfo.py:

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

3.4 运行结果

效果如下图所示:
OLED-SystemInfo.jpg

4 示例程序(2):UI Control via Joystick

该示例是配合BakeBit - JoyStick来实现的,可参考BakeBit - JoyStick页面。

5 相关资料