sh1106和ssd1306ssd和hdd的区别别

最近在学习树莓派,驱动OLED屏时出现了一个问题,就是花屏,折腾了两天后发现原来这个OLED的驱动芯片不是SSD1306而是SH1106,所以用Adafruit_Python_SSD1306这个库是花屏的。
OLED的驱动芯片有好几种,但是有的库只支持SSD1306芯片,所以当你的OLED屏出现花屏时就应该是芯片和库没对应上,购买OLED屏时最好购买i2c的SSD1306芯片的,库多且接线比较简单。
Python有两个可以用的OLED库:
—&只支持SSD1306
—&支持SSD1306 / SSD1322 / SSD1325 / SSD1331 / SH1106
Adafruit_Python_SSD1306库与Luma.oled库的安装说明(看不懂英文没关系,看下面我会说)。
本文的Luma.oled库参考了,但这是旧版本的,新版本库不是这样安装,请看下文。
树莓派物理BOARD引脚
接好线后就是像一个L型的。
开启i2c功能
sudo apt-get install -y python-smbus
sudo apt-get install -y i2c-tools
sudo raspi-config
打开树莓派配置选择5 Interfacing Options。
选择P5 I2C回车激活I2C。
按回车启动就得了。
查看i2c地址
sudo i2cdetect -y 1
然后你能看到下面的地址,3c就是oled屏的i2c地址了,说明已经成功开启i2c啦
– 安装Adafruit_Python_SSD1306库
终端输入下面命令。
sudo apt-get update
sudo apt-get install build-essential python-dev python-pip
sudo pip install RPi.GPIO
sudo apt-get install python-imaging python-smbus
sudo apt-get install git
git clone https://github.com/adafruit/Adafruit_Python_SSD1306.git
cd Adafruit_Python_SSD1306
sudo python setup.py install
安装好Adafruit_Python_SSD1306库后,cd examples进入例程目录,ls查看文件,以shapes.py例程说明。
import time
import Adafruit_GPIO.SPI as SPI
import Adafruit_SSD1306
import Image
import ImageDraw
import ImageFont
# Raspberry Pi pin configuration:
# Note the following are only used with SPI:
SPI_PORT = 0
SPI_DEVICE = 0
# Beaglebone Black pin configuration:
# RST = 'P9_12'
# Note the following are only used with SPI:
# DC = 'P9_15'
# SPI_PORT = 1
# SPI_DEVICE = 0
# 128x32 display with hardware I2C:
disp = Adafruit_SSD1306.SSD(rst=RST)
# 128x64 display with hardware I2C:
# disp = Adafruit_SSD1306.SSD(rst=RST)
# Alternatively you can specify an explicit I2C bus number, for example
# with the 128x32 display you would use:
# disp = Adafruit_SSD1306.SSD(rst=RST, i2c_bus=2)
# 128x32 display with hardware SPI:
# disp = Adafruit_SSD1306.SSD(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))
# 128x64 display with hardware SPI:
# disp = Adafruit_SSD1306.SSD(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))
# Alternatively you can specify a software SPI implementation by providing
# digital GPIO pin numbers for all the required display pins.
For example
# on a Raspberry Pi with the 128x32 display you might use:
# disp = Adafruit_SSD1306.SSD(rst=RST, dc=DC, sclk=18, din=25, cs=22)
# Initialize library.
disp.begin()
# Clear display.
disp.clear()
disp.display()
# Create blank image for drawing.
# Make sure to create image with mode '1' for 1-bit color.
width = disp.width
height = disp.height
image = Image.new('1', (width, height))
# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)
# Draw a black filled box to clear the image.
draw.rectangle((0,0,width,height), outline=0, fill=0)
# Draw some shapes.
# First define some constants to allow easy resizing of shapes.
padding = 2
shape_width = 20
top = padding
bottom = height-padding
# Move left to right keeping track of the current x position for drawing shapes.
x = padding
# Draw an ellipse.
draw.ellipse((x, top , x+shape_width, bottom), outline=255, fill=0)
x += shape_width+padding
# Draw a rectangle.
draw.rectangle((x, top, x+shape_width, bottom), outline=255, fill=0)
x += shape_width+padding
# Draw a triangle.
draw.polygon([(x, bottom), (x+shape_width/2, top), (x+shape_width, bottom)], outline=255, fill=0)
x += shape_width+padding
# Draw an X.
draw.line((x, bottom, x+shape_width, top), fill=255)
draw.line((x, top, x+shape_width, bottom), fill=255)
x += shape_width+padding
# Load default font.
font = ImageFont.load_default()
# Alternatively load a TTF font.
# Some other nice fonts to try: http://www.dafont.com/bitmap.php
#font = ImageFont.truetype('Minecraftia.ttf', 8)
# Write two lines of text.
draw.text((x, top),
font=font, fill=255)
draw.text((x, top+20), 'World!', font=font, fill=255)
# Display image.
disp.image(image)
disp.display()
按照你的oled屏修改代码,程序默认是12832的,你的oled屏是这个就不用改直接运行就OK。
如果是12864的I2C就像下面那样修改,把12832加#注释,12864#注释去掉保存。
# 128x32 display with hardware I2C:
#disp = Adafruit_SSD1306.SSD(rst=RST)
# 128x64 display with hardware I2C:
disp = Adafruit_SSD1306.SSD(rst=RST)
终端输入sudo python shapes.py或用Python打开文件运行就能看到OLED屏有显示了。
– 安装Luma.oled库
终端输入下面命令。
sudo apt-get install python-dev python-pip libfreetype6-dev libjpeg-dev
sudo -H pip install --upgrade pip
sudo apt-get purge python-pip
sudo -H pip install --upgrade luma.oled&span id="mce_marker" data-mce-type="bookmark" data-mce-fragment="1"&&/span&
注:如果你需要安装Python3的Luma.oled库的则按下面对应的Python3版本修改上面的命令进行安装。
pip => pip3
python => python3
python-dev => python3-dev
python-pip => python3-pip
如果安装Luma.oled库时出现红字错误,请继续执行命令重试,那是因为网络问题下载一个叫Pillow的库不成功。
安装好Luma.oled库后新建文件命名为oled.py,复制粘贴下面代码。
from luma.core.interface.serial import i2c, spi
from luma.core.render import canvas
from luma.oled.device import ssd1306, ssd1325, ssd1331, sh1106
# rev.1 users set port=0
# substitute spi(device=0, port=0) below if using that interface
serial = i2c(port=1, address=0x3C)
# substitute ssd1331(...) or sh1106(...) below if using that device
device = sh1106(serial)#这里改ssd1306, ssd1325, ssd1331, sh1106
with canvas(device) as draw:
draw.rectangle(device.bounding_box, outline="white", fill="black")
draw.text((30, 40), "Hello World", fill="white")
如果你的oled驱动芯片是其它型号找到device = sh1106(serial),把sh1106改成库支持的其它型号。
树莓派上用Python2打开oled.py运行就能看到下图的Hello World。
能驱动成功后我们去下载Luma.oled的。
然后是examples里面的例子怎么用呢?如果是非ssd1306芯片直接运行还是花屏的,因为那个examples的代码需要修改。
下面以pi_logo.py为例参考上面那个Hello World的例子修改成自己OLED芯片型号的(文件放在在examples内)。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2014-17 Richard Hull and contributors
# See LICENSE.rst for details.
# PYTHON_ARGCOMPLETE_OK
Display the Raspberry Pi logo (loads image as .png).
import os.path
from PIL import Image
from luma.core.interface.serial import i2c, spi
from luma.oled.device import ssd1306, ssd1325, ssd1331, sh1106
def main():
img_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
'images', 'pi_logo.png'))
logo = Image.open(img_path).convert("RGBA")
fff = Image.new(logo.mode, logo.size, (255,) * 4)
background = Image.new("RGBA", device.size, "white")
posn = ((device.width - logo.width) // 2, 0)
while True:
for angle in range(0, 360, 2):
rot = logo.rotate(angle, resample=Image.BILINEAR)
img = Image.composite(rot, fff, rot)
background.paste(img, posn)
device.display(background.convert(device.mode))
if __name__ == "__main__":
serial = i2c(port=1, address=0x3C)
device = sh1106(serial)
except KeyboardInterrupt:
Python运行上面的程序oled屏会出现一个能旋转的树莓派LOGO。
转载请注明:《》Loading...【图片】【arduino】有谁用过这个屏幕u8g应该用哪个?_arduino吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:54,251贴子:
【arduino】有谁用过这个屏幕u8g应该用哪个?收藏
arduino, 650多家厂商代理,100多万种现货库存,当天出货,免费送货.
//U8GLIB_ST_1X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16);
// 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16//U8GLIB_ST_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16);
// 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16//U8GLIB_ST_1X u8g(18, 16, 17);// SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17//U8GLIB_ST_4X u8g(18, 16, 17);// SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17//U8GLIB_SSD u8g(13, 11, 10, 9);// SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9//U8GLIB_SSD u8g(10, 9);// HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are
SCK = 13 and MOSI = 11)//U8GLIB_SSD u8g(U8G_I2C_OPT_NONE);// I2C / TWI //U8GLIB_SSD u8g(U8G_I2C_OPT_NO_ACK);// Display which does not send ACK//U8GLIB_SH u8g(13, 11, 10, 9);// SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9//U8GLIB_SH u8g(U8G_I2C_OPT_NONE);// I2C / TWI //U8GLIB_SH u8g(U8G_I2C_OPT_NO_ACK);// Display which does not send ACK//U8GLIB_SSD u8g(13, 11, 10, 9);// SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9//U8GLIB_T u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
u8glib ssd
我记得这个好像要改跳线
看你的屏幕引脚 驱动芯片貌似和我一样
根据你的接法,得选择不同的句子
我给你我的接法和句子吧
vcc-3.3v gnd-gndd0-13
d1-11 rst-rst dc-9 cs-10
句子我选的是 U8GLIB_SSD@306_128X1,11,10,9);
选 U8GLIB_SSD1306_ADAFRUIT_128X64 u8g(13, 11, 10, 9);
// SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9可是我显示出来的字上下闪动,救命啊
我的是iic的
U8GLIB_SSD u8g(U8G_I2C_OPT_NONE);
登录百度帐号推荐应用Access denied | learn.adafruit.com used Cloudflare to restrict access
Please enable cookies.
What happened?
The owner of this website (learn.adafruit.com) has banned your access based on your browser's signature (3e8cc23b3f5792b8-ua98).A small library to drive an OLED device with either SSD1306, SSD1325, SSD1331 or SH1106 chipset
Python library interfacing OLED matrix displays with the SSD1306, SSD1325, SSD1331 or
SH1106 driver using I2C/SPI on the Raspberry Pi and other linux-based single-board computers -
it provides a Pillow-compatible drawing canvas, and other functionality to support:
scrolling/panning capability,
terminal-style printing,
state management,
color/greyscale (where supported),
dithering to monochrome
A list of tested devices can be found in the
The SSD1306 display pictured below is 128 x 64 pixels, and the board is tiny,
and will fit neatly inside the RPi case.
As well as display drivers for various physical OLED devices, there are emulators that run in real-time
(with pygame) and others that can take screenshots, or assemble animated GIFs, as per the examples below (source
code for these is available in the
directory:
Documentation
Full documentation with installation instructions and examples can be found on
The MIT License (MIT)
Copyright (c) 2016 Richard Hull & Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Contributing
Pull requests (code changes / documentation / typos / feature requests / setup)
are gladly accepted. If you are intending to introduce some large-scale
changes, please get in touch first to make sure we’re on the same page: try to
include a docstring for any new method or class, and keep method bodies small,
readable and PEP8-compliant. Add tests and strive to keep the code coverage
levels high.
The source code is available to clone at:
Contributors
Thijs Triemstra (@thijstriemstra)
Christoph Handel (@fragfutter)
Boeeerb (@Boeeerb)
xes (@xes)
Roger Dahl (@rogerdahl)
Václav ?milauer (@eudoxos)
Claus Bjerre (@bjerrep)
Description
Performance improvements for SH1106 driver (2x frame rate!)
Support for 4-bit greyscale OLED (SSD1325)
Landscape/portrait orientation with rotate=N parameter
Add savepoint/restore functionality
Add terminal functionality
Canvas image dithering
Additional & improved examples
Load config settings from file (for examples)
Universal wheel distribution
Improved/simplified error reporting
Documentation updates
Add ability to adjust brightness of screen
Fix for wrong value NORMALDISPLAY for SSD1331 device
Support for 16-bit color OLED (SSD1331)
Viewport/scrolling support
Remove pygame as an install dependency in setup
Ensure SH1106 device collapses color images to monochrome
Fix for emulated devices: do not need cleanup
Fix to allow gifanim emulator to process 1-bit images
Establish a single threadpool for all virtual viewports
Fix issue preventing multiple threads from running concurrently
Documentation updates
Add support for 128x32, 96x16 OLED screens (SSD1306 chipset only)
Fix boundary condition error when supplying max-frames to gifanim
Bit pattern calc rework when conveting color -& monochrome
Approx 20% performance improvement in display method
Add animated-GIF emulator
Add color-mode flag to emulator
Fix regression in SPI interface
Rename emulator transform option ‘scale’ to ‘identity’
Add HQX scaling to capture and pygame emulators
SPI support (NOTE: contains breaking changes)
Improve benchmarking examples
Fix resource leakage & noops on emulated devices
Additional tests
Pygame-based device emulator & screen capture device emulator
Add bouncing balls demo, clock & Space Invaders examples
Auto cleanup on exit
Add bounding_box attribute to devices
Demote buffer & pages attributes to “internal use” only
Replaced SH1106 data sheet with version that is not “preliminary”
Add font attribution
Tests for SSD1306 & SSH1106 devices
Add code coverage & upload to coveralls.io
flake8 code compliance
Documentation updates
Performance improvements - render speeds ~2x faster
Documentation updates
Add PyPi badge
Use smbus2
Fix bug in maze example (integer division on python 3)
Use latest pip
Add tox & travis config (+ badge)
Add RTFD config
Documentation updates
Adjust requirements (remove smbus)
Default RTFD theme
Documentation updates
Allow SMBus implementation to be supplied
Add show, hide and clear methods
Catch & rethrow IOError exceptions
Fix error in ‘hello world’ example
Cleanup imports
Allow setting width/height
Documentation updates
Add Python 3 support
Add options to demos
Micro-optimizations
Remove unused optional arg
Fix bug in rendering image data
Added more examples
Add setup file
Support SH1106
Documentation updates
Py Version
Uploaded on
Python Wheel
Richard Hull
Home Page:
Download URL:
raspberry pi rpi oled display screen ssd1306 ssd1325 ssd1331 sh1106 spi i2c 128x64 128x32 96x16
Categories
Package Index Owner:
Copyright (C) ,}

我要回帖

更多关于 m2ssd和ssd的区别 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信