《食用指南》之我的树莓派4B搭配12468屏幕

配置清单

硬件

  • 树莓派4B x 1台
  • 四针脚0.96寸12468屏幕 x 1块
  • 母对母杜邦线 x 4条

硬件链接

在这里插入图片描述

四针脚0.96寸12468屏幕

二、引脚定义及连接方法

屏幕针脚含义连接树莓派针脚位置
VCC电源(3.3V~5V)左一
GND左五
SCLIIC时钟信号左三
SDAIIC数据信号左二

软件

连接好硬件设备,我们开始软件方面的配置。

所需软件(Windows系统)

有了以上两个软件,我们便可以和树莓派系统实现互联互通,通过Windows来控制树莓派和文件的相互拷贝

所需软件(Raspbian系统)

通过命令我们来安装屏幕所需要的驱动:

开启i2C功能

sudo apt-get install -y python-smbus
sudo apt-get install -y i2c-tools
sudo raspi-config

在这里插入图片描述

在这里插入图片描述

查看i2c地址

sudo i2cdetect -y 1
在这里插入图片描述

安装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

python如果是3.x版本,pip需要改成pip3

屏幕显示

安装好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:
RST = 24
# Note the following are only used with SPI:
DC = 23
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.SSD1306_128_32(rst=RST)
      
# 128x64 display with hardware I2C:
# disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)
      
# Alternatively you can specify an explicit I2C bus number, for example
# with the 128x32 display you would use:
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, i2c_bus=2)
      
# 128x32 display with hardware SPI:
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))
      
# 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))
      
# 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.SSD1306_128_32(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),    'Hello',  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.SSD1306_128_32(rst=RST)
      
# 128x64 display with hardware I2C:
disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)

终端输入sudo python shapes.py或用Python打开文件运行就能看到OLED屏有显示了。

python程序运行

命令

python test1.py

后台运行命令

python test.py &

退出ssh,仍可运行命令

nohup python test.py >null 2>&1 &

实际应用效果图(微博热搜)

在这里插入图片描述

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
树莓4B使用VNC屏幕很小可能是由于默认的分辨率设置较低所致。要解决这个问题,你可以尝试以下步骤: 1. 在VNC Viewer中连接到树莓4B。 2. 打开终端,输入以下命令来编辑配置文件:sudo nano /boot/config.txt 3. 在配置文件中找到并修改以下两行: hdmi_group=2 hdmi_mode=82 将hdmi_mode的值修改为适合你的显示器的分辨率代码。可以在Raspberry Pi官方网站上找到不同分辨率对应的代码。 4. 按Ctrl + X,然后按Y保存修改。 5. 重新启动树莓4B,命令为:sudo reboot 这样,你应该能够通过VNC连接到树莓4B并且在更大的屏幕上获得更好的显示效果。请注意,你也可以根据自己的需求自定义分辨率设置。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [树莓4B使用VNC连接之大无语事件](https://blog.csdn.net/qq_41071754/article/details/120380734)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [【物联网树莓毕设01】树莓4B快速实现VNC连接](https://blog.csdn.net/weixin_45406778/article/details/122318705)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值