当前位置:网站首页>Nanopc-t4 (rk3399) Game1 OLED (I2C) display time weather temperature
Nanopc-t4 (rk3399) Game1 OLED (I2C) display time weather temperature
2022-06-28 19:23:00 【No regrets!】
List of articles
If you encounter some problems , See this introduction It's amazing NanoPC-T4(RK3399) As the initial configuration of the workstation and related applications
A long time ago, when I was playing single chip microcomputer in the undergraduate stage , The rest of the
0.96 oledOne more , I happened to watch Zhi Huijun's little TV recently , brainwave , Just want to use thisoledMake one that can display the current time , Weather and cpu Temperature display ; At the same time, it should be noted that ,NanoPC-T4(RK3399)The board has been openedI2CThe hardware driver of , That is, just connect according to the pin diagramI2C, This board can identify the corresponding device on the bus , Just followUSBOne principle ; So the hardware is solved !!!
There is a missing diagram 
Tell the truth , Linux Under the development , It's all that simple , In especial python, Everything you can think of , Someone is already
GitHubThe bag is ready for youcloneAnd used , That's what this thing is today , Go directly to GitHub Search for a wavepython oled driveJust find one , Then take a closer look at , luma A package is a call to oled Driven by various models python package , So the software has also solved !!!

1. see GPIO Definition wiringpi library
wiringpi A library is an operating hardware GPIO Driver library , After installation, you can set the high and low levels of external pins , And different communication protocols , such as I2C, SPI etc.
mkdir -p /home/02_hardware && cd /home/02_hardware
# Remove Older Versions
wget http://112.124.9.243:8888/wiringpi/friendlyelec-rk3399/remove_oldversion_wiringPi.sh
chmod 755 remove_oldversion_wiringPi.sh
sudo ./remove_oldversion_wiringPi.sh
# Install a new version
wget http://112.124.9.243:8888/wiringpi/friendlyelec-rk3399/wiringpi-v2.44-friendlyelec-rk3399.deb
sudo dpkg -i wiringpi-v2.44-friendlyelec-rk3399.deb
(base) [email protected]:~$ gpio readall
+------+-----+----------+------+ Model NanoPC-T4 +------+----------+-----+------+
| GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
| | | 3.3V | | | 1 || 2 | | | 5V | | |
| | | I2C2_SDA | | | 3 || 4 | | | 5V | | |
| | | I2C2_SCL | | | 5 || 6 | | | GND(0V) | | |
| 32 | 7 | GPIO1_A0 | IN | 0 | 7 || 8 | | | I2C3_SCL | | |
| | | GND(0V) | | | 9 || 10 | | | I2C3_SDA | | |
| 33 | 0 | GPIO1_A1 | IN | 0 | 11 || 12 | 1 | IN | GPIO1_C2 | 1 | 50 |
| 35 | 2 | GPIO1_A3 | IN | 0 | 13 || 14 | | | GND(0V) | | |
| 36 | 3 | GPIO1_A4 | IN | 0 | 15 || 16 | 0 | IN | GPIO1_C6 | 4 | 54 |
| | | 3.3V | | | 17 || 18 | 0 | IN | GPIO1_C7 | 5 | 55 |
| 40 | 12 | GPIO1_B0 | ALT | | 19 || 20 | | | GND(0V) | | |
| 39 | 13 | GPIO1_A7 | ALT | | 21 || 22 | 0 | IN | GPIO1_D0 | 6 | 56 |
| 41 | 14 | GPIO1_B1 | ALT | | 23 || 24 | | ALT | GPIO1_B2 | 10 | 42 |
| | | GND(0V) | | | 25 || 26 | | ALT | GPIO4_C5 | 11 | 140 |
| | | I2C2_SDA | | | 27 || 28 | | | I2C2_SCL | | |
| 132 | 21 | GPIO4_A4 | IN | 0 | 29 || 30 | | | GND(0V) | | |
| 133 | 22 | GPIO4_A5 | IN | 0 | 31 || 32 | | | I2S_CLK | | |
| 131 | 23 | GPIO4_A3 | IN | 0 | 33 || 34 | | | GND(0V) | | |
| 134 | 24 | GPIO4_A6 | IN | 0 | 35 || 36 | 0 | IN | GPIO4_A7 | 27 | 135 |
| 124 | 25 | GPIO3_D4 | ALT | | 37 || 38 | | ALT | GPIO3_D5 | 28 | 125 |
| | | GND(0V) | | | 39 || 40 | | ALT | GPIO3_D6 | 29 | 126 |
+------+-----+----------+------+---+----++----+---+------+----------+-----+------+
Here we know Pin 3,5 Is the corresponding I2C2_SDA/SCL
So will oled The four pins of vcc/gnd,sda,scl Just plug it in
2. Make sure there is no problem with the hardware (i2c-tools)
There are two points to note before using the following command :
- i2c The device is executing a command (0x00) And data (0x04) There is a distinction between reading and writing
- This board is the first
I2CInterfaces are usedI2C-2 Bus No - This board is
I2CThe hardware chip isrk3x-i2c, Instead of the usual xxx
# Installation identification i2c Tools for
sudo apt-get install i2c-tools
(base) [email protected]:~$ apt-cache policy i2c-tools
i2c-tools:
Installed: 4.0-2
Candidate: 4.0-2
Version table:
*** 4.0-2 500
500 http://mirrors.ustc.edu.cn/ubuntu-ports bionic/universe arm64 Packages
100 /var/lib/dpkg/status
# Print all i2c Bus , I found that the chip used here is rk3x-i2c, Not raspberry pie bcm2835
(base) [email protected]:~$ sudo i2cdetect -l
i2c-0 i2c rk3x-i2c I2C adapter
i2c-1 i2c rk3x-i2c I2C adapter
i2c-2 i2c rk3x-i2c I2C adapter
i2c-4 i2c rk3x-i2c I2C adapter
i2c-7 i2c rk3x-i2c I2C adapter
i2c-9 i2c DP-AUX I2C adapter
i2c-10 i2c DP-AUX I2C adapter
# testing I2C Bus
(py3.7) [email protected]:zjq$ sudo i2cdetect -F 2
Functionalities implemented by /dev/i2c-2:
I2C yes
SMBus Quick Command yes
SMBus Send Byte yes
SMBus Receive Byte yes
SMBus Write Byte yes
SMBus Read Byte yes
SMBus Write Word yes
SMBus Read Word yes
SMBus Process Call yes
SMBus Block Write yes
SMBus Block Read no
SMBus Block Process Call no
SMBus PEC yes
I2C Block Write yes
I2C Block Read yes
# take oled Insert into 1356 Pin , Query occupied iic Address , Note from the above figure , 1345 The pin corresponds to i2c-2 Bus
# So here's the query i2c-2 Bus
[email protected]:~$ sudo i2cdetect -y -r -a 2
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# Here's just one I2C Address 0xUU
# Check i2c Is there a driver
cat /sys/bus/i2c/devices/i2c-1/name
# Register data export . On the bus i2c The data of the device is to be stored in registers .
(base) [email protected]:~$ sudo i2cdump -y 2 0x3c
No size specified (using byte-data access)
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC
10: 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC
20: 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC
30: 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC
40: 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC
50: 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC
60: 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC
70: 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC
80: 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC
90: 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC
a0: 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC
b0: 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC
c0: 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC
d0: 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC
e0: 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC
f0: 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 CCCCCCCCCCCCCCCC
# Register data write , That is, insert data into a bit address in the register :
sudo i2cset -y 2 0x3c 0x20 0x55
# Read I2C Devices on the bus 0x3c Of 0x80 Register address data
sudo i2cget -y 2 0x3c 0x20
3. install oled drive python package
git clone https://github.com.cnpmjs.org/rm-hull/luma.examples
cd luma.examples && pip install -e .
3.1 Use case testing
cd /home/02_hardware/luma.examples/examples
python 3d_box.py --help
I2C:
--i2c-port I2C_PORT I2C bus number (default: 1)
--i2c-address I2C_ADDRESS
I2C display address (default: 0x3C)
# Therefore, you can run... Directly with the following command demo
python 3d_box.py --i2c-port=2 --i2c-address=0x3c
3.2 The test case 2
# https://blog.csdn.net/ki1381/article/details/79291138/
# https://blog.csdn.net/u011198687/article/details/120347965
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from luma.core.interface.serial import i2c
from luma.core.render import canvas
# SSD1306, SSD1309, SSD1322, SSD1325, SSD1327, SSD1331,SSD1351, SSD1362 and SH1106 devices.
from luma.oled.device import ssd1306, ssd1309, ssd1322, ssd1325, ssd1327, ssd1331, ssd1351, ssd1362, sh1106
from time import sleep
from PIL import ImageDraw, ImageFont
""" OLED luma Driver library test program function : Show hello world And rectangular frame 10 second """
__version__ = 1.0
# Initialize port
serial = i2c(port=2, address=0x3C)
# # Initialization equipment , Change here ssd1306, ssd1325, ssd1331, sh1106
device = ssd1306(serial)
# Call the display function
with canvas(device) as draw:
font = ImageFont.load_default()
# there font2 The font can be changed to Chinese font , For instance from win10 The path of windows/fonts/ In italics , Put it here , That's all right.
font2 = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeSans.ttf', 20)
draw.rectangle(device.bounding_box, outline="white", fill="black")
draw.text((10, 25), "hello world", font=font2, fill=255)
# Delay display 10s
while True:
pass
Be careful : The font used here can go to `c:/windows/fonts/ Regular script, etc .ttf` Upload to the board , Then use it according to the absolute path 4. oled Display time , The weather , temperature
Be careful : oled If the Chinese font is displayed, you need to start from win Copy a Chinese font inside ttf Put the file on the board
It's very simple , Direct use of system time , Through the weather API Check the weather , By reading CPU Get the temperature from the temperature file , The last indication is oled above
# Set up oled Show
# City : blessing
# date Time week
# The weather today
# Tomorrow's weather
# Update every ten seconds
from luma.core.interface.serial import i2c
from luma.core.render import canvas
# SSD1306, SSD1309, SSD1322, SSD1325, SSD1327, SSD1331,SSD1351, SSD1362 and SH1106 devices.
from luma.oled.device import ssd1306, ssd1309, ssd1322, ssd1325, ssd1327, ssd1331, ssd1351, ssd1362, sh1106
from PIL import ImageDraw, ImageFont
import urllib.request
import gzip
import json
import datetime
import time
__version__ = 1.0
# Initialize port
serial = i2c(port=2, address=0x3C)
# # Initialization equipment , Change here ssd1306, ssd1325, ssd1331, sh1106
device = ssd1306(serial)
def get_weather_data() :
url1 = 'http://wthrcdn.etouch.cn/weather_mini?city='+urllib.parse.quote(" Xi'an ")
url2 = 'http://wthrcdn.etouch.cn/weather_mini?citykey=101010100'
weather_data = urllib.request.urlopen(url1).read()
weather_data = gzip.decompress(weather_data).decode('utf-8')
weather_dict = json.loads(weather_data) # take json Convert data to dictionary format
forecast = weather_dict.get('data').get('forecast')
today_weather = " today : " + forecast[0].get('type') + " " + weather_dict.get('data').get('wendu')+'℃ ' + \
"(" +forecast[0].get('low')[3:-1] + "~" + forecast[0].get('high')[3:-1] +")"
# print(today_weather)
tomorrow_weather = " bright : " + forecast[1].get('type') + " " +\
forecast[1].get('low')[3:] + "~" + forecast[1].get('high')[3:]
# print(tomorrow_weather)
return today_weather, tomorrow_weather
font1 = ImageFont.load_default() # default font
font2 = ImageFont.truetype('/home/pi/zjq/04_hardware/oled/ttf_font/STKAITI.TTF', 16) # Chinese Fonts
def display():
today_weather, tomorrow_weather = get_weather_data()
now_time = datetime.datetime.now().strftime("%m-%d %A %H:%M ")# now.strftime("%Y-%m-%d %H:%M:%S")
# print(now_time)
with open("/sys/devices/virtual/thermal/thermal_zone0/temp", "r") as f:
temperature = str(int(int(f.read())/1000))
with canvas(device) as draw:
draw.rectangle(device.bounding_box, outline="white", fill="black")
draw.text((0, 0), today_weather, font=font2, fill=255)
draw.text((0, 16), tomorrow_weather, font=font2, fill=255)
draw.text((5, 38), "CPU:" + temperature+"°", font=font1, fill=255)
draw.text((5, 50), now_time, font=font1, fill=255)
time.sleep(10)
while True:
display()
# display()
5. application 1 oled Scroll through the text
text = " Drink in Li Bai You can't see the Yellow River coming up , Running to the sea and never returning .\
If you don't see the mirror in the high hall, you'll have white hair , Morning as black as snow . You must be happy in life ,\
Don't empty the golden cup to the moon . I'm born to be useful , When all the money is gone ."
from time import sleep
from luma.core.virtual import viewport
from PIL import ImageDraw, ImageFont
virtual = viewport(device, width=2048, height=720)
font2 = ImageFont.truetype('/home/pi/zjq/04_hardware/oled/STKAITI.TTF', 16) # Chinese Fonts
# Horizontal scrolling
def horizontal_scroll():
with canvas(virtual) as draw:
draw.text((0,0), text=text, fill="white", font=font2)
sleep(1)
y = 0
for x in range(len(text)*16):
virtual.set_position((x, y))
sleep(0.05)
def main():
print(" current version :", __version__)
horizontal_scroll()
# vertical_scroll()
main()
边栏推荐
- Double contextual relationship network for polyp segmentation
- 智能计算系统1 环境搭建
- Get the timestamp of 0:00 and 23:59 of the current date
- Redis 如何实现库存扣减操作?如何防止商品被超卖?
- Shell unknown rollup 1
- leetcode 1689. Partitioning into minimum number of deci binary numbers
- The white paper on the panorama of the digital economy and the digitalization of consumer finance were released
- 易观分析《2022年中国银行业隐私计算平台供应商实力矩阵分析》研究活动 正式启动
- A few lines of code can realize complex excel import and export. This tool class is really powerful!
- 论文笔记:Universal Value Function Approximators
猜你喜欢

