凌风清羽 发表于 2016-1-10 22:13:37

【树莓派教程】——SPI驱动OLED 128*64



树莓派针脚定义


OLED各针脚定义以及联线
GND——rasp gnd
VCC ——rasp vcc(3.3/5V)
D0(SCLK)——rasp SCLK (BCM:11/BOARD:23)
D1(MOSI )——rasp MOSI(BCM:10/BOARD:19)
RST——rasp GPIO(BCM:17/BOARD:11)
DC(数据与命令选择)——rasp (BCM:27/BOARD:13)
CS(SPI片选)——rasp (BCM:8/BOARD:24)

重要的部分要开始啦~~~~ATTENTION!!!!!!!!!!
1.打开树莓派的SPI。
树莓派的SPI默认是关闭的(这一点和I2C类似),打开方法有多种,在这仅介绍一种
vi /etc/modprobe.d/raspi-blacklist.conf
修改为如图


注释掉两行表示启用SPI/I2C
# blacklist spi and i2c by default (many users don't need them)

   #blacklist spi-bcm2708
   #blacklist i2c-bcm2708
reboot 以下
cd /dev
ls -al
你会看到spidev0.0以及spidev0.1



2.库
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 啦~~在此要感谢@孙毅带我入git的坑~~O(∩_∩)O哈哈~
git clone https://github.com/adafruit/Adafruit_Python_SSD1306.git
cd Adafruit_Python_SSD1306
sudo python setup.py install到这就差不多了,来一个python的程序
#!/usr/bin/python/
# coding: utf-8
import time
import Adafruit_GPIO.SPI as SPI
import Adafruit_SSD1306
import Image
import ImageDraw
import ImageFont

# Raspberry Pi pin configuration:
RST = 17
# Note the following are only used with SPI:
DC = 27
SPI_PORT = 0
SPI_DEVICE = 0

# 128x64 display with hardware SPI:
disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))

# 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 = 1
top = padding
x = 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), 'This is first line', font=font, fill=255)
draw.text((x, top+10), 'This is second line', font=font, fill=255)
draw.text((x, top+20), 'This is third line', font=font, fill=255)
draw.text((x, top+30), 'This is fourth line', font=font, fill=255)
draw.text((x, top+40), 'This is fifth line', font=font, fill=255)
draw.text((x, top+50), 'This is last line', font=font, fill=255)

# Display image.
disp.image(image)
disp.display()

凌风清羽 发表于 2016-1-10 22:14:55

舒爽{:5_172:}

大连林海 发表于 2016-1-10 23:18:48

凌风清羽 发表于 2016-1-10 22:14
舒爽

厉害{:5_172:}

孙毅 发表于 2016-1-11 00:22:22

要不要这么任性。。。哈哈哈,牛!

hnyzcj 发表于 2016-1-11 05:53:30

刚买了一块OLED,正好用用。

丄帝De咗臂 发表于 2016-1-11 08:14:01

树莓派被你玩透了

孙毅 发表于 2016-1-11 09:58:50

hnyzcj 发表于 2016-1-11 05:53
刚买了一块OLED,正好用用。

你oled接哪里用啊,陈老师?
用什么“软体”?

hnyzcj 发表于 2016-1-11 10:09:23

孙毅 发表于 2016-1-11 09:58
你oled接哪里用啊,陈老师?
用什么“软体”?

用ARDUINO软体

凌风清羽 发表于 2016-1-11 11:57:58

大连林海 发表于 2016-1-10 23:18
厉害

嘿嘿,刚刚起步~~{:5_171:}

凌风清羽 发表于 2016-1-11 11:57:59

大连林海 发表于 2016-1-10 23:18
厉害

嘿嘿,刚刚起步~~{:5_171:}

凌风清羽 发表于 2016-1-11 12:00:00

丄帝De咗臂 发表于 2016-1-11 08:14
树莓派被你玩透了

还差的远呢~~~{:5_168:}~~

大连林海 发表于 2016-1-11 16:34:29

凌风清羽 发表于 2016-1-11 11:57
嘿嘿,刚刚起步~~

加油加油

大连林海 发表于 2016-1-11 19:58:47

大神 是不是要和你求师了 {:5_172:}

凌风清羽 发表于 2016-1-12 16:57:44

大连林海 发表于 2016-1-11 19:58
大神 是不是要和你求师了

{:5_171:}

大连林海 发表于 2016-1-12 19:50:02

凌风清羽 发表于 2016-1-12 16:57


{:5_171:}

dsweiliang 发表于 2016-7-27 12:33:56

https://www.dfrobot.com.cn/goods-804.html
这块可以用么啊?

凌风清羽 发表于 2016-7-27 21:59:19

dsweiliang 发表于 2016-7-27 12:33
https://www.dfrobot.com.cn/goods-804.html
这块可以用么啊?

应该是不可以的
驱动芯片估计不一样
页: [1]
查看完整版本: 【树莓派教程】——SPI驱动OLED 128*64