mod-oled-128x64的控制模块

mod-oled-128x64的Python项目详细描述


简介

用于将mod-oled-128x64与olinuxino板连接的python库。 SSD1306控制器支持SPI、I2C和并行接口,但是 这个模块只有I2C可用。

默认情况下,I2C-1和I2C-2总线使用100kHz时钟。这意味着你可以 每秒大约8帧。你可以使用I2C-0,在大多数Olinuxino板中 运行在400kHz(大约25fps,因为该总线也用于PMU模块)。 使用小于128x64的显示区域可以加快速度。

要求

此软件包需要以下模块:

  • 中小企业CFFI

安装

来自github:

git clone https://github.com/SelfDestroyer/pyMOD-OLED.git
cd pyMOD-OLED
python setup.py install

来自PYPI:

wget https://pypi.python.org/packages/source/m/mod-oled-128x64/mod-oled-128x64-0.0.3.tar.gz
tar -zxf mod-oled-128x64-0.0.3.tar.gz
cd mod-oled-128x64-0.0.3
python setup.py install

使用pip:

pip install mod-oled-128x64

用法

此软件包中有3个模块:

  • OLED-控件的主类。在这里你可以做所有你需要的设置。
  • 字体-包含基本字体表,并有能力从中写入字符。
  • 图形。基本绘图方法。像素,线和圆。

要导入模块,请使用:

fromoledimportOLEDfromoledimportFontfromoledimportGraphics

完整示例:

fromoledimportOLEDfromoledimportFontfromoledimportGraphics# Connect to the display on /dev/i2c-0dis=OLED(0)# Start communicationdis.begin()# Start basic initializationdis.initialize()# Do additional configurationdis.set_memory_addressing_mode(0)dis.set_column_address(0,127)dis.set_page_address(0,7)# Clear displaydis.clear()# Set font scale x2f=Font(2)# Print some large textf.print_string(6,0,"OLIMEX LTD")# Change font to 5x7f.scale=1f.print_string(0,24,"MOD-OLED-128x64")f.print_string(0,32,"olimex.com")# Send video buffer to displaydis.update()# Make horizontal scrolldis.horizontal_scroll_setup(dis.LEFT_SCROLL,3,3,7)dis.activate_scroll()# Only the last scroll setup is activedis.horizontal_scroll_setup(dis.LEFT_SCROLL,4,4,7)dis.activate_scroll()# Draw lineGraphics.draw_pixel(0,0)Graphics.draw_line(0,60,100,63)dis.update()

类和方法

类oled.oled(I2C,地址=60)

activate_scroll()

Activate Scroll (2Fh)

This command starts the motion of scrolling and should only be issued after the scroll setup parameters have been defined by the scrolling setup commands :26h/27h/29h/2Ah . The setting in the last scrolling setup command overwrites the setting in the previous scrolling setup commands.

The following actions are prohibited after the scrolling is activated RAM access (Data write or read)

Changing the horizontal scroll setup parameters

begin()

Create communication object

充电泵设置(开)

Charge Pump Regulator (8Dh)

Parameters:
on – True - Enable charge pump during display on False - Disable charge pump(RESET)

clear(update=true)

Clear video buffer

Parameters:
update – If true send the empty buffer to the controller

close()

Close I2C bus and delete communication object

deactivate\u scroll()

Deactivate scroll (2Eh)

This command stops the motion of scrolling. After sending 2Eh command to deactivate the scrolling action,the ram data needs to be rewritten.

整个显示打开(状态)

Entire Display ON (A4h/A5h)

A4h command enable display outputs according to the GDDRAM contents.If A5h command is issued, then by using A4h command, the display will resume to the GDDRAM contents. In other words, A4h command resumes the display from entire display “ON” stage. A5h command forces the entire display to be “ON”, regardless of the contents of the display data RAM.

Parameters:
status – True - Entire display ON. Output ignores RAM content False - Resume to RAM content display (RESET). Output follows RAM content

水平滚动设置(方向、起始页、结束页、速度)

Horizontal Scroll Setup (26h/27h)

This command consists of consecutive bytes to set up the horizontal scroll parameters and determines the scrolling start page, end page and scrolling speed. Before issuing this command the horizontal scroll must be deactivated (2Eh). Otherwise, RAM content may be corrupted.

Parameters:
  • direction – 0 - Right Horizontal Scroll 1 - Left Horizontal Scroll
  • start_page – Define start page address - PAGE0 ~ PAGE7
  • end_page – Define end page address - PAGE0 ~ PAGE7
  • speed – Set time interval between each roll step in terms of frame frequency: 0 - 5 frames 1 - 64 frames 2 - 128 frames 3 - 256 frames 4 - 3 frames 5 - 4 frames 6 - 25 frames 7 - 2 frames