颜色渐变的FontAwesome图标

rancher增加/删除node节点

Leetcode 周赛299

腾讯汤道生:面向数实融合新世界,开发者是最重要的“建筑师”

About Critical Values

MongoDB系列之MongoDB工作原理简单介绍

Try except add auxiliary new column

Building tin with point cloud

How to change the status bar at the bottom of win11 to black? How to change the status bar at the bottom of win11 to black

PCL 环境下安装配置CGAL 5.4.1
随机推荐
Pipeline based hybrid rendering
找出连续7天登陆,连续30天登陆的用户
Constrained Delaunay triangulation in MATLAB
C语言-函数知识点
Chunfeng power and Huawei work together to build a smart Park benchmark, and the future factory innovation will reach a new level
C语言局部变量与全局变量重名时的优先级问题(当局部变量和全局变量同时存在的时候,优先引用局部变量,而不去引用全局变量)
Get the timestamp of 0:00 and 23:59 of the current date
Differences and relations among rxjs map, mergemap and switchmap
Month on month SQL implementation
Double contextual relationship network for polyp segmentation
论文阅读:Duplex Contextual Relation Network for Polyp Segmentation
释放互联网价值的 Web3
POI excel conversion tool
I. The HR system is put on the enterprise wechat ISV to enhance the in-depth application of enterprise wechat in service chain retail and other industries
大火的虚拟人在哪些产业开始发力?
PCL 计算平面三角形外接圆的圆心和半径
Group programming TIANTI competition exercise - continuously updating
华为云OneMeeting告诉你全场景会议这么开!
180.1. Log in continuously for n days (database)
PostgreSQL database docker