Raises ValueError:
Start page cannot be larger than end page

initialize()

Basic display initialization

发送数据(数据)

Send data in packets by 16 bytes

Parameters:
data – Data to be send

send_nop()

NOP (E3h)

No operation command

设置列地址(列起始地址,列结束地址)

Set Column Address (21h)

This triple byte command specifies column start address and end address of the display data RAM. This command also sets the column address pointer to column start address. This pointer is used to define the current read/write column address in graphic display data RAM. If horizontal address increment mode is enabled by command 20h, after finishing read/write one column data, it is incremented automatically to the next column address. Whenever the column address pointer finishes accessing the end column address, it is reset back to start column address and the row address is incremented to the next row.

Parameters:
  • column_start_address – Column start address, range : 0-127d, (RESET=0d)
  • column_end_address – Column end address, range : 0-127d, (RESET =127d)
Raises MethodError:
This command is only for horizontal or vertical addressing mode.

设置COM引脚配置(配置,重新映射)

Set COM Pins Hardware Configuration (DAh)

This command sets the COM signals pin configuration to match the OLED panel hardware layout. Refer to datasheet section 10.1.18 for detailed information.

Parameters:
  • configuration – 0 - Sequential COM pin configuration, 1 - Alternative COM pin configuration (RESET)
  • remap – 0 - Disable COM Left/Right remap (RESET) 1 - Enable COM Left/Right remap

设置对比度控制(对比度)

Set Contrast Control for BANK0 (81h)

This command sets the Contrast Setting of the display. The chip has 256 contrast steps from 00h to FFh. The segment output current increases as the contrast step value increases.

Parameters:
contrast – Double byte command to select 1 out of 256 contrast steps. Contrast increases as the value increases. (RESET = 7Fh )

set取消选择级别(级别)

Set Vcomh deselect level (DBh)

This command adjust the Vcomh regulator output.

Parameters:
level – 0, 1 or 2 0 ~ 0.65 * Vcc 1 ~ 0.77 * Vcc (RESET) 2 ~ 0.83 * Vcc

设置显示时钟(分频器,OSC频率)

Set Display Clock Divide Ratio/Oscillator Frequency (D5h)

This command consists of two functions:

  • Display Clock Divide Ratio (D)(A[3:0])

Set the divide ratio to generate DCLK (Display Clock) from CLK. The divide ratio is from 1 to 16, with reset value = 1. Please refer to section 8.3 for the details relationship of DCLK and CLK.

  • Oscillator Frequency (A[7:4])

Program the oscillator frequency Fosc that is the source of CLK if CLS pin is pulled high. The 4-bit value results in 16 different frequency settings available as shown below. The default setting is 1000b.

参数:
  • 除法器–定义显示器的除法比(d) 时钟(dclk):dvide ration=divider+1,reset为0 (除以比率=1)
  • osc_freq–设置振荡器频率fosc。 振荡器频率随振荡频率的增加而增加 反之亦然。复位为1000B。范围:0000B~1111B。

set_display_offset(偏移量)

Set Display Offset (D3h)

This is a double byte command. The second command specifies the mapping of the display start line to one of COM0~COM63 (assuming that COM0 is the display start line then the display start line register is equal to 0). For example, to move the COM16 towards the COM0 direction by 16 lines the 6-bit data in the second byte should be given as 010000b. To move in the opposite direction by 16 lines the 6-bit data should be given by 64 – 16, so the second byte would be 100000b.

参数:
偏移量–设置com从0d到63d的垂直偏移值 重置后重置为00小时。

set_display_on_off(开)

Set Display ON/OFF (AEh/AFh)

These single byte commands are used to turn the OLED panel display ON or OFF. When the display is ON, the selected circuits by Set Master Configuration command will be turned ON. When the display is OFF, those circuits will be turned OFF and the segment and common output are in VSS state and high impedance state, respectively.

Parameters:
on – True - Display ON False - Display OFF

设置显示开始行(开始行)

Set Display Start Line (40h~7Fh)

This command sets the Display Start Line register to determine starting address of display RAM, by selecting a value from 0 to 63. With value equal to 0, RAM row 0 is mapped to COM0. With value equal to 1, RAM row 1 is mapped to COM0 and so on.

Parameters:
start_line – Set display RAM display start line register from 0-63. Display start line register is reset to 000000b during RESET.

set_higher_列(列)

Set Higher Column Start Address for Page Addressing Mode (10h~1Fh)

This command specifies the higher nibble of the 8-bit column start address for the display data RAM under Page Addressing Mode. The column address will be incremented by each data access.

Parameters:
column – Set the higher nibble of the column start address register for Page Addressing Mode using X[3:0] as data bits. The initial display line register is reset to 0000b after RESET.
Raises MethodError:
This command is only for page addressing mode

set_inverse_display(inverse)

Set Normal/Inverse Display (A6h/A7h)

This command sets the display to be either normal or inverse. In normal display a RAM data of 1 indicates an “ON” pixel while in inverse display a RAM data of 0 indicates an “ON” pixel.

Parameters:
inverse – True - Inverse display False - ormal display (RESET)

set_lower_列(列)

Set Lower Column Start Address for Page Addressing Mode (00h~0Fh)

This command specifies the lower nibble of the 8-bit column start address for the display data RAM under Page Addressing Mode. The column address will be incremented by each data access.

Parameters:
column – Set the lower nibble of the column start address register for Page Addressing Mode using X[3:0] as data bits. The initial display line register is reset to 0000b after RESET.
Raises MethodError:
This command is only for page addressing mode

设置内存寻址模式(模式)

Set Memory Addressing Mode (20h)

There are 3 different memory addressing mode in SSD1306: page addressing mode, horizontal addressing mode and vertical addressing mode. This command sets the way of memory addressing into one of the above three modes. In there, “COL” means the graphic display data RAM column.

Parameters:

mode

2 - Page addressing mode In page addressing mode, after the display RAM is read/written, the column address pointer is increased automatically by 1. If the column address pointer reaches column end address, the column address pointer is reset to column start address and page address pointer is not changed. Users have to set the new page and column addresses in order to access the next page RAM content.

0 - Horizontal addressing mode In horizontal addressing mode, after the display RAM is read/written, the column address pointer is increased automatically by 1. If the column address pointer reaches column end address, the column address pointer is reset to column start address and page address pointer is increased by 1. When both column and page address pointers reach the end address, the pointers are reset to column start address and page start address.

1 - Vertical addressing mode In vertical addressing mode, after the display RAM is read/written, the page address pointer is increased automatically by 1. If the page address pointer reaches the page end address, the page address pointer is reset to page start address and column address pointer is increased by 1. When both column and page address pointers reach the end address, the pointers are reset to column start address and page start address

set多路复用比率(比率)

Set Multiplex Ratio (A8h)

This command switches the default 63 multiplex mode to any multiplex ratio, ranging from 16 to 63. The output pads COM0~COM63 will be switched to the corresponding COM signal.

Parameters:
ratio – Set MUX ratio to N+1 MUX N=A[5:0] : from 16MUX to 64MUX, RESET= 111111b (i.e. 63d, 64MUX) A[5:0] from 0 to 14 are invalid entry.

设置页面地址(页面起始地址,页面结束地址)

Set Page Address (22h)

This triple byte command specifies page start address and end address of the display data RAM. This command also sets the page address pointer to page start address. This pointer is used to define the current read/write page address in graphic display data RAM. If vertical address increment mode is enabled by command 20h, after finishing read/write one page data, it is incremented automatically to the next page address. Whenever the page

address pointer finishes accessing the end page address, it is reset back to start page address.
参数:
  • 页面起始地址–页面起始地址,范围: 0-7d,(复位=0d)
  • 页结束地址–页结束地址,范围:0-7d, (复位=7d)
引发方法错误:
此命令仅用于水平或垂直寻址 模式。

设置页面起始地址(页面)

Set Page Start Address for Page Addressing Mode (B0h~B7h)

This command positions the page start address from 0 to 7 in GDDRAM under Page Addressing Mode.

Parameters:
page – Set GDDRAM Page Start Address (PAGE0~PAGE7) for Page Addressing Mode using X[2:0].
Raises MethodError:
This command is only for page addressing mode

set_precharge_period(phase1,phase2)

Set Pre-charge Period (D9h)

This command is used to set the duration of the pre-charge period. The interval is counted in number of DCLK, where RESET equals 2 DCLKs.

Parameters:
  • phase1 – Phase 1 period of up to 15 DCLK clocks, 0 is invalid entry (RESET = 2h)
  • phase2 – Phase 2 period of up to 15 DCLK clocks, 0 is invalid entry (RESET = 2h)

设置扫描方向(重新映射)

Set COM Output Scan Direction (C0h/C8h)

This command sets the scan direction of the COM output allowing layout flexibility in the OLED module design. Additionally, the display will show once this command is issued. For example, if this command is sent during normal display then the graphic display will be vertically flipped immediately.

Parameters:
remapped – True - remapped mode. Scan from COM[N-1] to COM0 False - normal mode. Scan from COM0 to COM[N –1] (RESET) Where N is the Multiplex ratio.

set_segment_remap(remap)

Set Segment Re-map (A0h/A1h)

This command changes the mapping between the display data column address and the segment driver. It allows flexibility in OLED module design. Please refer to Table 9-1.

This command only affects subsequent data input. Data already stored in GDDRAM will have no changes.

Parameters:
remap – True - column address 127 is mapped to SEG0 False - column address 0 is mapped to SEG0 (RESET)

设置垂直滚动区域(开始,计数)

Set Vertical Scroll Area(A3h)

This command consists of 3 consecutive bytes to set up the vertical scroll area. For the continuous vertical scroll function (command 29/2Ah), the number of rows that in vertical scrolling can be set smaller or equal to the MUX ratio.

Parameters:
  • start – Set No. of rows in top fixed area. The No. of rows in top fixed area is referenced to the top of the GDDRAM (i.e. row 0).[RESET =0]
  • count – Set No. of rows in scroll area. This is the number of rows to be used for vertical scrolling. The scroll area starts in the first row below the top fixed area. [RESET = 64]

Raises ValueError:

update()

Send video buffer to the controller

垂直和水平滚动设置(方向、起始页、结束页、速度、垂直偏移)

Continuous Vertical and Horizontal Scroll Setup (29h/2Ah)

This command consists of 6 consecutive bytes to set up the continuous vertical scroll parameters and determines the scrolling start page, end page, scrolling speed and vertical scrolling offset.

The bytes B[2:0], C[2:0] and D[2:0] of command 29h/2Ah are for the setting of the continuous horizontal scrolling. The byte E[5:0] is for the setting of the continuous vertical scrolling offset. All these bytes together are for the setting of continuous diagonal (horizontal + vertical) scrolling. If the vertical scrolling offset byte E[5:0] is set to zero, then only horizontal scrolling is performed (like command 26/27h).

Before issuing this command the scroll must be deactivated (2Eh). Otherwise, RAM content may be corrupted.

Parameters:
  • direction – 0 - Vertical and Right Horizontal Scroll 1 - Vertical and Left Horizontal Scroll
  • start_page – Define start page address - PAGE0 ~ PAGE7
  • end_page – Define end page address - PAGE0 ~ PAGE7
  • speed – Set time interval between each roll step in terms of frame frequency: 0 - 5 frames 1 - 64 frames 2 - 128 frames 3 - 256 frames 4 - 3 frames 5 - 4 frames 6 - 25 frames 7 - 2 frames
  • vertical_offset – Vertical scrolling offset e.g. 01h refer to offset = 1 row 3Fh refer to offset = 63 rows
Raises ValueError:
Start page cannot be larger than end page

类oled.font(scale=1)

print_char(x, y, ch)

Print single char at location

Parameters:
  • x – X location
  • y – Y location
  • ch – ASCII code for char

打印字符串(x0,y0,字符串)

Print string to display.

Parameters:
  • x0 – Start X position
  • y0 – Start Y position
  • string – String to display

Returns: None

class类oled.graphics

classmethod draw_circle(x0, y0, r)

Draw singled circle

Parameters:
  • x0 – Center x location
  • y0 – Center y location
  • r – Radius

classmethod绘制线(x0,y0,x1,y1)

Draw single line

Parameters:
  • x0 – Start x location
  • y0 – Start y location
  • x1 – End x location
  • y1 – End y location

classmethod绘制像素(x,y,on=true)

Draw single pixel to video buffer

Parameters:
  • x – X location
  • y – Y location
  • on – True - Set pixel, False - clear pixel

0.0.4(2015-03-21)

  • 修复了pypi archieve。

0.0.3(2015-06-18)

  • 添加了详细的自述文件

0.0.1(2015-06-17)

  • 初始版本

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
带有嵌套JAR的java RCP ClassNotFoundException   java在输入框中设置默认值,crud应用程序使用spring   java如何在Heroku中使用fs创建新文件   java将JPanel放在JFrame中   java这个正则表达式会匹配“i.imgur.com/xxx”吗?   java在片段内创建RecylerView,而无需在Android中设置片段   Android上Groovy导致java错误的双精度浮点精度损失   swing Java查找JFrame属于JPanel的内容   java Spring junit自连线自定义类本身必须有构造函数吗?   java textswitcher支持前面的文本   从Android客户端到JAXRS的java Post自定义对象   java如何检索JSON数据并使用MPAndroidChart绘制折线图,以及在安卓上的改进   拒绝用户“root”@“localhost”的java c3p0访问(使用密码“是”)   使用Selenium Webdriver自动化ExtJS应用程序时java面临的问题